javascript - 为什么更改语言时会出现此 RSA 填充错误?
问题描述
所以我试图用 RSA 加密 C# 中的数据,并用 JavaScript 也用 RSA 解密它。
这是我用来在 C# 中加密数据的函数:
private static byte[] Encrypt(byte[] input, bool server)
{
byte[] encrypted;
using (var rsa = new RSACryptoServiceProvider(4096))
{
rsa.PersistKeyInCsp = false;
if (server)
{
rsa.ImportParameters(ImportPublicKey(Main.PUBLIC_KEY_SERVER).ExportParameters(false));
}
else
{
rsa.ImportParameters(publicKey);
}
encrypted = rsa.Encrypt(input, true);
}
return encrypted;
}
这是我用来解密 JavaScript 数据的代码:
function decryptMessage(encryptedMessage, privateKey) {
console.log(encryptedMessage);
const rsaPrivateKey = {
key: privateKey,
passphrase: '',
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING
};
const decryptedMessage = crypto.privateDecrypt(
rsaPrivateKey,
Buffer.from(encryptedMessage, 'base64'),
);
return decryptedMessage.toString('utf8');
}
现在的问题是我总是得到错误:
Error: error:04099079:rsa routines:RSA_padding_check_PKCS1_OAEP_mgf1:oaep decoding error
我不知道为什么。出于某种原因,加密填充似乎不再相同。有没有办法解决这个问题?
〜路易
解决方案
推荐阅读
- python - 将数字标签转换回原始字符串
- r - 在闪亮的应用程序 R 的 tabitem 部分添加图像
- java - 在 Visual Studio 代码中为 system.out.println 创建快捷方式
- c - 如何将 mmap “翻译”为 Windows ABI?
- mysql - MySql中列值组合的一个实例
- reactjs - 如何使用 ReactJS 在 OpenLayer6 中使弹出窗口工作?
- arrays - 如何在调用函数之前等待数组具有最终值?
- javascript - 我应该如何通过我在 vue 3 中的视图发送数据?
- vue.js - Vue:跟踪一个与动态组件相关的 JS 错误
- java - JTextPane 在 Java 8 和 Java 17 之间以不同方式包装文本