Skip to content

Remove 32-byte minimum keyLength restriction in Base64StringKeyGenerator #17091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,6 +24,7 @@
*
* @author Joe Grandja
* @author Rob Winch
* @author Andrey Litvitski
* @since 5.0
*/
public class Base64StringKeyGenerator implements StringKeyGenerator {
Expand Down Expand Up @@ -67,8 +68,8 @@ public Base64StringKeyGenerator(Base64.Encoder encoder, int keyLength) {
if (encoder == null) {
throw new IllegalArgumentException("encode cannot be null");
}
if (keyLength < DEFAULT_KEY_LENGTH) {
throw new IllegalArgumentException("keyLength must be greater than or equal to " + DEFAULT_KEY_LENGTH);
if (keyLength <= 0) {
throw new IllegalArgumentException("keyLength must be greater than 0");
}
this.encoder = encoder;
this.keyGenerator = KeyGenerators.secureRandom(keyLength);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,13 +25,14 @@

/**
* @author Rob Winch
* @author Andrey Litvitski
* @since 5.0
*/
public class Base64StringKeyGeneratorTests {

@Test
public void constructorIntWhenLessThan32ThenIllegalArgumentException() {
assertThatIllegalArgumentException().isThrownBy(() -> new Base64StringKeyGenerator(31));
public void constructorIntWhenEqual0ThenIllegalArgumentException() {
assertThatIllegalArgumentException().isThrownBy(() -> new Base64StringKeyGenerator(0));
}

@Test
Expand Down