gpt4 book ai didi

java - 无法通过 bouncycaSTLe 库在 Android 上生成证书请求

转载 作者:行者123 更新时间:2023-12-01 14:53:35 24 4
gpt4 key购买 nike

我现在正在 Android 上开发数字签名应用程序。

但是,我未能制作 apk 文件,因为 eclipse 显示以下消息

[2013-01-27 20:43:25 - BlowfishCipher] Dx意外的顶级异常:java.lang.IllegalArgumentException:已添加:Lorg/bouncycaSTLe/mozilla/SignedPublicKeyAndChallenge;

[2013-01-27 20:43:25 - BlowfishCipher] Dx at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)[2013-01-27 20:43:25 - BlowfishCipher] Dx at com.android.dx.dex.file.DexFile.add(DexFile.java:163)

我知道错误消息表明存在重复的 jar 文件,但我不知道如何解决这个问题,因为重复的 jar (Lorg/bouncycaSTLe/mozilla/SignedPublicKeyAndChallenge;) 是 bouncy caslte 库的核心文件。

下面的java代码没有显示语法错误,但它导致java.lang.IllegalArgumentException:已经添加异常

package exam.blowfishcipher;

import java.io.FileWriter;
import java.io.OutputStreamWriter;
import java.security.KeyPair;
import java.security.SecureRandom;
import javax.security.auth.x500.X500Principal;
import org.bouncycastle.jce.PKCS10CertificationRequest;
import org.bouncycastle.openssl.PEMWriter;
import android.os.Environment;
import chapter6.PKCS10ExtensionExample;



public class PKCS10Generater
{
public static PKCS10CertificationRequest generateRequest(
KeyPair pair)
throws Exception

{
return new PKCS10CertificationRequest(
"SHA256withRSA",
new X500Principal("CN=Test CA Certificate"),
//new X500Principal("CN=end"),
pair.getPublic(),
null,
pair.getPrivate());
}

public static void pemEncodeToFile(String filename, Object obj, char[] password) throws Exception{
PEMWriter pw = new PEMWriter(new FileWriter(filename));
if (password != null && password.length > 0) {
pw.writeObject(obj, "DESEDE", password, new SecureRandom());
} else {
pw.writeObject(obj);
}
pw.flush();
pw.close();
}

public static void reqGen() throws Exception
{
//create the keys
/*
KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA", "BC");
//KeyPairGenerator kpGen = KeyPairGenerator.getInstance()

kpGen.initialize(512, chapter4.Utils.createFixedRandom());

KeyPair pair=kpGen.generateKeyPair();
*/
//PKCS10CertificationRequest request = generateRequest(pair);

KeyPair pair = chapter8.Utils.generateRSAKeyPair();
PKCS10CertificationRequest request = PKCS 10ExtensionExample.generateRequest(pair);


pemEncodeToFile(Environment.getExternalStorageDirectory()+"pkcs10.req", request, null);
PEMWriter pemWrt = new PEMWriter( new OutputStreamWriter(System.out));
pemWrt.writeObject(request);
pemWrt.close();
}


}

最佳答案

Android 系统中已经包含 BouncyCaSTLe,这就是为什么您在尝试再次添加它时会收到错误(在最近的版本中,它实际上位于 com.android.org.bouncycaSTLe 或类似的位置)所以理论上你不应该得到这个错误)。如果你想将 BC 包含在你的项目中(使用 jarjar 等),你必须重命名 BC 的包。 SpongyCaSTLe 是一个已经为您完成此任务的项目。尝试使用它代替常规的 BC jar。

https://github.com/rtyley/spongycastle

关于java - 无法通过 bouncycaSTLe 库在 Android 上生成证书请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14547151/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com