C# 输入输出均为string的HMAC-MD5

     public    bool  hmac_md5( string  timespan,   password,255);">ref    outdigest)
    
{

        

byte[] b_tmp;

        

[] b_tmp1;

        

string szRet = .Empty;

        

if (password ==null|| password.Length <1)
        
{

            

returnfalse;

        }


        

[] digest new[512];

        

[] k_ipad 64[] k_opad [] source  System.Text.ASCIIEncoding.ASCII.GetBytes(password);

        System.Security.Cryptography.MD5 shainner 

 MD5CryptoServiceProvider();

        

for (int i 0; i ; i++)
        
{

            k_ipad[i] 

^0x36;

            k_opad[i] 

0x5ctry
        
 (source.Length >)
            
{

                shainner 

 MD5CryptoServiceProvider();

                source 

 shainner.ComputeHash(source);

            }


            

 source.Length; i)
            
{

                k_ipad[i] 

)(source[i] );

                k_opad[i] 

);

            }


            b_tmp1 

 System.Text.ASCIIEncoding.ASCII.GetBytes(timespan);

            b_tmp 

 adding(k_ipad, b_tmp1);

            shainner 

 MD5CryptoServiceProvider();

            digest 

 shainner.ComputeHash(b_tmp);

            b_tmp 

 adding(k_opad, digest);

            shainner 

 shainner.ComputeHash(b_tmp);

//             for (int i = 0; i < digest.Length; i++)

             {

                outdigest  System.Text.ASCIIEncoding.ASCII.GetString(digest);[i].ToString(); 

                 

             }            truecatch (Exception e)
        
{

            outdigest 

 e.Message.ToString();

            


    }


    
/***

    * * 填充byte

     **

*/

    

byte [] adding( [] a,0);">[] b)
    
[] c [a.Length + b.Length];

        a.CopyTo(c, 

);

        b.CopyTo(c, a.Length);

        

 c;

    }

 

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...