2020-07-20 15:53:10
使用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内已经实现的方法。