소스 검색

AES Decrypt now handles blank IVs correctly. Fixes #613

n1474335 5 년 전
부모
커밋
863551ee1d
2개의 변경된 파일32개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      src/core/operations/AESDecrypt.mjs
  2. 31 0
      tests/operations/tests/Crypt.mjs

+ 1 - 1
src/core/operations/AESDecrypt.mjs

@@ -91,7 +91,7 @@ The following algorithms will be used based on the size of the key:
 
         const decipher = forge.cipher.createDecipher("AES-" + mode, key);
         decipher.start({
-            iv: iv,
+            iv: iv.length === 0 ? "" : iv,
             tag: gcmTag
         });
         decipher.update(forge.util.createBuffer(input));

+ 31 - 0
tests/operations/tests/Crypt.mjs

@@ -54,6 +54,21 @@ The following algorithms will be used based on the size of the key:
             }
         ],
     },
+    {
+        name: "AES Encrypt: AES-128-CTR, no IV, ASCII",
+        input: "The quick brown fox jumps over the lazy dog.",
+        expectedOutput: "a98c9e8e3b7c894384d740e4f0f4ed0be2bbb1e0e13a255812c3c6b0a629e4ad759c075b2469c6f4fb2c0cf9",
+        recipeConfig: [
+            {
+                "op": "AES Encrypt",
+                "args": [
+                    {"option": "Hex", "string": "00112233445566778899aabbccddeeff"},
+                    {"option": "Hex", "string": ""},
+                    "CTR", "Raw", "Hex"
+                ]
+            }
+        ],
+    },
     {
         name: "AES Encrypt: AES-128-CBC with IV, ASCII",
         input: "The quick brown fox jumps over the lazy dog.",
@@ -645,6 +660,22 @@ The following algorithms will be used based on the size of the key:
             }
         ],
     },
+    {
+        name: "AES Decrypt: AES-128-CTR, no IV, ASCII",
+        input: "a98c9e8e3b7c894384d740e4f0f4ed0be2bbb1e0e13a255812c3c6b0a629e4ad759c075b2469c6f4fb2c0cf9",
+        expectedOutput: "The quick brown fox jumps over the lazy dog.",
+        recipeConfig: [
+            {
+                "op": "AES Decrypt",
+                "args": [
+                    {"option": "Hex", "string": "00112233445566778899aabbccddeeff"},
+                    {"option": "Hex", "string": ""},
+                    "CTR", "Hex", "Raw",
+                    {"option": "Hex", "string": ""}
+                ]
+            }
+        ],
+    },
     {
         name: "AES Decrypt: AES-128-CBC with IV, ASCII",
         input: "4fa077d50cc71a57393e7b542c4e3aea0fb75383b97083f2f568ffc13c0e7a47502ec6d9f25744a061a3a5e55fe95e8d",