我正在尝试使用节点js库node-rsa
来通过两个密钥交换地加密和解密。这是我的意思的示例:
const NodeRSA = require('node-rsa')
const key1 = new NodeRSA({b: 512})
const key2 = new NodeRSA({b: 512})
const e0 = 'Hello RSA!'
const e1 = key1.encrypt(e0, 'base64')
const e2 = key2.encrypt(e1, 'base64')
const e3 = key2.decrypt(e2, 'utf8')
const e4 = key1.decrypt(e3, 'utf8')
console.log(e4)
我希望能够像这样切换删除顺序:
const NodeRSA = require('node-rsa')
const key1 = new NodeRSA({b: 512})
const key2 = new NodeRSA({b: 512})
const e0 = 'Hello RSA!'
const e1 = key1.encrypt(e0, 'base64')
const e2 = key2.encrypt(e1, 'base64')
const e3 = key1.decrypt(e2, 'utf8')
const e4 = key2.decrypt(e3, 'utf8')
console.log(e4) // this should return 'Hello RSA!' just like before
我相信这是有可能的,因为rsa是可交换的,但这是行不通的,运行此代码时出现错误。我如何对其进行修改以使其起作用?