我正在尝试使用 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
1 回答

紫衣仙女
TA贡献1839条经验 获得超15个赞
以防万一有人遇到问题,即使尝试了一切仍然不起作用。
对于我的情况,bit size
默认情况下仅允许,256
因为我的密钥位大小是2048
其返回null
要解决此问题,请在您的中添加policy.jar
和 ,因为您不需要添加。us-export.jar
$JRE_HOME/lib/secuirty/
java8
如果你想检查你的java是否允许你的位大小,你可以通过以下方式检查。
System.out.println( javax.crypto.Cipher.getMaxAllowedKeyLength("AES"));
添加回答
举报
0/150
提交
取消