secureRandomBytes should call getNextBytes, not generateSeed (#2587)

This commit is contained in:
Konstantinos Chalkias 2018-03-08 11:44:26 +00:00 committed by GitHub
parent c3c3a859d5
commit 2e9027db1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View File

@ -168,7 +168,7 @@ fun KeyPair.verify(signatureData: ByteArray, clearData: ByteArray): Boolean = Cr
* which should never happen and suggests an unusual JVM or non-standard Java library.
*/
@Throws(NoSuchAlgorithmException::class)
fun secureRandomBytes(numOfBytes: Int): ByteArray = newSecureRandom().generateSeed(numOfBytes)
fun secureRandomBytes(numOfBytes: Int): ByteArray = ByteArray(numOfBytes).apply { newSecureRandom().nextBytes(this) }
/**
* Get an instance of [SecureRandom] to avoid blocking, due to waiting for additional entropy, when possible.

View File

@ -78,7 +78,7 @@ sealed class SecureHash(bytes: ByteArray) : OpaqueBytes(bytes) {
* Generates a random SHA-256 value.
*/
@JvmStatic
fun randomSHA256() = sha256(newSecureRandom().generateSeed(32))
fun randomSHA256() = sha256(secureRandomBytes(32))
/**
* A SHA-256 hash value consisting of 32 0x00 bytes.