密码加密 - C#
尝试使用 HTTPWebRequest 模拟文件上传。客户端正在使用此开发人员的 Md5.js MD5.js
在我的 C# 代码中,我是生成这样的加密字符串
public string PasswordHash(string password, string Key)
{
ASCIIEncoding encoding = new ASCIIEncoding();
HMACMD5 hmacmd = new HMACMD5(encoding.GetBytes(Key));
byte[] bytes = encoding.GetBytes(password);
byte[] byteBuffer= hmacmd.ComputeHash(bytes);
StringBuilder builder = new StringBuilder();
for (int i = 0; i < buffer3.Length; i++)
{
builder.Append(byteBuffer[i].ToString("x2"));
}
return builder.ToString().ToLower();
}
接下来使用的是 MD5.js 中的函数:
function hex_hmac_md5(k, d) {
return rstr2hex(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)));
}
使用 fiddler,我在使用 IE 登录时捕获了密钥以及加密的密码。我的代码使用 C# 和相同密钥生成的密码与 JavaScript 方法生成的密码不匹配。我可以缺少什么吗?
C# 密码:5d2b9c906608d8381cef4c24ff045be7
由网站使用 .js 生成并使用 FIDDLER 捕获的密码:f79a31f85da55aa0e3aca07e06568709
Trying to simulate a file upload using HTTPWebRequest. The client side is using Md5.js from this developer MD5.js
In my C# code I am generating the encyptered string as such
public string PasswordHash(string password, string Key)
{
ASCIIEncoding encoding = new ASCIIEncoding();
HMACMD5 hmacmd = new HMACMD5(encoding.GetBytes(Key));
byte[] bytes = encoding.GetBytes(password);
byte[] byteBuffer= hmacmd.ComputeHash(bytes);
StringBuilder builder = new StringBuilder();
for (int i = 0; i < buffer3.Length; i++)
{
builder.Append(byteBuffer[i].ToString("x2"));
}
return builder.ToString().ToLower();
}
The function from MD5.js being used is next:
function hex_hmac_md5(k, d) {
return rstr2hex(rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d)));
}
Using fiddler I captured the key when logging using IE as well as the encrypted password. The password generated by my code using C# and same key does not match that of what the JavaScript method produces. what can I be missing?
C# pwd:5d2b9c906608d8381cef4c24ff045be7
pwd as generated by web site using .js and captured using FIDDLER: f79a31f85da55aa0e3aca07e06568709
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您确定 MD5.js 也使用 ASCII 编码吗?看起来使用的是UTF8
Are you sure MD5.js is also using ASCII encoding? It looks like it is using UTF8
名称空间:
使用“MD5”的代码:
Name Space :
CODE USING "MD5" :