gpg --list-keys 为空但文件解密了 bouncycastle 加密文件
gpg --list-keys is empty but file decrypts bouncycastle encrypted file
我目前正在 Java 应用程序中使用 BouncyCastle PGP 从字符串中读取 public 密钥,并使用该密钥加密文件。正在加载密钥...
Security.addProvider(new BouncyCastleProvider());
InputStream keyIn = new ByteArrayInputStream(publicKey.getBytes());
PGPPublicKeyRingCollection pgpKeyRing = new PGPPublicKeyRingCollection(PGPUtil.getDecoderStream(keyIn), new JcaKeyFingerpringCalculator());
PGPPublicKey = pgpKeyRing.getKeyRings().next().getPublicKey();
输出文件可以用
解密
gpg --decrypt file.gpg
即使 gpg --list-keys
和 gpg --list-secret-keys
为空
这怎么可能?它是否可能从其他地方读取密钥环?我在 CentOS 7 上,我删除了 ~/.gnupg 并重新创建了它。
我也试过更改我用来加密的 public 密钥,但它仍然可以解密。
事实证明,我的代码中有一个错误,并且正在写出 PGP 压缩文件的 Ascii 装甲版本,但没有加密。正如它所发生的那样,gpg --decrypt
将解压缩此文件,即使密钥环中没有密钥,因为它从不进行检查。 gpg --debug-level 9
对解决这个问题很有用。
我目前正在 Java 应用程序中使用 BouncyCastle PGP 从字符串中读取 public 密钥,并使用该密钥加密文件。正在加载密钥...
Security.addProvider(new BouncyCastleProvider());
InputStream keyIn = new ByteArrayInputStream(publicKey.getBytes());
PGPPublicKeyRingCollection pgpKeyRing = new PGPPublicKeyRingCollection(PGPUtil.getDecoderStream(keyIn), new JcaKeyFingerpringCalculator());
PGPPublicKey = pgpKeyRing.getKeyRings().next().getPublicKey();
输出文件可以用
解密gpg --decrypt file.gpg
即使 gpg --list-keys
和 gpg --list-secret-keys
为空
这怎么可能?它是否可能从其他地方读取密钥环?我在 CentOS 7 上,我删除了 ~/.gnupg 并重新创建了它。
我也试过更改我用来加密的 public 密钥,但它仍然可以解密。
事实证明,我的代码中有一个错误,并且正在写出 PGP 压缩文件的 Ascii 装甲版本,但没有加密。正如它所发生的那样,gpg --decrypt
将解压缩此文件,即使密钥环中没有密钥,因为它从不进行检查。 gpg --debug-level 9
对解决这个问题很有用。