tim*_*tim 6 java encryption node.js cryptojs
数据解密将使用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中实现相同的效果
我终于找到了答案。相当于“RSA/ECB/OAEPWithSHA-256AndMGF1Padding”可以通过node-forge npm 模块实现。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()
}
});
Run Code Online (Sandbox Code Playgroud)
谢谢
| 归档时间: |
|
| 查看次数: |
7667 次 |
| 最近记录: |