第一个坑:生产上业务要求用的是子密钥加密文件。
@SuppressWarnings("unchecked") public static PGPPublicKey readPublicKey(InputStream in) throws IOException, PGPException {
PGPPublicKeyRingCollection keyRingCollection = new PGPPublicKeyRingCollection(PGPUtil.getDecoderStream(in)); PGPPublicKey publicKey = null;
Iterator<PGPPublicKeyRing> rIt = keyRingCollection.getKeyRings();
while (publicKey == null && rIt.hasNext()) {
PGPPublicKeyRing kRing = rIt.next();
Iterator<PGPPublicKey> kIt = kRing.getPublicKeys();
while (publicKey == null && kIt.hasNext()) {
PGPPublicKey key = kIt.next(); &n

本文总结了在Java中使用GPG进行加解密时遇到的两个主要问题。第一个问题是业务要求使用子密钥加密文件,通过遍历公钥环找到子密钥并排除主密钥。第二个问题是在读取公钥文件时出现错误,原因在于公钥文件中缺少PGPPublicKeyRing对象。解决方案包括检查公钥文件格式和正确识别子密钥。
最低0.47元/天 解锁文章
3010

被折叠的 条评论
为什么被折叠?



