Merge pull request #26 from TouchInstinct/feature/hash-utils

add hash utils
This commit is contained in:
Alexander Buntakov 2021-06-20 15:51:38 +03:00 committed by GitHub
commit facff6525d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 0 deletions

View File

@ -0,0 +1,11 @@
package ru.touchin.common.byte
object ByteUtils {
fun ByteArray.toHex(): String {
return joinToString(separator = "") { byte ->
"%02x".format(byte)
}
}
}

View File

@ -0,0 +1,17 @@
package ru.touchin.common.security.hash
import java.nio.charset.StandardCharsets.UTF_8
import java.security.MessageDigest
object HashUtils {
enum class HashAlgorithm {
MD5
}
fun String.calculateHash(algorithmName: HashAlgorithm): ByteArray {
return MessageDigest.getInstance(algorithmName.name)
.digest(this.toByteArray(UTF_8))
}
}