Skip to content

Commit 2272be7

Browse files
committed
Fixed: Replace RandomStringUtils with custom salt generation in HashCrypt for enhanced security
(cherry picked from commit 3dd9014)
1 parent bc6eaff commit 2272be7

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

  • framework/base/src/main/java/org/apache/ofbiz/base/crypto

framework/base/src/main/java/org/apache/ofbiz/base/crypto/HashCrypt.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
import org.apache.commons.codec.binary.Base64;
3333
import org.apache.commons.codec.binary.Hex;
34-
import org.apache.commons.lang.RandomStringUtils;
3534
import org.apache.ofbiz.base.util.Debug;
3635
import org.apache.ofbiz.base.util.GeneralRuntimeException;
3736
import org.apache.ofbiz.base.util.StringUtil;
@@ -148,7 +147,13 @@ public static String cryptBytes(String hashType, String salt, byte[] bytes) {
148147
hashType = "SHA";
149148
}
150149
if (salt == null) {
151-
salt = RandomStringUtils.random(SECURE_RANDOM.nextInt(15) + 1, CRYPT_CHAR_SET);
150+
int length = SECURE_RANDOM.nextInt(15) + 1;
151+
StringBuilder saltBuilder = new StringBuilder(length);
152+
for (int i = 0; i < length; i++) {
153+
int index = SECURE_RANDOM.nextInt(CRYPT_CHAR_SET.length());
154+
saltBuilder.append(CRYPT_CHAR_SET.charAt(index));
155+
}
156+
salt = saltBuilder.toString();
152157
}
153158
StringBuilder sb = new StringBuilder();
154159
sb.append("$").append(hashType).append("$").append(salt).append("$");

0 commit comments

Comments
 (0)