0

I am currently upgrading bouncycastle jar in my project from 1.47 to 1.70. The upgrade went fine and 1.70 is working good encrypting and decrpyting the files. But when it comes to decrypting older version files, for instance, a file sample.txt encrypted in 1.47 version is not getting decrypted in 1.70. I am getting the exception as below. Have any of you come across this context. This is critical from business perspective because the business might use older encrypted files to decrypt when ever they want to. the version upgrade should not be a show stopper.

Exception trace

org.bouncycastle.openpgp.PGPException: Exception constructing key
    at org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyConverter.getPrivateKey(Unknown Source)
    at org.bouncycastle.openpgp.operator.jcajce.JcePublicKeyDataDecryptorFactoryBuilder$2.recoverSessionData(Unknown Source)
    at org.bouncycastle.openpgp.PGPPublicKeyEncryptedData.getSessionKey(Unknown Source)
    at org.bouncycastle.openpgp.PGPPublicKeyEncryptedData.getDataStream(Unknown Source)
    at PGPNew.decryptFile(PGPNew.java:212)
    at PGPNew.main(PGPNew.java:146)
Caused by: java.security.NoSuchProviderException: no such provider: BC
    at java.base/sun.security.jca.GetInstance.getService(GetInstance.java:83)
    at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:206)
    at java.base/java.security.KeyFactory.getInstance(KeyFactory.java:225)
    at org.bouncycastle.jcajce.util.NamedJcaJceHelper.createKeyFactory(Unknown Source)
    at org.bouncycastle.openpgp.operator.jcajce.OperatorHelper.createKeyFactory(Unknown Source)
    at org.bouncycastle.openpgp.operator.jcajce.JcaPGPKeyConverter.implGeneratePrivate(Unknown Source)

your text I tried to setup a stand alone progrom for both the versions 1.47 and 1.70. I generated my own pair of keys. Tried to decrypt 1.47 version encrypted file.

1 Answers1

0

As your actual issue in this case seems to be java.security.NoSuchProviderException: no such provider: BC I think the following similar situation may provide some good hints on how to proceed: PGP Encrypt using BouncyCastle in Java .

Other, probably more appropriate ways to register the provider are Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()) or adding an entry to the policy file, similar to security.provider.?=org.bouncycastle.jce.provider.BouncyCastleProvider.

It may be that this is not your actual problem, but rather reflects a difference in your test program setup. Even so, adding the appropriate provider in the appropriate way should get you one step further.

Xecrets
  • 79
  • 5