Node.js 已在会话中保存RSA私钥,但已被破坏
这就是我计划要做的Node.js 已在会话中保存RSA私钥,但已被破坏,node.js,session,encryption,express-session,cryptico,Node.js,Session,Encryption,Express Session,Cryptico,这就是我计划要做的 用户调用我的网站时生成的RSA私钥/公钥 为浏览器提供公钥 在会话中保存私钥(node.js,express会话) 当用户尝试登录时,使用公钥加密id和pw,使用会话中保存的私钥对其进行解密 问题来了。我这样保存私钥 app.get('/', function(req, res) { var passPhrase = 'secret key'; bits = 1024; req.session.rsa = cryptico.generateRSAKey(passPhrase,
app.get('/', function(req, res) {
var passPhrase = 'secret key';
bits = 1024;
req.session.rsa = cryptico.generateRSAKey(passPhrase, bits);
....
}
RSA密钥似乎很长,我附上了图片->
但是,当我在另一个AJAX中从会话调用RSA密钥时,它突然变短,我无法解密消息,因为有一个错误,它说“您的私钥与公钥不匹配”
app.post('/login', function(req, res) {
console.log(req.session.rsa);
}
由于这个问题,我不能使用RSA私钥/公钥来加密/解密id/pw。为什么会这样?为什么req.session中的数据已损坏?我不明白为什么它的价值会改变
这是express会话的设置。这里有什么问题吗?还是其他原因
app.use(session({
store: new RedisStore({
host: 'localhost',
port: 6379,
client: redis,
resave: false
}),
secret: 'keyboard cat',
cookie: {
maxAge: 1000 * 60 * 60
},
resave : false,
saveUninitialized : true
}));
它似乎没有很好的文档记录,但请尝试以下方法:
// storing the key in the session
req.session.rsa = JSON.stringify(cryptico.generateRSAKey(passPhrase, bits).toJSON());
// retrieving the key from the session
let RSAKey = cryptico.RSAKey.parse(req.session.rsa);