1

I am encrypting a text file with public key which i already have, I have a method which basically reads public key from the input stream, while creating an object at the following line i am getting exception

public static PGPPublicKey readPublicKeyFromCol(InputStream in)
           throws IOException, PGPException {
    PGPPublicKey k =null;
        in = PGPUtil.getDecoderStream(in);

        PGPPublicKeyRingCollection pgpPub = new PGPPublicKeyRingCollection(in, new BcKeyFingerprintCalculator());// Exception thrown on this line
        Iterator rIt = pgpPub.getKeyRings();

        while (rIt.hasNext()) {
           PGPPublicKeyRing kRing = (PGPPublicKeyRing) rIt.next();
           Iterator kIt = kRing.getPublicKeys();

           while (kIt.hasNext()) {
               k = (PGPPublicKey) kIt.next();
               if (k.isEncryptionKey()) {
                   return k;
               }
           }
        }
        return k;

}

This was working few hours before and suddenly it stopped working, haven't change anything in the code. And now, following is the exception i m getting

Exception in thread "main" org.bouncycastle.openpgp.PGPException: org.bouncycastle.openpgp.PGPEncryptedDataList found where PGPPublicKeyRing expected

Any one faced this type of error before ? Appreciate any help on this

0 Answers0