暗黑模式
CryptoJS 加密解密
文章Outlook
官方文档
https://cryptojs.gitbook.io/docs
https://www.npmjs.com/package/crypto-js
安装
bash
pnpm add crypto-js
1
AES
js
import CryptoJS from 'crypto-js';
const aesKey = CryptoJS.enc.Hex.parse('secrect key 123')
const encrypted = CryptoJS.AES.encrypt('your password', aesKey, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7,
})
console.log('密钥', encrypted.key.toString())
console.log('加密后', encrypted.ciphertext.toString())
console.log(
'解密后',
CryptoJS.enc.Utf8.stringify(CryptoJS.AES.decrypt(CryptoJS.format.Hex.parse(encrypted.ciphertext.toString()), aesKey, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7,
})),
)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17