From 2232fe83fe5dd0edcead0c470cafd2c453a309fc Mon Sep 17 00:00:00 2001 From: liudonghua Date: Mon, 17 Jun 2024 02:44:45 +0000 Subject: [PATCH 1/2] config default iv to fix aes error when key passed as wordarray and iv is not provided --- src/cipher-core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cipher-core.js b/src/cipher-core.js index 125632c..d01a420 100644 --- a/src/cipher-core.js +++ b/src/cipher-core.js @@ -28,7 +28,7 @@ CryptoJS.lib.Cipher || (function (undefined) { * * @property {WordArray} iv The IV to use for this operation. */ - cfg: Base.extend(), + cfg: Base.extend({iv: WordArray.create()}), /** * Creates this cipher in encryption mode. From bbc87bea529bb84ae04ac47176f34e8e94f012a6 Mon Sep 17 00:00:00 2001 From: liudonghua Date: Mon, 17 Jun 2024 03:45:20 +0000 Subject: [PATCH 2/2] add test for encrypt/decrypt without cfg --- test/aes-test.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/test/aes-test.js b/test/aes-test.js index ca589dd..a522d8a 100644 --- a/test/aes-test.js +++ b/test/aes-test.js @@ -75,6 +75,11 @@ YUI.add('algo-aes-test', function (Y) { // Restore random method C.lib.WordArray.random = random; - } + }, + + testWithoutCfg: function () { + Y.Assert.areEqual('69c4e0d86a7b0430d8cdb78070b4c55a9e978e6d16b086570ef794ef97984232', C.AES.encrypt(C.enc.Hex.parse('00112233445566778899aabbccddeeff'), C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f')).ciphertext.toString()); + Y.Assert.areEqual('00112233445566778899aabbccddeeff', C.AES.decrypt(C.lib.CipherParams.create({ ciphertext: C.enc.Hex.parse('69c4e0d86a7b0430d8cdb78070b4c55a9e978e6d16b086570ef794ef97984232') }), C.enc.Hex.parse('000102030405060708090a0b0c0d0e0f')).toString()); + }, })); }, '$Rev$');