javascript
AES
下面设置opt为了使每次加密,都会生成相同的密文
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23const AESCrypt = require('crypto-js/aes')
const encUtf8 = require('crypto-js/enc-utf8')
const modeCFB = require('crypto-js/mode-cfb')
const NoPadding = require('crypto-js/pad-nopadding')
const IV = 'nirvana'
const opt = {
iv: encUtf8.parse(IV),
mode: modeCFB,
padding: NoPadding
}
let AES = {
encrypt: (text, secretkey) => {
let enText = AESCrypt.encrypt(text, encUtf8.parse(secretkey), opt).toString()
return atob(enText)
},
decrypt: (text, secretKey) => {
let deText = btoa(text)
return AESCrypt.decrypt(deText, encUtf8.parse(secretKey), opt).toString(encUtf8)
}
}
export { AES }