This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-codec.git


The following commit(s) were added to refs/heads/master by this push:
     new cd91956c Don't repeat the code in B64.getRandomSalt
cd91956c is described below

commit cd91956caf3aed9402b6a0c43affc3a7e8546661
Author: Sebb <[email protected]>
AuthorDate: Tue Jul 30 16:01:26 2024 +0100

    Don't repeat the code in B64.getRandomSalt
---
 src/main/java/org/apache/commons/codec/digest/UnixCrypt.java | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/commons/codec/digest/UnixCrypt.java 
b/src/main/java/org/apache/commons/codec/digest/UnixCrypt.java
index 2917acf7..3b5a4b5f 100644
--- a/src/main/java/org/apache/commons/codec/digest/UnixCrypt.java
+++ b/src/main/java/org/apache/commons/codec/digest/UnixCrypt.java
@@ -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 };
 
@@ -250,10 +247,7 @@ public class UnixCrypt {
      */
     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);
         }

Reply via email to