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

zhanghaozhe committed
4 5 6 7
const key = Crypto.enc.Hex.parse(
  "C7D590D00FA968A261BDD5B6CD40DDC2C0561338BF8B9197"
)
const iv = Crypto.enc.Hex.parse("19513F90B7A8875E469E82195F90EE99")
zhanghaozhe committed
8 9

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

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

zhanghaozhe committed
22
export { encrypt, decrypt }