aes.js 528 B

12345678910111213
  1. const CryptoJS = require('crypto-js');
  2. export function Encrypt(word, keyStr = '1234567891231231') {
  3. const key = CryptoJS.enc.Utf8.parse(keyStr); //十六位十六进制数作为密钥
  4. const iv = CryptoJS.enc.Utf8.parse(keyStr); //十六位十六进制数作为密钥偏移量
  5. const srcs = CryptoJS.enc.Utf8.parse(word);
  6. var encrypted = CryptoJS.AES.encrypt(srcs, key, {
  7. iv: iv,
  8. mode: CryptoJS.mode.CBC,
  9. padding: CryptoJS.pad.Pkcs7
  10. });
  11. return CryptoJS.enc.Base64.stringify(encrypted.ciphertext).replace(/\s/g, '')
  12. }