ASP.NET 中实现 MD5_HMAC(C#),ASP.NET中,SP.NET中实,P.NET中实现,.NET中实现M,NET中实现MD,ET中实现MD5,T中实现MD5_,中实现MD5_H,实现MD5_HM,现MD5_HMA,MD5_HMAC,D5_HMACC

本站地址:http://www.bajiao123.com

ASP.NET 中实现 MD5_HMAC(C#)
<%@ Page Language="C#" Description="MD5_HMAC ASP.NET" %>
<%@ Import Namespace="System"%>
<%@ Import Namespace="System.IO"%>
<%@ Import Namespace="System.Security"%>
<%@ Import Namespace="System.Security.Cryptography"%>
<%@ Import Namespace="System.Text"%>
<script language="c#" runat=server>
//by skyonline
//Date: 2003/6/3
//MD5 Function
string fun_MD5(string str)
{
byte[] b = System.Text.Encoding.GetEncoding(1252).GetBytes(str);
b=new System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(b);
string ret="";
for(int i=0;i<b.Length;i++)
ret+=b[i].ToString("x").PadLeft(2,´0´);
return ret;
}
Byte[] hexstr2array(string HexStr)
{
string HEX = "0123456789ABCDEF";
string str = HexStr.ToUpper();
int len = str.Length;
byte[] RetByte = new byte[len/2];
for(int i=0; i<len/2; i++)
{
int NumHigh = HEX.IndexOf(str[i*2]);
int NumLow = HEX.IndexOf(str[i*2+1]);
RetByte[i] = Convert.ToByte(NumHigh*16+NumLow);
}
return RetByte;
}
</script>
<%
//these for MD5_HMAC
string ipad="";
string opad="";
{
for(int i=0; i<64; i++)
{
ipad += "6";
opad += "\\";
}
}
string Password= "Jefe";
int KLen = Password.Length;
string iResult = "";
{
for(int i = 0; i < 64; i++)
{
if(i < KLen)
iResult += Convert.ToChar(ipad[i] ^ Password[i]);
else
iResult += Convert.ToChar(ipad[i]);
}
}
iResult += "what do ya want for nothing?";
iResult = fun_MD5(iResult);
byte[] Test = hexstr2array(iResult);
iResult = "";
char[] b = System.Text.Encoding.GetEncoding(1252).GetChars(Test);
for(int i=0;i<b.Length;i++)
{
iResult += b[i];
}
string oResult = "";
{
for (int i=0; i<64; i++)
{
if (i < KLen)
oResult += Convert.ToChar(opad[i] ^ Password[i]);
else
oResult += Convert.ToChar(opad[i]);
本站地址:http://www.bajiao123.com

