【发布时间】:2016-09-07 08:20:11
【问题描述】:
我想在客户端 (angular.js) 上加密密码,将其发送到服务器 (express.js) 并在服务器上解密。我想要一个简单的方法。我使用 $http 来发布请求。 我知道退出 angular-bcrypt 库和 nodeJS 中的相同,但对我来说不值得,因为它只有方法比较。
我想要这样的东西:
password = document.getElementById('txtPassword').value;
var xorKey = 129; /// you can have other numeric values also.
var result = "";
for (i = 0; i < password.length; ++i) {
result += String.fromCharCode(xorKey ^ password.charCodeAt(i));
}
但是,我只找到了c#中的解密方法:
public bool Authenticate(string userName, string password)
{
byte result = 0;
StringBuilder inSb = new StringBuilder(password);
StringBuilder outSb = new StringBuilder(password.Length);
char c;
for (int i = 0; i < password.Length; i++)
{
c = inSb[i];
c = (char)(c ^ 129); /// remember to use the same XORkey value you used in javascript
outSb.Append(c);
}
password = outSb.ToString();
// your rest of code
}
有什么想法吗?非常感谢。 :P
【问题讨论】:
标签: javascript angularjs node.js express encryption