我在asp.net中创建了一个wesite并使用ms-sql数据库来保存记录。现在想要在node.js应用程序中进行转换。并希望使用相同的SQL数据库。在asp.net应用程序中,我已经为注册用户加密了密码。以下是代码。Node.js密码加密与Asp.Net相同
public static string CreateHash(string unHashed)
{
System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] data = System.Text.Encoding.ASCII.GetBytes(unHashed);
data = x.ComputeHash(data);
return System.Text.Encoding.ASCII.GetString(data);
}
public static bool MatchHash(string HashData, string HashUser)
{
HashUser = CreateHash(HashUser);
if (HashUser == HashData)
return true;
else
return false;
}
现在的问题是,我如何在node.js中使用相同的加密。所以当节点应用程序准备就绪时,旧用户也可以进行登录。它只有在节点应用程序也可以使用我在asp.net中使用的相同加密时才有可能。
对于节点我创建了所有环境并使用mssql模块进行数据库通信。请帮我解决这个问题。谢谢!!
感谢您的回复,但它似乎不工作。我有使用字符串“testpassword”。 .Net返回“?k * ??#?N ?? 9?l”和节点返回“e16b2ab8d12314bf4efbd6203906ea6c”。节点也应该返回与.net函数相同的值。 – user1951489
@ user1951489我已经更新了答案,因为您给了我更多关于评论中发生的事情的线索。 – alandarev
如果使用.digest('binary'),则节点返回“ák*,Ñ#¶¿NûÖ9♠êl”。它应该返回“?k * ??#?N ?? 9?l” – user1951489