我正在尝试实现 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();