index.js 482 Bytes
Newer Older
zhanghaozhe committed
1 2 3
import aes from 'crypto-js/aes'
import Crypto from 'crypto-js'

zhanghaozhe committed
4 5 6
const key = Crypto.enc.Hex.parse('C7D590D00FA968A261BDD5B6CD40DDC2C0561338BF8B9197')
const iv = Crypto.enc.Hex.parse('19513F90B7A8875E469E82195F90EE99')

zhanghaozhe committed
7 8

function encrypt(message) {
zhanghaozhe committed
9 10 11 12
    return aes.encrypt(message, key, {
        iv,
        mode: Crypto.mode.CBC,
    }).toString()
zhanghaozhe committed
13 14 15
}

function decrypt(encrypted) {
zhanghaozhe committed
16
    return Crypto.enc.Utf8.stringify(aes.decrypt(encrypted, key, {iv}))
zhanghaozhe committed
17 18 19
}

export { encrypt, decrypt }