如何解决Android 应用程序中 Bouncy Castle 加密中的完整性保护警告
参考这个答案link
我收到以下警告:
gpg: WARNING: message was not integrity protected
gpg: Hint: If this message was created before the year 2003 it is
likely that this message is legitimate. This is because back
then integrity protection was not widely used.
gpg: Use the option '--ignore-mdc-error' to decrypt anyway.
完全可以忽略。但我想解决它。通过互联网上的 BCGPG 内容,我将问题缩小到我认为的问题所在。
PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(new BcPGPDataEncryptorBuilder(SymmetricKeyAlgorithmTags.TRIPLE_DES).setSecureRandom(new SecureRandom()));
我认为问题出在
BcPGPDataEncryptorBuilder(SymmetricKeyAlgorithmTags.TRIPLE_DES)
as SymmetricKeyAlgorithmTags.TRIPLE_DES 是一种相当古老的加密方法。此外,密钥对是非对称的,因此应该在代码中使用其他一些非对称算法。我没有得到实现 AES 和 SHA 等其他方法的正确方法。
虽然我不是 100% 确定,但可以提出更多关于解决这个问题的见解。
解决方法
这正是消息所说的。完整性保护描述如下:https://tools.ietf.org/html/rfc4880#section-5.13
我相信您引用的代码没有在 withIntegrityPacket 上设置 BcPGPDataEncryptorBuilder 标志
所以我会改变:
PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(new BcPGPDataEncryptorBuilder(SymmetricKeyAlgorithmTags.TRIPLE_DES).setSecureRandom(new SecureRandom()));
到:
PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(new BcPGPDataEncryptorBuilder(SymmetricKeyAlgorithmTags.TRIPLE_DES).setSecureRandom(new SecureRandom()).setWithIntegrityPacket(true));
让我知道它是否有效。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。