猿问

充气城堡 PGPObjectFactory nextObject 返回 null

我正在尝试使用 RSA 公钥和私钥解密和加密消息。


当我尝试阅读时,PGPObjectFactory.nextObject()我得到null 下面是我的代码。


  Security.addProvider(new BouncyCastleProvider());

        InputStream in = PGPUtil.getDecoderStream(new ByteArrayInputStream(encryptedString.getBytes()));

        JcaPGPObjectFactory pgpFact;

        PGPObjectFactory pgpF = new PGPObjectFactory(in, new JcaKeyFingerprintCalculator());


        Object o = pgpF.nextObject(); // I get this null

        PGPEncryptedDataList encList;


        if(o instanceof PGPEncryptedDataList)

        {

            encList = (PGPEncryptedDataList) o;

        }else {


            encList = (PGPEncryptedDataList) pgpF.nextObject();

        }


        Iterator<PGPPublicKeyEncryptedData> itt = encList.getEncryptedDataObjects(); 

相同的代码正在运行java 1.8,但在 java 1.7 中运行时会出现此问题,


我正在使用所有充气城堡1.63


智慧大石
浏览 119回答 1
1回答

紫衣仙女

以防万一有人遇到问题,即使尝试了一切仍然不起作用。对于我的情况,bit size默认情况下仅允许,256因为我的密钥位大小是2048其返回null要解决此问题,请在您的中添加policy.jar和 ,因为您不需要添加。us-export.jar$JRE_HOME/lib/secuirty/java8如果你想检查你的java是否允许你的位大小,你可以通过以下方式检查。System.out.println( javax.crypto.Cipher.getMaxAllowedKeyLength("AES"));
随时随地看视频慕课网APP

相关分类

Java
我要回答