在使用SpongyCastle导入PGP密钥并检查是否可以使用它解密后,我希望添加一个密码来保护密钥环。所以我做了一个加密的副本:
secretKeyRing = PGPSecretKeyRing.copyWithNewPassword(secretKeyRing, new char[] {},
newPassPhrase.toCharArray(), PGPEncryptedData.CAST5,
new SecureRandom(), new BouncyCastleProvider());我用以下方法测试解密:
testKey = secretKeyRing.getSecretKey().extractPrivateKey(newPassPhrase.toCharArray(), new BouncyCastleProvider());很显然这很好用。
当我试图用这个加密密钥解密一个文件时,使用相同的密码:
PGPPrivateKey testKey = secretKey.extractPrivateKey(passPhrase.toCharArray(),
new BouncyCastleProvider());当secretKey是密钥环的主键时,我得到一个PGPException语句
Exception constructing key我觉得我错过了一些显而易见的东西。请随时询问更多细节。
这是在一个定制的pgp应用上我正在构建,它只需要导入一个单独的私钥,所以主键是唯一的钥匙,AFAI理解。
发布于 2013-12-16 09:37:50
我找到了解决这个问题的方法:我只需要使用相同的算法来编码新的密钥环。
secretKeyRing = PGPSecretKeyRing.copyWithNewPassword(secretKeyRing, new char[] {},
newPassPhrase.toCharArray(), secretKeyRing.getSecretKey().getKeyEncryptionAlgorithm(),
new SecureRandom(), new BouncyCastleProvider());https://stackoverflow.com/questions/20572060
复制相似问题