微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Android 应用程序中 Bouncy Castle 加密中的完整性保护警告

如何解决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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?