AES全称高级加密标准(英语:Advanced Encryption Standard,缩写:AES),在密码学中又称Rijndael加密法。
前端加密解密
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| <script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js" integrity="sha512-E8QSvWZ0eCLGk4km3hxSsNmGWbLtSCSUcewDQPQWZF6pEU8GlT8a5fF32wOl1i8ftdMhssTrF/OhyGWwonTcXA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
function aesEncode(str,key) { key = CryptoJS.enc.Utf8.parse(key); var encryptedData = CryptoJS.AES.encrypt(str, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }); return encryptedData.toString(); }
function aesDecode(encryptedStr,key) { key = CryptoJS.enc.Utf8.parse(key); var encryptedHexStr = CryptoJS.enc.Base64.parse(encryptedStr); var encryptedBase64Str = CryptoJS.enc.Base64.stringify(encryptedHexStr); var decryptedData = CryptoJS.AES.decrypt(encryptedBase64Str, key, { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }); return decryptedData.toString(CryptoJS.enc.Utf8); }
|
后端加密解密
添加封装的依赖hu-tool
1 2 3 4 5
| <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>5.7.22</version> </dependency>
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, "qeNm3eXK/BCAwTVoEjfaGQ==".getBytes(StandardCharsets.UTF_8));
byte[] encrypt = aes.encrypt(content);
byte[] decrypt = aes.decrypt(encrypt);
String decryptStr = aes.decryptStr(encrypt, CharsetUtil.CHARSET_UTF_8);
|
封面