crypt-helper.js 582 B

1234567891011121314151617181920212223
  1. // crypt-helper.js
  2. // CryptoJS 已经由 cdn 引入,可直接使用
  3. (function () {
  4. class CryptToJS {
  5. constructor() {
  6. this.crypt = CryptoJS;
  7. this.secret = 'Believe in yourself.';
  8. }
  9. Encrypt(text) {
  10. return this.crypt.AES.encrypt(text, this.secret).toString();
  11. }
  12. Decrypt(text) {
  13. if (!text) return "";
  14. return this.crypt.AES.decrypt(text, this.secret).toString(this.crypt.enc.Utf8);
  15. }
  16. }
  17. // 关键:挂载到 window
  18. window.CryptToJS = new CryptToJS();
  19. })();