diff options
author | mayx | 2022-01-04 20:42:55 +0800 |
---|---|---|
committer | mayx | 2022-01-04 20:42:55 +0800 |
commit | f4aa957c53cda659d026ffd23856f65a72fee739 (patch) | |
tree | afc51b78e1ff241c955ca30910e895e02e0a1d22 /_layouts/encrypt.html |
Restore deleted repositories
Diffstat (limited to '_layouts/encrypt.html')
-rw-r--r-- | _layouts/encrypt.html | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/_layouts/encrypt.html b/_layouts/encrypt.html new file mode 100644 index 0000000..153a27e --- /dev/null +++ b/_layouts/encrypt.html @@ -0,0 +1,55 @@ +--- +layout: post +--- + +<script src="/js/aes.js"></script> +<script> +function getByteLen(val) { + var len = 0; + for (var i = 0; i < val.length; i++) { + if (val[i].match(/[^\x00-\xff]/ig) != null) len += 3; + else len += 1; + } + return len; +} + +function onbtnDecrypto() { + var encryptedData = "{{ content | strip_html | strip_newlines }}"; + var keyword = document.getElementById("inputkey").value; + + if (keyword.replace(/(^\s*)|(\s*$)/g, "") == '') { + alert("请输入密码!"); + return; + } + while (getByteLen(keyword) % 8 != 0) { + keyword = keyword + "\0"; + } + + var key = CryptoJS.enc.Utf8.parse(keyword); + var encryptedHexStr = CryptoJS.enc.Hex.parse(encryptedData); + var encryptedBase64Str = CryptoJS.enc.Base64.stringify(encryptedHexStr); + + var decryptedData = CryptoJS.AES.decrypt(encryptedBase64Str, key, { + mode: CryptoJS.mode.ECB, + padding: CryptoJS.pad.Pkcs7 + }); + + if (decryptedData.sigBytes < 0) { + document.getElementById("output").innerHTML = "解密失败!密文或者key错误!"; + return; + } + try { + decryptedData.toString(CryptoJS.enc.Utf8) + } catch(e) { + document.getElementById("output").innerHTML = "解密失败!密文或者key错误!"; + return; + } + var decryptedStr = decryptedData.toString(CryptoJS.enc.Utf8); + document.getElementById("output").innerHTML = decryptedStr; + document.getElementById("pwinput").style.display = "none"; +} +</script> +<div id="pwinput">{{ page.tips | default: "请输入密码:" }}<br /> + <input id="inputkey" type="password" /> <button onclick="onbtnDecrypto()">解密</button> +</div> +<div id="output"></div> <br /> |