add hash utils
This commit is contained in:
parent
5daf28ac10
commit
4f742e9235
|
|
@ -0,0 +1,11 @@
|
|||
package ru.touchin.common.byte
|
||||
|
||||
object ByteUtils {
|
||||
|
||||
fun ByteArray.toHex(): String {
|
||||
return joinToString(separator = "") { byte ->
|
||||
"%02x".format(byte)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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.calcHash(algorithmName: HashAlgorithm): ByteArray {
|
||||
return MessageDigest.getInstance(algorithmName.name)
|
||||
.digest(this.toByteArray(UTF_8))
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue