Merge pull request #26 from TouchInstinct/feature/hash-utils
add hash utils
This commit is contained in:
commit
facff6525d
|
|
@ -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.calculateHash(algorithmName: HashAlgorithm): ByteArray {
|
||||
return MessageDigest.getInstance(algorithmName.name)
|
||||
.digest(this.toByteArray(UTF_8))
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue