Skip to Content
0
Former Member
Dec 29, 2011 at 05:53 PM

"Exception creating cipher" exception

557 Views

Hi Experts,

I'm getting "Exception creating cipher" exception while decrypting a file using Bouncy castle api.

I'm using RSA pubic and private keys

Here is the piece of decryption code where in the exception is coming .

PGPPrivateKey sKey = null;

PGPPublicKeyEncryptedData pbe = null;

PGPSecretKeyRingCollection pgpSec;

Iterator it1;

try {

in = PGPUtil.getDecoderStream(in);

pgpF = new PGPObjectFactory(in);

Object o = pgpF.nextObject();

if (o instanceof PGPEncryptedDataList) {

enc = (PGPEncryptedDataList) o;

} else {

enc = (PGPEncryptedDataList) pgpF.nextObject();

}

Iterator it = enc.getEncryptedDataObjects();

PGPPrivateKey sKey = null;

PGPPublicKeyEncryptedData pbe = null;

while (sKey == null && it.hasNext()) {

pbe = (PGPPublicKeyEncryptedData) it.next();

sKey = findSecretKey(keyIn, pbe.getKeyID(), passwd);

-


-


}

PGPPrivateKey findSecretKey(InputStream keyIn, long keyID,

char[] pass) throws IOException, PGPException,

NoSuchProviderException {

PGPSecretKeyRingCollection pgpSec = new PGPSecretKeyRingCollection(PGPUtil.getDecoderStream(keyIn));

PGPSecretKey pgpSecKey = pgpSec.getSecretKey(keyID);

if (pgpSecKey == null) {

return null;

}

return pgpSecKey.extractPrivateKey(pass, "BC");-->//Here i'm getting "Exception creating the cipher" }

Could you please advice me ?

Thanks in Advance

Regards

Venkat