ASP implementation of SHA1 encryption and decryption code (and C # compatible) _ Application techniques

Source: Internet
Author: User
Tags hash md5 sha1 sha1 encryption

Baidu looking for several ASP SHA1 (VBS write) encryption results and ASP.net SHA1 encryption results, ASP.net SHA1 after the encryption is 40-bit, the Internet to find the ASP SHA1 encryption is 64-bit, Also thought ASP.net did intercept (such as the online ASP's MD5 secret and asp.net number is not the same, is to do the interception problem), but the ASP's 64-bit encryption results do not contain asp.net 40-bit results, it seems to find the version and ASP.net encryption algorithm is not the same.

Finally or by the wall with Google found a JS version of the SHA1 encryption code combined with the results of ASP and asp.net SHA1 encryption exactly. It seems that the technical type of words with the mother or do not make Google Ah. Casually fuck the Chinese firewall. Google has also been sealed.

ASP SHA1 encryption source code as follows, and ASP.net SHA1 encryption results are consistent:

Copy Code code as follows:

<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
* HTTP://PAJHOME.ORG.UK/CRYPT/MD5 for details.
*/
/*
* Configurable variables. You could need to tweak are 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 and you'll usually want to call
* They take string arguments and return either hex or BASE-64 encoded
*/
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, 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);
x[(len + >> 9) << 4) = Len;
var w = Array (80);
var a = 1732584193;
var b =-271733879;
var c =-1732584194;
var d = 271733878;
var e =-1009589776;
for (var i = 0; i < x.length i + + 16)
{
var Olda = A;
var oldb = b;
var oldc = c;
var oldd = D;
var olde = e;
for (var j = 0; J < + j)
{
if (J <) W[j] = X[i + j];
else w[j] = Rol (w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
var t = safe_add (Safe_add (Rol (A, 5), sha1_ft (J, B, C, D)),
Safe_add (Safe_add (E, w[j]), Sha1_kt (j)));
e = D;
D = C;
c = Rol (b, 30);
b = A;
A = t;
}
A = Safe_add (A, Olda);
b = Safe_add (b, oldb);
c = Safe_add (c, OLDC);
D = Safe_add (d, OLDD);
E = Safe_add (e, Olde);
}
Return Array (A, B, C, D, E);
}
/*
* Perform the appropriate triplet combination function for the current
* Iteration
*/
function sha1_ft (t, B, C, D)
{
if (T <) return (b & c) | ((~b) & D);
if (T <) return b ^ C ^ D;
if (T < a) return (b & c) | (b & D) | (C & D);
Return b ^ C ^ D;
}
/*
* Determine the appropriate additive constant for the current iteration
*/
function Sha1_kt (t)
{
Return (T < 20)?  1518500249: (T < 40)? 1859775393:
(T < 60)? -1894007588:-899497514;
}
/*
* Calculate the HMAC-SHA1 of a key and some data
*/
function Core_hmac_sha1 (key, data)
{
var bkey = str2binb (key);
if (Bkey.length >) bkey = CORE_SHA1 (Bkey, key.length * chrsz);
var ipad = array, Opad = Array (16);
for (var i = 0; i < i++)
{
Ipad[i] = bkey[i] ^ 0x36363636;
Opad[i] = bkey[i] ^ 0x5c5c5c5c;
}
var hash = CORE_SHA1 (str2binb (data), Ipad.concat + data.length * chrsz);
Return Core_sha1 (Opad.concat (hash), 512 + 160);
}
/*
* Add integers, wrapping at 2^32. This uses 16-bit operations internally
* To work around bugs in some JS interpreters.
*/
function Safe_add (x, y)
{
var LSW = (x & 0xFFFF) + (Y & 0xFFFF);
var MSW = (x >>) + (y >>) + (LSW >> 16);
Return (MSW << 16) | (LSW & 0xFFFF);
}
/*
* Bitwise rotate a 32-bit number to the left.
*/
function Rol (num, CNT)
{
return (num << cnt) | (Num >>> (32-cnt));
}
/*
* Convert an 8-bit or 16-bit string to an array of Big-endian words
* in 8-bit function characters >255 have their hi-byte silently.
*/
function Str2binb (str)
{
var bin = Array ();
var mask = (1 << chrsz)-1;
for (var i = 0; i < str.length * Chrsz i + = Chrsz)
BIN[I&GT;&GT;5] |= (Str.charcodeat (I/chrsz) & Mask) << (32-chrsz-i%32);
return bin;
}
/*
* Convert An array of Big-endian words to a string
*/
function Binb2str (BIN)
{
var str = "";
var mask = (1 << chrsz)-1;
for (var i = 0; i < bin.length * i + + = Chrsz)
str = String.fromCharCode ((bin[i>>5] >>> (32-chrsz-i%32)) & mask);
return str;
}
/*
* Convert An array of Big-endian words to a hex string.
*/
function Binb2hex (BinArray)
{
var hex_tab = hexcase? "0123456789ABCDEF": "0123456789abcdef";
var str = "";
for (var i = 0; i < binarray.length * 4; i++)
{
str = Hex_tab.charat ((binarray[i>>2] >> ((3-i%4) *8+4)) & 0xF) +
Hex_tab.charat ((Binarray[i>>2] >> ((3-i%4) *8)) & 0xF);
}
return str;
}
/*
* Convert An array of Big-endian words to a base-64 string
*/
function binb2b64 (BinArray)
{
var tab = "Abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx yz0123456789+/";
var str = "";
for (var i = 0; i < binarray.length * 4; i + + 3)
{
var triplet = ((binarray[i >> 2] >> 8 * (3-i%4) & 0xFF) << 16)
| (((binarray[i+1 >> 2] >> 8 * (3-(i+1)%4) & 0xFF) << 8)
| ((binarray[i+2 >> 2] >> 8 * (3-(i+2)%4) & 0xFF);
for (var j = 0; J < 4; J + +)
{
if (I * 8 + J * 6 > Binarray.length *) str + = B64pad;
else str = Tab.charat ((triplet >> 6* (3-j)) & 0x3F);
}
}
return str;
}
</script>
<%
function Sha1 (Data)
SHA1 = HEX_SHA1 (Data)
End Function
%>
<%
Response.Write (SHA1 ("abcdef"))
%>

Copy Code code as follows:

public void ProcessRequest (HttpContext context)
{
Context. Response.Write (System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile ("abcdef", "SHA1"). ToLower ());
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.