use only one SecureRandom

This commit is contained in:
Jörg Prante 2022-04-28 19:23:11 +02:00
parent 2c11a18aa0
commit 51a3af22bf
2 changed files with 9 additions and 10 deletions

View file

@ -1,5 +1,7 @@
package org.xbib.groovy.crypt
import org.xbib.groovy.crypt.random.RandomUtil
import javax.crypto.Mac
import javax.crypto.SecretKeyFactory
import javax.crypto.spec.PBEKeySpec
@ -9,7 +11,6 @@ import java.nio.ByteOrder
import java.nio.charset.StandardCharsets
import java.security.MessageDigest
import java.security.NoSuchAlgorithmException
import java.security.SecureRandom
/**
* A utility class for invoking encryption methods and returning LDAP password string,
@ -17,8 +18,6 @@ import java.security.SecureRandom
*/
class CryptUtil {
private static final Random random = new SecureRandom()
static String hexDigest(String plainText, String algo, String prefix) throws NoSuchAlgorithmException {
if (plainText == null) {
return null
@ -152,13 +151,7 @@ class CryptUtil {
}
static String randomHexString(int length) {
randomBytes(length).encodeHex()
}
static byte[] randomBytes(int length) {
byte[] b = new byte[length]
random.nextBytes(b)
b
RandomUtil.randomBytes(length).encodeHex()
}
static ByteBuffer htonl(int value) {

View file

@ -11,4 +11,10 @@ class RandomUtil {
secureRandom.nextBytes(b)
b.encodeHex().toString()
}
static byte[] randomBytes(int length) {
byte[] b = new byte[length]
secureRandom.nextBytes(b)
b
}
}