I am creating a JAVA EE
application with using some encryption techniques . I am using ibmjceprovider 10.0
jar file for signing process . My deployment environment is JBOSS
with Java JDK 1.6
.
This is the complete stack trace i am getting :
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
In 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();
and in 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();
}
}
Why i am getting this error ? Anything i am missing here ? Any suggestion would be more helpful . Please Help .