Skip to content

Commit 3b492a9

Browse files
therepanicrwinch
authored andcommitted
remove 32-byte minimum keyLength restriction in Base64StringKeyGenerator (#17012)
Signed-off-by: Andrey Litvitski <[email protected]>
1 parent c22091d commit 3b492a9

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

crypto/src/main/java/org/springframework/security/crypto/keygen/Base64StringKeyGenerator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
2424
*
2525
* @author Joe Grandja
2626
* @author Rob Winch
27+
* @author Andrey Litvitski
2728
* @since 5.0
2829
*/
2930
public class Base64StringKeyGenerator implements StringKeyGenerator {
@@ -67,8 +68,8 @@ public Base64StringKeyGenerator(Base64.Encoder encoder, int keyLength) {
6768
if (encoder == null) {
6869
throw new IllegalArgumentException("encode cannot be null");
6970
}
70-
if (keyLength < DEFAULT_KEY_LENGTH) {
71-
throw new IllegalArgumentException("keyLength must be greater than or equal to " + DEFAULT_KEY_LENGTH);
71+
if (keyLength <= 0) {
72+
throw new IllegalArgumentException("keyLength must be greater than 0");
7273
}
7374
this.encoder = encoder;
7475
this.keyGenerator = KeyGenerators.secureRandom(keyLength);

crypto/src/test/java/org/springframework/security/crypto/keygen/Base64StringKeyGeneratorTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,13 +25,14 @@
2525

2626
/**
2727
* @author Rob Winch
28+
* @author Andrey Litvitski
2829
* @since 5.0
2930
*/
3031
public class Base64StringKeyGeneratorTests {
3132

3233
@Test
33-
public void constructorIntWhenLessThan32ThenIllegalArgumentException() {
34-
assertThatIllegalArgumentException().isThrownBy(() -> new Base64StringKeyGenerator(31));
34+
public void constructorIntWhenEqual0ThenIllegalArgumentException() {
35+
assertThatIllegalArgumentException().isThrownBy(() -> new Base64StringKeyGenerator(0));
3536
}
3637

3738
@Test

0 commit comments

Comments
 (0)