当我从.pfx文件中读取私钥以对字符串进行签名时,必须在其中使用BouncyCastleProvider作为安全提供程序。
错误抛出位置:
KeyStore.getInstance(“ PKCS12”,新的BouncyCastleProvider()。getName())
代码段:
String message = jsonString;
String password = "XXXX";
Security.addProvider(new BouncyCastleProvider());
logger.severe("message : " + message);
File pfxFile = new file("/XXXX/XXXX/XXXX.pfx");
KeyStore keyStore = KeyStore.getInstance("PKCS12", new BouncyCastleProvider().getName()); //here getting error
logger.severe("keyStore : " + keyStore);
keyStore.load(new FileInputStream(pfxFile), password.toCharArray());
String alias = (String) keyStore.aliases().nextElement();
PrivateKey privateKey = (PrivateKey) keyStore.getKey(alias, password.toCharArray());
Signature privateSignature = Signature.getInstance("SHA256withRSA");
privateSignature.initSign(privateKey);
privateSignature.update(message.getBytes("UTF-8"));
byte[] signature2 = privateSignature.sign();
String smsgContent = SHA256SignerUtil.encodeBase64String(signature2);
错误摘要:
Caused by: java.lang.VerifyError: (class: org/bouncycastle/jce/provider/JDKPKCS12KeyStore, method: engineLoad, signature: (Ljava/io/InputStream;[C)V, offset: 1278) Incompatible object argument org/bouncycastle/asn1/DERSet for function call, expecting org/bouncycastle/asn1/DERConstructedSet