当前位置:编程学习 > C#/ASP.NET >>

PHP中HMAC-SHA1算法怎么改成ASP.NET代码实现(C#)

PHP版本
function get_signature($str, $key)
{
    $signature = "";
    if (function_exists('hash_hmac'))
    {
        $signature = base64_encode(hash_hmac("sha1", $str, $key, true));
    }
    else
    {
        $blocksize    = 64;
        $hashfunc    = 'sha1';
        if (strlen($key) > $blocksize)
        {
            $key = pack('H*', $hashfunc($key));
        }
        $key    = str_pad($key,$blocksize,chr(0x00));
        $ipad    = str_repeat(chr(0x36),$blocksize);
        $opad    = str_repeat(chr(0x5c),$blocksize);
        $hmac     = pack(
            'H*',$hashfunc(
                ($key^$opad).pack(
                    'H*',$hashfunc(
                        ($key^$ipad).$str
                    )
                )
            )
        );
        $signature = base64_encode($hmac);
    }

    return $signature;
}
这个是PHP版本的,但是我现在要改成ASP.NET的版本,请问高手们怎么修改。。。急,急,急。。。  --------------------编程问答-------------------- 顶!!!!!!!!!!!!!!!!!!!!!!!!!
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,