问题描述
JS的hex_hmac_md5方法加密得到的密码,怎么用.net后台加密得到一样的密码:代码为:<scriptsrc="JS/md5.js"type="text/javascript"></script><scripttype="text/javascript">functionclickFun(){varstr='abcd';varc=hex_hmac_md5(str,str);alert(c);//密码为:1faa00eb25c23ca3ac47d7cceab1a33f}</script>现在怎么让后台加密“abcd”同样得到相同密码:1faa00eb25c23ca3ac47d7cceab1a33f
解决方案
解决方案二:
求高手指导啊,求大神
解决方案三:
varbytes=Encoding.Default.GetBytes("abcd");varhmacmd5=newHMACMD5{Key=bytes};varhash=hmacmd5.ComputeHash(bytes);varc=string.Concat(hash.Select(b=>b.ToString("x2")));Console.WriteLine(c);
解决方案四:
解决方案五:
usingSystem.Text;usingSystem.Security.Cryptography;publicstaticstringGetSignByHmacMd5(stringkey,stringcode){byte[]keyBytes=Encoding.Default.GetBytes(key);byte[]hasCodeBytes=Encoding.Default.GetBytes(code);stringresult=string.Empty;using(HMACMD5hmac=newHMACMD5(keyBytes)){byte[]hashValue=hmac.ComputeHash(hasCodeBytes);result=string.Concat(hashValue.Select(b=>b.ToString("x2")));}returnresult.ToUpper();}
解决方案六:
额,微软其实自己就用HMACMD5类,所以你只需要查msdn手册就ok了