io.provenance.eventstream.utils.Hash.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of es-core Show documentation
Show all versions of es-core Show documentation
A collection of libraries to connect and stream blocks from a node
The newest version!
package io.provenance.eventstream.utils
import java.security.MessageDigest
import java.security.NoSuchAlgorithmException
/**
* Compute a hex-encoded (printable) version of a SHA-256 encoded string.
*
* @param input An array of bytes.
* @return An array of SHA-256 hashed bytes.
*/
fun sha256(input: ByteArray?): ByteArray =
try {
val digest = MessageDigest.getInstance("SHA-256")
digest.digest(input)
} catch (e: NoSuchAlgorithmException) {
throw RuntimeException("Couldn't find a SHA-256 provider", e)
}
/**
* Compute a hex-encoded (printable) version of a SHA-256 encoded string from a series of byte arrays.
*
* @param inputs A series of strings to concatenate and hash.
* @return An array of SHA-256 hashed bytes.
*/
fun sha256(vararg inputs: String?): ByteArray = sha256(inputs.asIterable())
fun sha256(inputs: Iterable): ByteArray =
sha256(inputs.filterNotNull().joinToString("").toByteArray())
© 2015 - 2025 Weber Informatics LLC | Privacy Policy