在会话中保存了 RSA 私钥,但它已被破坏
Saved RSA private key in session, but it has been spoiled
这就是我的计划。
- 当用户调用我的网站时生成 RSA private/public 密钥
- 将 public 密钥提供给浏览器
- 在会话中保存私钥(node.js,快速会话)
- 当用户尝试登录时使用public密钥加密id和pw,用我保存在session
中的私钥解密
问题来了。我是这样保存私钥的
app.get('/', function(req, res) {
var passPhrase = 'secret key';
bits = 1024;
req.session.rsa = cryptico.generateRSAKey(passPhrase, bits);
....
}
而且RSA密钥好像很长,我附上图片->
RSA that I generated first(image)
但是当我从另一个 AJAX 的会话中调用 RSA 密钥时,它突然变短了,我无法解密消息,因为出现错误,它说“你的私钥与public键'
app.post('/login', function(req, res) {
console.log(req.session.rsa);
}
RSA that I loaded from the session in app.post('/login')
因为这个问题,我不能使用 RSA private/public 密钥到 encrypt/decrypt id/pw。为什么会这样?为什么 req.session 中的数据被破坏了?我不明白为什么其中的值会改变。
这是快速会话的设置。这里有问题吗?还是其他原因?
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);
这就是我的计划。
- 当用户调用我的网站时生成 RSA private/public 密钥
- 将 public 密钥提供给浏览器
- 在会话中保存私钥(node.js,快速会话)
- 当用户尝试登录时使用public密钥加密id和pw,用我保存在session 中的私钥解密
问题来了。我是这样保存私钥的
app.get('/', function(req, res) {
var passPhrase = 'secret key';
bits = 1024;
req.session.rsa = cryptico.generateRSAKey(passPhrase, bits);
....
}
而且RSA密钥好像很长,我附上图片-> RSA that I generated first(image)
但是当我从另一个 AJAX 的会话中调用 RSA 密钥时,它突然变短了,我无法解密消息,因为出现错误,它说“你的私钥与public键'
app.post('/login', function(req, res) {
console.log(req.session.rsa);
}
RSA that I loaded from the session in app.post('/login')
因为这个问题,我不能使用 RSA private/public 密钥到 encrypt/decrypt id/pw。为什么会这样?为什么 req.session 中的数据被破坏了?我不明白为什么其中的值会改变。
这是快速会话的设置。这里有问题吗?还是其他原因?
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);