asp实现的sha1加密解密代码(和C#兼容)

在百度找的几个asp sha1(vbs写的)加密结果和asp.net的sha1加密结果不一样,asp.net sha1加密完后是40位,网上找的asp sha1加密是64位,还以为asp.net做了截取(如网上的asp的md5机密和asp.net位数不一样,是做了截取的问题),但是asp的64位加密结果并没有包含asp.net的40位结果,看来找到的版本和asp.net的加密算法不一样。
 
最后还是靠翻墙用google找到了一个js版本的sha1加密代码结合asp使用后结果和asp.net的sha1加密一模一样。。看来技术类的文字用度娘还是搞不过谷歌啊。。随便fuck下中国的防火墙。。谷歌也给封了。
 
asp sha1加密源代码如下,和asp.net的sha1加密结果一致:

复制代码 代码如下:

<script language="javascript" type="text/javascript" runat="server">
/*
 * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
 * in FIPS PUB 180-1
 * Version 2.1a Copyright Paul Johnston 2000 - 2002.
 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
 * Distributed under the BSD License
 * See http://pajhome.org.uk/crypt/md5 for details.
 */
/*
 * Configurable variables. You may need to tweak these to be compatible with
 * the server-side, but the defaults work in most cases.
 */
var hexcase = 0;  /* hex output format. 0 - lowercase; 1 - uppercase        */
var b64pad  = "="; /* base-64 pad character. "=" for strict RFC compliance   */
var chrsz   = 8;  /* bits per input character. 8 - ASCII; 16 - Unicode      */
/*
 * These are the functions you'll usually want to call
 * They take string arguments and return either hex or base-64 encoded strings
 */
function hex_sha1(s){return binb2hex(core_sha1(str2binb(s),s.length * chrsz));}
function b64_sha1(s){return binb2b64(core_sha1(str2binb(s),s.length * chrsz));}
function str_sha1(s){return binb2str(core_sha1(str2binb(s),s.length * chrsz));}
function hex_hmac_sha1(key, data){ return binb2hex(core_hmac_sha1(key, data));}
function b64_hmac_sha1(key, data){ return binb2b64(core_hmac_sha1(key, data));}
function str_hmac_sha1(key, data){ return binb2str(core_hmac_sha1(key, data));}
/*
 * Perform a simple self-test to see if the VM is working
 */
function sha1_vm_test()
{
  return hex_sha1("abc") == "a9993e364706816aba3e25717850c26c9cd0d89d";
}
/*
 * Calculate the SHA-1 of an array of big-endian words, and a bit length
 */
function core_sha1(x, len)
{
  /* append padding */
  x[len >> 5] |= 0x80 << (24 - len % 32);

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/2134.html