数据解密将使用this.router.events.subscribe((val) => {
// see also
let id = this.route.snapshot.paramMap["id"];
console.log(id)
});
算法在JAVA中运行。因此,我必须使用与RSA/ECB/OAEPWithSHA-256AndMGF1Padding
中的RSA/ECB/OAEPWithSHA-256AndMGF1Padding
等效的算法使用公共密钥加密数据。
我尝试了node.js
,它使用与上述算法不相似的crypto.constants.RSA_PKCS1_OAEP_PADDING。
因此,我需要等效于“ RSA / ECB / OAEPWithSHA-256AndMGF1Padding”的算法,或者如何在node.js中实现相同的算法
答案 0 :(得分:1)
我终于找到了答案。 可以通过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()
}
});
谢谢
答案 1 :(得分:-2)
首先,您不应该使用“ ECB”模式密码,因为:
MSC61-J. Do not use insecure or weak cryptographic algorithms
因此,在这种情况下,您只需要使用OAEP进行RSA加密,因为它是一种填充方案,并且有助于防止Oracle Padding使用非对称算法,然后将代码更改为RSA/None/OAEPWithSHA-256AndMGF1Padding
。也许您可以获得与Node.js的兼容性。另外,我建议您访问官方网站:
希望这些信息对您有所帮助。
祝你好运。