crypto.js 944 B

1234567891011121314151617181920212223242526272829303132333435
  1. // https://github.com/brix/crypto-js
  2. import CryptoJS from 'crypto-js';
  3. const key = CryptoJS.enc.Utf8.parse("1234123412ABCDEF"); //十六位十六进制数作为密钥
  4. const iv = CryptoJS.enc.Utf8.parse('ABCDEF1234123412'); //十六位十六进制数作为密钥偏移量
  5. //解密方法
  6. function Decrypt(word) {
  7. let encryptedHexStr = CryptoJS.enc.Hex.parse(word);
  8. let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
  9. let decrypt = CryptoJS.AES.decrypt(srcs, key, {
  10. iv: iv,
  11. mode: CryptoJS.mode.CBC,
  12. padding: CryptoJS.pad.Pkcs7
  13. });
  14. let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
  15. return decryptedStr.toString();
  16. }
  17. //加密方法
  18. function Encrypt(word) {
  19. let srcs = CryptoJS.enc.Utf8.parse(word);
  20. let encrypted = CryptoJS.AES.encrypt(srcs, key, {
  21. iv: iv,
  22. mode: CryptoJS.mode.CBC,
  23. padding: CryptoJS.pad.Pkcs7
  24. });
  25. return encrypted.ciphertext.toString().toUpperCase();
  26. }
  27. export default {
  28. Decrypt,
  29. Encrypt
  30. }