㈠ 介绍一点js加密的方法

你可以到网上下载下面所用的js文件。
1、base64加密
在页面中引入base64.js文件,调用方法为:
<scripttype="text/javascript"src="base64.js"></script>
<scripttype="text/javascript">
varb=newBase64();
varstr=b.encode("admin:admin");
alert("base64encode:"+str);
str=b.decode(str);
alert("base64decode:"+str);
</script>
2、md5加密
在页面中引用md5.js文件,调用方法为
<scripttype="text/ecmascript"src="md5.js"></script>
<scripttype="text/javascript">
varhash=hex_md5("123dafd");
alert(hash)
</script>
3、sha1加密
据说这是最安全的加密
页面中引入sha1.js,调用方法为
<scripttype="text/ecmascript"src="sha1.js"></script>
<scripttype="text/javascript">
varsha=hex_sha1('mima123465')
alert(sha)
</script>

㈡ 怎么使用js sha512加密

使用js sha512加密的方法:

1、首先去git上下载sha512.js引入需要调用的页面上。

2、调用方法,在head和</head>之间的script标签写入以下js代码:

function calcHash() {

try {

var hashInput = document.getElementById("hashInputText");

var hashInputType = document.getElementById("hashInputType");

var hashVariant = document.getElementById("hashVariant");

var hashRounds = document.getElementById("hashRounds");

var hashOutputType = document.getElementById("hashOutputType");

var hashOutput = document.getElementById("hashOutputText");

var hashObj = new jsSHA(

hashVariant.options[hashVariant.selectedIndex].value,

hashInputType.options[hashInputType.selectedIndex].value,

{numRounds: parseInt(hashRounds.value, 10)}

);

hashObj.update(hashInput.value);

hashOutput.value = hashObj.getHash(hashOutputType.options[hashOutputType.selectedIndex].value);

} catch(e) {

hashOutput.value = e.message

}

}


function calcHMAC() {

try {

var hmacText = document.getElementById("hmacInputText");

var hmacTextType = document.getElementById("hmacTextType");

var hmacKeyInput = document.getElementById("hmacInputKey");

var hmacKeyInputType = document.getElementById("hmacKeyType");

var hmacVariant = document.getElementById("hmacVariant");

var hmacOutputType = document.getElementById("hmacOutputType");

var hmacOutput = document.getElementById("hmacOutputText");

var hmacObj = new jsSHA(

hmacVariant.options[hmacVariant.selectedIndex].value,

hmacTextType.options[hmacTextType.selectedIndex].value

);

hmacObj.setHMACKey(

hmacKeyInput.value,

hmacKeyInputType.options[hmacKeyInputType.selectedIndex].value

);

hmacObj.update(hmacText.value);


hmacOutput.value = hmacObj.getHMAC(hmacOutputType.options[hmacOutputType.selectedIndex].value);

} catch(e) {

hmacOutput.value = e.message

}

}

其中jsSHA是sha512.js内已经实现的方法。