[英]Java's RSA/ECB/OAEPWithSHA-256AndMGF1Padding equivalent in Node.js
The data decryption will run in JAVA using RSA/ECB/OAEPWithSHA-256AndMGF1Padding
algorithm.数据解密将使用
RSA/ECB/OAEPWithSHA-256AndMGF1Padding
算法在 JAVA 中运行。 So I have to encrypt the data with public key using the algorithm equivalent to RSA/ECB/OAEPWithSHA-256AndMGF1Padding
in node.js
.因此,我必须使用等效于
node.js
中RSA/ECB/OAEPWithSHA-256AndMGF1Padding
的算法使用公钥加密数据。
I tried with crypto.publicEncrypt(key, buffer)
which uses crypto.constants.RSA_PKCS1_OAEP_PADDING which is not similar to the above algorithm.我尝试使用
crypto.publicEncrypt(key, buffer)
,它使用与上述算法不相似的 crypto.constants.RSA_PKCS1_OAEP_PADDING 。 So I need algorithm equivalent to "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" or how to achieve the same in node.js所以我需要等同于“RSA/ECB/OAEPWithSHA-256AndMGF1Padding”的算法或者如何在 node.js 中实现相同的算法
I finally found the answer.我终于找到了答案。 Equivalent to "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" can be achieved via node-forge npm module.
相当于“RSA/ECB/OAEPWithSHA-256AndMGF1Padding”可以通过node-forge npm模块实现。 https://www.npmjs.com/package/node-forge#rsa
https://www.npmjs.com/package/node-forge#rsa
// encrypt data with a public key using RSAES-OAEP/SHA-256/MGF1-SHA-1
// compatible with Java's RSA/ECB/OAEPWithSHA-256AndMGF1Padding
var encrypted = publicKey.encrypt(bytes, 'RSA-OAEP', {
md: forge.md.sha256.create(),
mgf1: {
md: forge.md.sha256.create()
}
});
Thank you谢谢
Firstly, you shouldn't use "ECB" mode cipher, because:首先,你不应该使用“ECB”模式密码,因为:
MSC61-J. MSC61-J。 Do not use insecure or weak cryptographic algorithms
不要使用不安全或弱加密算法
So, in this case, you just need to use OAEP for RSA encryption, because it's a padding scheme and it helpts to prevent Oracle Padding for asymetric algorithms, then change your code for: RSA/None/OAEPWithSHA-256AndMGF1Padding
.因此,在这种情况下,您只需要使用 OAEP 进行 RSA 加密,因为它是一种填充方案,它有助于防止 Oracle Padding 用于非对称算法,然后将您的代码更改为:
RSA/None/OAEPWithSHA-256AndMGF1Padding
。 Maybe, you could get compatibility with Node.js.也许,您可以获得与 Node.js 的兼容性。 Also, I recommend you visit the official web site:
另外,我建议您访问官方网站:
I hope this information helps you.希望这些信息对您有所帮助。
Good luck.祝你好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.