decrypt pfx OR p12 using iaik_jce.jar in Java throws Unable to decrypt PrivateKey! exception

875 Views Asked by At

I obtained iaik_jce.jar file from thirdparty. I am using it to decrypt a pfx file. When i am calling decrypt api then i am getting Unable to decrypt PrivateKey! exception. Below is the piece of code which i use for decryption.

    FileInputStream inStream = new FileInputStream(currentCredentialFile.getAbsoluteFile());
pkcs12 = new PKCS12(inStream);
pkcs12.decrypt(currentCredentialPassword.toCharArray());

Below is the exception stack trace

Caused by: iaik.pkcs.PKCSException: Unable to decrypt PrivateKey!
    at iaik.pkcs.pkcs12.AuthenticatedSafe.decrypt(Unknown Source)
    at iaik.pkcs.pkcs12.PKCS12.decrypt(Unknown Source)
    at com.raja.testapp.TestApplicatioin.main(TestApplicatioin.java:32)

Do i need to make any configuration changes for using iaik_jce.jar file for decryption.

1

There are 1 best solutions below

0
On

I solved the issue myself. I needed to do some initialization which i did not do before.

iaik.security.provider.IAIK.addAsProvider(false);

Adding the above statement did the trick