post-quantum-cryptography - McEliece Java 中的错误填充
问题描述
我正在尝试实现 McEliece 算法,但遇到了一些麻烦。当我尝试解密消息时,它显示一个异常,指出密文无效。我使用 BouncyCastle 实现作为我工作的指南。
// check if padding byte is valid
if (index<0 || mrBytes[index] != 0x01)
{
throw new InvalidCipherTextException("Bad Padding: invalid ciphertext");
}
加密有效,它在解密期间抛出此异常
org.bouncycastle.crypto.InvalidCipherTextException: Bad Padding: invalid ciphertext
at org.bouncycastle.pqc.crypto.mceliece.McElieceCipher.computeMessage(Unknown Source)
at org.bouncycastle.pqc.crypto.mceliece.McElieceCipher.messageDecrypt(Unknown Source)
这是我为解密而写的
try {
cipher.init(false, generator.generateKeyPair().getPrivate());
byte[] decodedMessage = cipher.messageDecrypt(enc);
if (decodedMessage.equals(plainMessage))
{
System.out.println("success");
} else
{
System.out.println("...");
}
} catch (InvalidCipherTextException e) {
e.printStackTrace();
解决方案
推荐阅读
- php - php websocket棘轮不从学说中获取最新数据
- c++ - 动态内存如何与 CLion 一起工作?
- r - 如果 file.csv 使用“;”,则将字符变量转换为数字时出错 而不是“,”分隔符。R
- c++ - 如何在 VC++ 中定义一个超过 MAXINT 元素的布尔数组
- android - 使用 AppAuth-Android 和使用 IdS4 的 aspnet 核心进行身份验证
- javascript - 回调函数无法访问父函数范围内的变量
- javascript - 如何分离日期输入引导日期范围选择器
- airflow - Airflow: how to use xcom_push and xcom_pull in non-PythonOperator
- python - 通过添加 2 个 1D 数组的每个组合在 Python 中创建 2D 矩阵
- python - Flask 不会解释 css、js 文件