我正在尝试对通过ajax以json格式发送的密码进行加密。加密逻辑在我的server.js中
如何传递来自server.js的加密响应。我可以加密,但是我被这个加密的响应卡住了
server.js:
app.post('/mylink',function(request,reply){
var data = JSON.stringify(request.body.jsonblob);
var pwd = request.body.jsonblob.Password;
var cipher = crypto.createCipher(algorithm,password)
var crypted = cipher.update(pan,'utf8','hex')
crypted += cipher.final('hex');
console.log("crypted"+crypted);
reply.send(crypted);
});我的html页面中的ajax调用:
var json_data = JSON.stringify({
"jsonblob" : {
"Password": password
}
});
$.ajax({
url:"/mylink",
type: "post",
dataType: "json",
contentType: "application/json",
data: json_data,
success:function(response){
if(response.status === "success")
{
console.log(crypted);
}
},
error: function(jqXHR, textStatus, errorThtrown) {
console.log("error " +textStatus);
}
});发布于 2018-01-26 22:54:53
我想不出任何您想要向客户端返回加密密码的用例。您在服务器上加密和解密您的密码,以防止您的密码以明文形式存储在数据库中。
我认为您可能混淆了密码的加密和生成JSON Web令牌,稍后可以使用该令牌对用户进行身份验证。在这种情况下,您可能希望返回要保存在客户端的令牌。有许多关于如何构建安全的Node后端的很好的文章。下面是我最喜欢的:
https://medium.freecodecamp.org/securing-node-js-restful-apis-with-json-web-tokens-9f811a92bb52
此外,如果您想保护您的密码,使您的请求内容清晰,请确保您使用HTTPS。
https://stackoverflow.com/questions/48461541
复制相似问题