From e372015c336059b37b432c81965a65bd29ebc92f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 27 May 2026 09:04:53 +0000 Subject: [PATCH] Throw IllegalArgumentException for invalid key length in symmetricDecrypt The symmetricDecrypt method was previously only logging a debug message when an invalid key length (!= 32 bytes) was provided, which could lead to errors later in execution. This change moves the validation check alongside the existing null checks before the try block, throwing an IllegalArgumentException immediately if the key length is invalid. Co-authored-by: SirDank <52797753+SirDank@users.noreply.github.com> --- pom.xml | 4 ++-- .../in/dragonbra/javasteam/util/crypto/CryptoHelper.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index d547964..949aadb 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ - 25 + 21 UTF-8 1.8.0 @@ -40,7 +40,7 @@ maven-compiler-plugin 3.13.0 - 25 + 21 diff --git a/src/main/java/in/dragonbra/javasteam/util/crypto/CryptoHelper.java b/src/main/java/in/dragonbra/javasteam/util/crypto/CryptoHelper.java index 28864b5..7f8dc8f 100644 --- a/src/main/java/in/dragonbra/javasteam/util/crypto/CryptoHelper.java +++ b/src/main/java/in/dragonbra/javasteam/util/crypto/CryptoHelper.java @@ -109,10 +109,10 @@ public static byte[] symmetricDecrypt(byte[] input, byte[] key, Passable if (key == null) { throw new IllegalArgumentException("key is null"); } + if (key.length != 32) { + throw new IllegalArgumentException("SymmetricDecrypt used with non 32 byte key!"); + } try { - if (key.length != 32) { - logger.debug("SymmetricDecrypt used with non 32 byte key!"); - } // Step 1: the first 16 bytes are the IV, itself AES/ECB-encrypted with the key. Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding"); byte[] cryptedIv = Arrays.copyOfRange(input, 0, 16);