我正在使用一些加密技术创建JAVA EE
应用程序。我正在使用ibmjceprovider 10.0
jar文件进行签名过程。我的部署环境是JBOSS
,其中包含Java JDK 1.6
。
这是我得到的完整堆栈跟踪:
01:56:28,830 ERROR [stderr] java.io.IOException: The private key could not be decrypted
01:56:28,831 ERROR [stderr] at com.test.sample.core.CertificateService.readKeyPair(Certificatefile.java:140)
01:56:28,831 ERROR [stderr] at com.test.sample.security.certificate.CertificateHelper.generateKeyStorage(CertificateHelper.java:179)
01:56:28,847 ERROR [stderr] Caused by: org.bouncycastle.openssl.EncryptionException: exception using cipher - please check password and data.
01:56:28,847 ERROR [stderr] at org.bouncycastle.openssl.PEMUtilities.crypt(Unknown Source)
01:56:28,847 ERROR [stderr] at org.bouncycastle.openssl.PEMUtilities.crypt(Unknown Source)
01:56:28,848 ERROR [stderr] at org.bouncycastle.openssl.PEMReader$KeyPairParser.readKeyPair(Unknown Source)
01:56:28,848 ERROR [stderr] at org.bouncycastle.openssl.PEMReader$RSAKeyPairParser.parseObject(Unknown Source)
01:56:28,848 ERROR [stderr] at org.bouncycastle.openssl.PEMReader.readObject(Unknown Source)
01:56:28,849 ERROR [stderr] at com.test.sample.core.CertificateService.readKeyPair(Certificatefile.java:138)
01:56:28,849 ERROR [stderr] ... 33 more
01:56:28,849 ERROR [stderr] Caused by: java.lang.SecurityException: JCE cannot authenticate the provider BC
01:56:28,850 ERROR [stderr] at javax.crypto.Cipher.getInstance(DashoA13*..)
01:56:28,850 ERROR [stderr] ... 39 more
01:56:28,851 ERROR [stderr] Caused by: java.util.jar.JarException: Cannot parse vfs:/content/sample.ear/sample-webapp.war/WEB-INF/lib/bcprov-jdk16-1.46.jar
01:56:28,851 ERROR [stderr] at javax.crypto.SunJCE_c.a(DashoA13*..)
01:56:28,851 ERROR [stderr] at javax.crypto.SunJCE_b.b(DashoA13*..)
01:56:28,851 ERROR [stderr] at javax.crypto.SunJCE_b.a(DashoA13*..)
01:56:28,852 ERROR [stderr] ... 40 more
在 Certificatefile.java
中PKCS10 pkcs = new PKCS10(keyPair.getPublicKey());
pkcs.encodeAndSign(new X500Signer(signature,subject));
/*calling readKeyPair here*/
KeyPair pair = CertificateService.readKeyPair(new ClassPathResource("com/test/sample/myroot.key").getFile());
PrivateKey privateKey = pair.getPrivate();
并在 CertificateHelper.java
中public static KeyPair readKeyPair(File privateKey) throws IOException {
Security.addProvider(new BouncyCastleProvider());
FileReader fileReader = new FileReader(privateKey);
PEMReader r = new PEMReader(fileReader, new PasswordFinder() {
public char[] getPassword() {
return "password".toCharArray();
}
});
try {
return (KeyPair) r.readObject();
} catch (IOException ex) {
/*throwing error here*/
throw new IOException("The private key could not be decrypted", ex);
} finally {
r.close();
fileReader.close();
}
}
为什么我收到此错误?我在这里缺少什么?任何建议都会更有帮助。请帮助。