From 1b9c5574ff6c0f8b6a7796f27a7ebc419a038f6c Mon Sep 17 00:00:00 2001 From: Fay Date: Mon, 2 Mar 2020 16:43:00 +0800 Subject: [PATCH 1/2] =?UTF-8?q?KERNEL-2840=20=E5=A2=9E=E5=8A=A0=E4=B8=80?= =?UTF-8?q?=E4=B8=AAaes=E8=A7=A3=E5=AF=86=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/utils/aes.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/core/utils/aes.js b/src/core/utils/aes.js index 9971ebdd4..fcb9c54c5 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 From 999e5d794fa8487d29fc737af509ab7e35dc89f6 Mon Sep 17 00:00:00 2001 From: Fay Date: Mon, 2 Mar 2020 16:57:46 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=A1=A5=E5=85=85=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/utils/__test__/aes.test.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/core/utils/__test__/aes.test.js diff --git a/src/core/utils/__test__/aes.test.js b/src/core/utils/__test__/aes.test.js new file mode 100644 index 000000000..6b17963b9 --- /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"); + }); +});