JS实现密码加密
1、base64加密
在页面中引入base64.js文件,调用方法为:
DOCTYPE HTML>
<</SPAN>html>
<</SPAN>head>
<</SPAN>meta charset="utf-8">
<</SPAN>title>base64加密</</SPAN>title>
<</SPAN>script type="text/javascript" src="base64.js"></</SPAN>script>
<</SPAN>script type="text/javascript">
var b = new Base64();
var str = b.encode("admin:admin");
alert("base64 encode:" + str);
//解密
str = b.decode(str);
alert("base64 decode:" + str);
</</SPAN>script>
</</SPAN>head>
<</SPAN>body>
</</SPAN>body>
</</SPAN>html>
2、md5加密
在页面中引用md5.js文件,调用方法为
DOCTYPE HTML>
<</SPAN>html>
<</SPAN>head>
<</SPAN>meta charset="utf-8">
<</SPAN>title>md5加密</</SPAN>title>
<</SPAN>script type="text/ecmascript" src="md5.js"></</SPAN>script>
<</SPAN>script type="text/javascript">
var hash = hex_md5("123dafd");
alert(hash)
</</SPAN>script>
</</SPAN>head>
<</SPAN>body>
</</SPAN>body>
</</SPAN>html>
3、sha1加密
据说这是最安全的加密
页面中引入sha1.js,调用方法为
DOCTYPE HTML>
<</SPAN>html>
<</SPAN>head>
<</SPAN>meta charset="utf-8">
<</SPAN>title>sha1加密</</SPAN>title>
<</SPAN>script type="text/ecmascript" src="sha1.js"></</SPAN>script>
<</SPAN>script type="text/javascript">
var sha = hex_sha1('mima123465')
alert(sha)
</</SPAN>script>
</</SPAN>head>
<</SPAN>body>
</</SPAN>body>
</</SPAN>html>