Skip to content

Commit

Permalink
Don't repeat the code in B64.getRandomSalt
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbASF committed Jul 30, 2024
1 parent 97b7e5d commit cd91956
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions src/main/java/org/apache/commons/codec/digest/UnixCrypt.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ public class UnixCrypt {
71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102,
103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122 };

private static final char[] SALT_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./"
.toCharArray();

private static final boolean[] SHIFT2 = { false, false, true, true, true, true, true, true, false, true, true,
true, true, true, true, false };

Expand Down Expand Up @@ -250,10 +247,7 @@ public static String crypt(final byte[] original) {
*/
public static String crypt(final byte[] original, String salt) {
if (salt == null) {
final SecureRandom randomGenerator = new SecureRandom();
final int numSaltChars = SALT_CHARS.length;
salt = "" + SALT_CHARS[randomGenerator.nextInt(numSaltChars)] +
SALT_CHARS[randomGenerator.nextInt(numSaltChars)];
salt = B64.getRandomSalt(2);
} else if (!CRYPT_SALT_PATTERN.matcher(salt).matches()) {
throw new IllegalArgumentException("Invalid salt value: " + salt);
}
Expand Down

0 comments on commit cd91956

Please sign in to comment.