1

我正在用我已经拥有的公钥加密一个文本文件,我有一个基本上从输入流中读取公钥的方法,同时在下一行创建一个对象时我遇到了异常

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;

}

这是几个小时前的工作,突然停止工作,没有改变代码中的任何内容。现在,以下是我得到的例外

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

以前有人遇到过这种错误吗?感谢对此的任何帮助

4

0 回答 0