CORDA-1092 - fix secureRandomBytes (#2766)

This commit is contained in:
Konstantinos Chalkias 2018-03-08 15:12:18 +00:00 committed by Katelyn Baker
parent eede1cf6a1
commit d32dbc33c5
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. * which should never happen and suggests an unusual JVM or non-standard Java library.
*/ */
@Throws(NoSuchAlgorithmException::class) @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. * 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. * Generates a random SHA-256 value.
*/ */
@JvmStatic @JvmStatic
fun randomSHA256() = sha256(newSecureRandom().generateSeed(32)) fun randomSHA256() = sha256(secureRandomBytes(32))
/** /**
* A SHA-256 hash value consisting of 32 0x00 bytes. * A SHA-256 hash value consisting of 32 0x00 bytes.