Node.js中的Java的RSA / ECB / OAEPWithSHA-256AndMGF1Padding等效项 [英] Java's RSA/ECB/OAEPWithSHA-256AndMGF1Padding equivalent in Node.js
问题描述
数据解密将使用 RSA / ECB / OAEPWithSHA-256AndMGF1Padding
算法在JAVA中运行。因此,我必须使用与 node.js $ c $中的
RSA / ECB / OAEPWithSHA-256AndMGF1Padding
等效的算法对数据进行加密。 c>。
The data decryption will run in JAVA using RSA/ECB/OAEPWithSHA-256AndMGF1Padding
algorithm. So I have to encrypt the data with public key using the algorithm equivalent to RSA/ECB/OAEPWithSHA-256AndMGF1Padding
in node.js
.
我尝试使用 crypto.publicEncrypt(key,buffer)
,它使用的crypto.constants.RSA_PKCS1_OAEP_PADDING不相似以上算法。
所以我需要等价于 RSA / ECB / OAEPWithSHA-256AndMGF1Padding的算法或如何在node.js中实现相同的算法
I tried with crypto.publicEncrypt(key, buffer)
which uses crypto.constants.RSA_PKCS1_OAEP_PADDING which is not similar to the above algorithm.
So I need algorithm equivalent to "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" or how to achieve the same in node.js
推荐答案
我终于找到了答案。
可以通过node-forge npm模块实现与 RSA / ECB / OAEPWithSHA-256AndMGF1Padding等效。 https://www.npmjs.com/package/node-forge#rsa
I finally found the answer. Equivalent to "RSA/ECB/OAEPWithSHA-256AndMGF1Padding" can be achieved via node-forge npm module. 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()
}
});
谢谢
这篇关于Node.js中的Java的RSA / ECB / OAEPWithSHA-256AndMGF1Padding等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!