Skip to content

Commit ab83ed5

Browse files
committed
CODEC-253: simplify B64
1 parent 49de012 commit ab83ed5

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

  • src/main/java/org/apache/commons/codec/digest

src/main/java/org/apache/commons/codec/digest/B64.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,11 @@ static void b64from24bit(final byte b2, final byte b1, final byte b0, final int
7575
* @return a random salt {@link String}.
7676
*/
7777
static String getRandomSalt(final int num) {
78-
final StringBuilder saltString = new StringBuilder(num);
7978
try {
80-
final SecureRandom current = SecureRandom.getInstance("SHA1PRNG");
81-
for (int i = 1; i <= num; i++) {
82-
saltString.append(B64T.charAt(current.nextInt(B64T.length())));
83-
}
79+
return getRandomSalt(num, SecureRandom.getInstanceStrong());
8480
} catch (NoSuchAlgorithmException e) {
85-
throw new RuntimeException(e);
81+
throw new IllegalStateException(e);
8682
}
87-
return saltString.toString();
8883
}
8984

9085
/**
@@ -98,10 +93,10 @@ static String getRandomSalt(final int num) {
9893
* @return a random salt {@link String}.
9994
*/
10095
static String getRandomSalt(final int num, final Random random) {
101-
final StringBuilder saltString = new StringBuilder(num);
102-
for (int i = 1; i <= num; i++) {
103-
saltString.append(B64T.charAt(random.nextInt(B64T.length())));
104-
}
105-
return saltString.toString();
96+
final StringBuilder saltString = new StringBuilder(num);
97+
for (int i = 1; i <= num; i++) {
98+
saltString.append(B64T.charAt(random.nextInt(B64T.length())));
99+
}
100+
return saltString.toString();
106101
}
107102
}

0 commit comments

Comments
 (0)