You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
2.1 KiB
44 lines
2.1 KiB
6 months ago
|
<!DOCTYPE html>
|
||
|
<html lang="en">
|
||
|
<head>
|
||
|
<meta charset="UTF-8">
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
<title>Document</title>
|
||
|
<script src ="https://cdn.bootcdn.net/ajax/libs/crypto-js/4.0.0/crypto-js.js"></script>
|
||
|
<script>
|
||
|
// const CryptoJS = require('./node_modules/crypto-js'); //引用AES源码js
|
||
|
|
||
|
const key = CryptoJS.enc.Utf8.parse("a102030405060708"); //十六位十六进制数作为密钥
|
||
|
const iv = CryptoJS.enc.Utf8.parse('a1b2c3d4e5f6g7h8'); //十六位十六进制数作为密钥偏移量
|
||
|
|
||
|
//解密方法
|
||
|
function Decrypt(word) {
|
||
|
const restoreBase64 = word.replace(/\-/g,'+').replace(/_/g,'/');
|
||
|
let decrypt = CryptoJS.AES.decrypt(restoreBase64, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.ZeroPadding });
|
||
|
return CryptoJS.enc.Utf8.stringify(decrypt);
|
||
|
}
|
||
|
|
||
|
//加密方法
|
||
|
function Encrypt(word) {
|
||
|
let encrypted = CryptoJS.AES.encrypt(word, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.ZeroPadding });
|
||
|
const test = encrypted.ciphertext.toString(CryptoJS.enc.Base64);
|
||
|
return test.toString(CryptoJS.enc.Utf8);
|
||
|
}
|
||
|
|
||
|
function init(){
|
||
|
const str='{"server": "mail.intra.nsfocus.com"}';
|
||
|
const res = Encrypt(str);
|
||
|
console.log(res);
|
||
|
console.log(Decrypt('UjQ8vsWGWdJqvGRDCU0DiBqMXOOi9m3BDijNeVFB2+gbyrQVIzsNUTvtW2l20xMEcPzd6RRbZDfelONZiLOrswlqY/JbMSNpRzKFp+8OFp6EcfM948EFRyOjt5UgnbTHVn2Q4FlXDAtKjoJVsn8ZJ+bsQ4Tut2QUuFn5/RZoNuo/8VKuMY5YKgE+fUW003cMAcqSauHXoi5cLOfRlQP4dFIfKpD72mH3HArHsq3Zm3Df4uD00VfTK9lDkoQkuBkMobImm04ggOFmwB3Tb6UtkERZCnJ4UIz+vMBQcHxQZ5oxBvY4DKOqjvUSuRuwkhwU'));
|
||
|
console.log(Decrypt('1fOSbzrfqkgsCsxtMzCBGg=='));
|
||
|
console.log(Decrypt('9uUsqL/bgBitN3Lvnfav5IUKcdDW0o+ooHR5uKMhWsZulRTdbgYSwY22jpkg6YPMnUBPTYCcdodvVT+2qneVigx/+bBPg2lOuDsJXJzvSJpPwGJPiLG9M4fCzjqqvyhs'));
|
||
|
console.log(Decrypt('hnV6BIeQnHfKD+HIGJISesG5GHmFuigENFOSxdorHiwVT5N4dWeW5YhyVFbe7Ne3aU+BdSHzGnMdr7BnMV+0D/6vNp+hZsDK0IUxgsJno9lT5QQyvfsHqc3r+UP62jmm'));
|
||
|
}
|
||
|
|
||
|
init();
|
||
|
</script>
|
||
|
</head>
|
||
|
<body>
|
||
|
|
||
|
</body>
|
||
|
</html>
|