数据解密将使用RSA/ECB/OAEPWithSHA-256AndMGF1Padding
算法在JAVA中运行。因此,我必须使用等效于RSA/ECB/OAEPWithSHA-256AndMGF1Padding
中的算法使用公开密钥加密数据node.js
。
我尝试crypto.publicEncrypt(key, buffer)
使用与上面的算法不相似的crypto.constants.RSA_PKCS1_OAEP_PADDING。所以我需要等效于“ RSA / ECB / OAEPWithSHA-256AndMGF1Padding”的算法,或者如何在node.js中实现相同的算法
我终于找到了答案。可以通过node-forge npm模块实现与“ RSA / ECB / OAEPWithSHA-256AndMGF1Padding”等效。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()
}
});
谢谢
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句