diff --git a/src/core/utils/__test__/aes.test.js b/src/core/utils/__test__/aes.test.js new file mode 100644 index 0000000000..6b17963b9d --- /dev/null +++ b/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"); + }); +}); diff --git a/src/core/utils/aes.js b/src/core/utils/aes.js index 9971ebdd42..fcb9c54c51 100644 --- a/src/core/utils/aes.js +++ b/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); } }); }()); \ No newline at end of file