From 63017bc248ff6099ff09d88ae5ba90ff828bd990 Mon Sep 17 00:00:00 2001 From: Isaac Levy Date: Wed, 27 Sep 2017 12:02:14 -0400 Subject: [PATCH] Fix crypto bit check --- modules/user/src/main/PasswordHasher.scala | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/user/src/main/PasswordHasher.scala b/modules/user/src/main/PasswordHasher.scala index fcbe631b9e..869cfb3d88 100644 --- a/modules/user/src/main/PasswordHasher.scala +++ b/modules/user/src/main/PasswordHasher.scala @@ -16,11 +16,11 @@ import com.roundeights.hasher.Implicits._ private[user] final class Aes(secret: String) { private val sKey = { val sk = Base64.getDecoder.decode(secret) - if (sk.length != 16) { - if (!(sk.length == 24 || sk.length == 32)) - throw new IllegalArgumentException("Invalid key length") - if (sk.length > Cipher.getMaxAllowedKeyLength("AES/CTS/NoPadding")) - throw new IllegalStateException(s"${sk.length * 8}b AES unavailable") + val kBits = sk.length * 8 + if (kBits != 128) { + if (!(kBits == 192 || kBits == 256)) throw new IllegalArgumentException + if (kBits > Cipher.getMaxAllowedKeyLength("AES/CTS/NoPadding")) + throw new IllegalStateException(s"$kBits bit AES unavailable") } new SecretKeySpec(sk, "AES") }