Browse Source

Merge pull request #1266 in VISUAL/fineui from ~FAY/fineui:master to master

* commit '999e5d794fa8487d29fc737af509ab7e35dc89f6':
  补充单元测试
  KERNEL-2840 增加一个aes解密方法
es6
fay 5 years ago
parent
commit
617e1f8497
  1. 26
      src/core/utils/__test__/aes.test.js
  2. 15
      src/core/utils/aes.js

26
src/core/utils/__test__/aes.test.js

@ -0,0 +1,26 @@
/*
* @Author: fay
* @Date: 2020-03-02 16:50:24
* @LastEditor: fay
* @LastEditTime: 2020-03-02 16:56:43
*/
describe("aesDecrypt", function () {
/**
* test_author_fay
*/
it("aesEncrypt", function () {
var text = "test";
expect(BI.aesEncrypt(text, "0123456789ABCDEF")).to.eql("0No4i/uz2cfoo6zQMHaL1A==");
});
/**
* test_author_fay
*/
it("aesDecrypt", function () {
var text = "0No4i/uz2cfoo6zQMHaL1A==";
expect(BI.aesDecrypt(text, "0123456789ABCDEF")).to.eql("test");
});
});

15
src/core/utils/aes.js

@ -2326,6 +2326,21 @@
var base64Cipher = cipher.ciphertext.toString(CryptoJS.enc.Base64);
return base64Cipher;
},
/**
* aes解密方法
* @param {String} text
* @param {String} key
*/
aesDecrypt: function (text, key) {
key = CryptoJS.enc.Utf8.parse(key);
var decipher = CryptoJS.AES.decrypt(text, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
return CryptoJS.enc.Utf8.stringify(decipher);
}
});
}());
Loading…
Cancel
Save