crypto-js 数据加密

import CryptoJS from 'crypto-js'
import Base64 from 'crypto-js/enc-base64'
import Utf8 from 'crypto-js/enc-utf8'
import sha256 from 'crypto-js/sha256'
const secretKey = 'BANG_TU'
export function getBase64(str: string) {
  return Base64.stringify(Utf8.parse(str))
}

export function getSha256(str: string) {
  return sha256(str).toString()
}

export function encrypt(str: string) {
  return CryptoJS.AES.encrypt(str, secretKey).toString()
}

export function decrypt(str: string) {
  const bytes = CryptoJS.AES.decrypt(str, secretKey)
  return bytes.toString(CryptoJS.enc.Utf8)
}

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐