<!doctype html public "-//w3c//dtd html 4.01 transitional//en"
"http://www.w3.org/tr/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>js md5的加密代码</title>
</head><body>
<table width="773" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="30"><div align="center"><strong>md5的加密</strong></div></td>
</tr>
<tr>
<td>
<input id=test value=sina>
<input type=button value=md5 onclick="ye.value=hex_md5(test.value)">
<p>
<textarea style="font-family:fixedsys;font-size:12px;border:1px inset #d3d6d9" cols=40 rows=10 id=ye></textarea>
<script>
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_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));}
function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));}
function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }
function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }/* backwards compatibility - same as hex_md5() */
function calcmd5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));}/*
* perform a simple self-test to see if the vm is working
*/
function md5_vm_test()
{
return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
}/*
* calculate the md5 of an array of little-endian words, and a bit length
*/
function core_md5(x, len)
{
/* append padding */
x[len >> 5] |= 0x80 << ((len) % 32);
x[(((len + 64) >>> 9) << 4) + 14] = len;
var a = 1732584193;
var b = -271733879;
var c = -1732584194;
var d = 271733878;for(var i = 0; i < x.length; i += 16)
{
var olda = a;
var oldb = b;
var oldc = c;
var oldd = d;
a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
c = md5_ff(c, d, a, b, x[i+ 2], 17, 606105819);
b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
d = md5_ff(d, a, b, c, x[i+ 5], 12, 1200080426);
c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
a = md5_ff(a, b, c, d, x[i+ 8], 7 , 1770035416);
d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
a = md5_ff(a, b, c, d, x[i+12], 7 , 1804603682);
d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
b = md5_ff(b, c, d, a, x[i+15], 22, 1236535329);a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
c = md5_gg(c, d, a, b, x[i+11], 14, 643717713);
b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
d = md5_gg(d, a, b, c, x[i+10], 9 , 38016083);
c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
a = md5_gg(a, b, c, d, x[i+ 9], 5 , 568446438);
d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
b = md5_gg(b, c, d, a, x[i+ 8], 20, 1163531501);
a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
c = md5_gg(c, d, a, b, x[i+ 7], 14, 1735328473);
b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
c = md5_hh(c, d, a, b, x[i+11], 16, 1839030562);
b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
d = md5_hh(d, a, b, c, x[i+ 4], 11, 1272893353);
c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
a = md5_hh(a, b, c, d, x[i+13], 4 , 681279174);
d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
b = md5_hh(b, c, d, a, x[i+ 6], 23, 76029189);
a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
c = md5_hh(c, d, a, b, x[i+15], 16, 530742520);
b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
d = md5_ii(d, a, b, c, x[i+ 7], 10, 1126891415);
c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
a = md5_ii(a, b, c, d, x[i+12], 6 , 1700485571);
d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
a = md5_ii(a, b, c, d, x[i+ 8], 6 , 1873313359);
d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
b = md5_ii(b, c, d, a, x[i+13], 21, 1309151649);
a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
c = md5_ii(c, d, a, b, x[i+ 2], 15, 718787259);
b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);a = safe_add(a, olda);
b = safe_add(b, oldb);
c = safe_add(c, oldc);
d = safe_add(d, oldd);
}
return array(a, b, c, d);
}/*
* these functions implement the four basic operations the algorithm uses.
*/
function md5_cmn(q, a, b, x, s, t)
{
return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
}
function md5_ff(a, b, c, d, x, s, t)
{
return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
}
function md5_gg(a, b, c, d, x, s, t)
{
return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
}
function md5_hh(a, b, c, d, x, s, t)
{
return md5_cmn(b ^ c ^ d, a, b, x, s, t);
}
function md5_ii(a, b, c, d, x, s, t)
{
return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
}/*
* calculate the hmac-md5, of a key and some data
*/
function core_hmac_md5(key, data)
{
var bkey = str2binl(key);
if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);var ipad = array(16), opad = array(16);
for(var i = 0; i < 16; i++)
{
ipad[i] = bkey[i] ^ 0x36363636;
opad[i] = bkey[i] ^ 0x5c5c5c5c;
}var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
return core_md5(opad.concat(hash), 512 + 128);
}/*
* 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 >> 16) + (y >> 16) + (lsw >> 16);
return (msw << 16) | (lsw & 0xffff);
}/*
* bitwise rotate a 32-bit number to the left.
*/
function bit_rol(num, cnt)
{
return (num << cnt) | (num >>> (32 - cnt));
}/*
* convert a string to an array of little-endian words
* if chrsz is ascii, characters >255 have their hi-byte silently ignored.
*/
function str2binl(str)
{
var bin = array();
var mask = (1 << chrsz) - 1;
for(var i = 0; i < str.length * chrsz; i += chrsz)
bin[i>>5] |= (str.charcodeat(i / chrsz) & mask) << (i%32);
return bin;
}/*
* convert an array of little-endian words to a hex string.
*/
function binl2hex(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] >> ((i%4)*8+4)) & 0xf) +
hex_tab.charat((binarray[i>>2] >> ((i%4)*8 )) & 0xf);
}
return str;
}/*
* convert an array of little-endian words to a base-64 string
*/
function binl2b64(binarray)
{
var tab = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+/";
var str = "";
for(var i = 0; i < binarray.length * 4; i += 3)
{
var triplet = (((binarray[i >> 2] >> 8 * ( i %4)) & 0xff) << 16)
| (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xff) << 8 )
| ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xff);
for(var j = 0; j < 4; j++)
{
if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
else str += tab.charat((triplet >> 6*(3-j)) & 0x3f);
}
}
return str;
}
</script>
</td>
</tr>
</table>
</body>
</html>
js md5的加密代码
时间: 2024-10-27 06:21:51
js md5的加密代码的相关文章
教你如何解密js/vbs/vbscript加密的编码异处理小结_javascript技巧
js/vbs/vbscript加密代码: <body style="font:12px"> <fieldset> <legend align="center">源码变异处理 </legend> <table> <tr valign=top> <td><br> <button onclick=encJSHTM()> JS 网页加密 </button>
js的加密代码,如何改为php 的代码?
问题描述 js的加密代码,如何改为php 的代码? 最近做一个android的app需要实现一个异步登陆的过程. 需要登陆的网站登陆是需要对用户密码和验证码加密后验证的.我app用webview可以 获取js加密文本之后加密,在进行登陆.但是这样耗时. 为想在服务器把js加密文档写成php的.请问js加密文档写成php可行吗?或者有什么更好的方法亦或者是js在服务器端运行的好方法? 解决方案 如果你有算法,就可以改写.但是要考虑到从客户端手机到服务器的传输过程中的安全性问题.比如说有人在wifi
Node.js中AES加密和其它语言不一致问题解决办法
这篇文章主要介绍了Node.js中AES加密和其它语言不一致问题解决办法,例如和C#.JAVA语言相互通信时,需要的朋友可以参考下 例子一: 这几天被一个问题困扰着.Nodejs的AES加密和Java,C#加密出来的不一致.当然,这样就不能解密了.纠结了许久:后来还是实在不行了,看了下源代码,要不然还得继续纠结下去.网上说,通常的nodejs AES和其他语言实现不一样.好吧~~或许吧. nodejs的crypto模块. 代码如下: var crypto = require('cry
c#算法-C#处理ASCII码以外数字的MD5码加密怎么办?
问题描述 C#处理ASCII码以外数字的MD5码加密怎么办? 1C 比如C++处理(char)-65MD5加密的时候会得到一组数据,C#在做MD5加密的时候会先将字符串转换成byte[]请问怎么用C#处理这同一个数得到相同的结果??很需要解决 解决方案 看你怎么调用的.如果你有C++代码,会很简单.你可以用Encoding.GetEncode(编码).GetBytes得到字节
java-那位大神能把我这个Java的md5的加密方法写个php版本哦,感激噢!
问题描述 那位大神能把我这个Java的md5的加密方法写个php版本哦,感激噢! 那位大神能把我这个Java的md5的加密方法写个php版本哦,感激噢,Java代码如下! 写这个的人 描述的思路如下 1.将秘钥.源串分别转换byte数组 2.声明2个64位数组 将key的byte数组分别做异或运算填充进去 并分别补充 54.92 补满64长度 3.获得md5摘要算法的MessageDigest 对象 4.使用其中一个数组及源串的数组更新MessageDigest 摘要 完成哈希计算 5.重置摘要
ajax-怎么能通过js实现rsa加密
问题描述 怎么能通过js实现rsa加密 如题,想实现js的rsa加密,ajax传输密文.用openssl生成证书 解决方案 网上好像很多 https://www.baidu.com/s?wd=js%20ras%E5%8A%A0%E5%AF%86&rsv_spt=1&rsv_iqid=0xa5fb9a2a0010b112&issp=1&f=8&rsv_bp=1&rsv_idx=2&ie=utf-8&tn=baiduhome_pg&rsv
php结合md5的加密解密算法实例_php技巧
本文实例讲述了php结合md5的加密解密算法.分享给大家供大家参考,具体如下: <?php /* * Created on 2016-9-30 * */ function encrypt($data, $key) { $key = md5($key); $x = 0; $len = strlen($data); $l = strlen($key); for ($i = 0; $i < $len; $i++) { if ($x == $l) { $x = 0; } $char .= $key{$
利用JS延迟加载百度分享代码,提高网页速度
发现很多网站在放置百度分享代码的时候,简单的将分享代码放置到固定的网页位置就完事了,这是非常致命的方式.因为,我经常打开一个网页的时候,发现在网页加载到分享代码的时候,有时候花上几秒的时候来请求百度的服务器,最后展示分享按钮. 其实,像这样对网页来说不是非常重要的功能,我们大可以用JS来延迟加载,从而提高网页主要内容的快速加载显示. 这里分享下我的放置方式.一.copy百度分享代码,如下: 复制代码 代码如下: <!-- Baidu Button BEGIN --> <div id=&q
js异步动态加载js与css文件代码
jquery动态加载css,js文件方法简单很, 例 方法1: 代码如下 $.getscript("test.js"); 方法2: 代码如下 function loadjs(file){ var head = $('head').remove('#loadscript'); $("<scri"+"pt>"+"</scr"+"ipt>").attr({src:file,type: