【问题标题】:Bouncycastle (Spongycastle) key import and use on androidBouncycastle (Spongycastle) 密钥导入和在 android 上使用
【发布时间】:2013-12-13 17:05:13
【问题描述】:

使用 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 明白。

【问题讨论】:

    标签: java android encryption bouncycastle spongycastle


    【解决方案1】:

    我找到了解决问题的方法:我只需要使用相同的算法来编码新的密钥环。

    secretKeyRing = PGPSecretKeyRing.copyWithNewPassword(secretKeyRing, new char[] {},
                    newPassPhrase.toCharArray(), secretKeyRing.getSecretKey().getKeyEncryptionAlgorithm(),
                    new SecureRandom(), new BouncyCastleProvider());
    

    【讨论】:

      猜你喜欢
      • 2014-05-20
      • 2011-12-15
      • 2013-03-16
      • 1970-01-01
      • 1970-01-01
      • 2019-06-24
      • 1970-01-01
      • 1970-01-01
      • 2017-03-17
      相关资源
      最近更新 更多