1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00
This commit is contained in:
Cedric Beust 2015-11-17 21:30:40 -08:00
parent 8c445952b0
commit 7aaffc03e1

View file

@ -1,29 +1,16 @@
package com.beust.kobalt.maven
import org.jetbrains.kotlin.rmi.toHexString
import java.io.File
import java.nio.file.Files
import java.nio.file.Paths
import java.security.MessageDigest
public class Md5 {
companion object {
fun toMd5(file: File) =
MessageDigest.getInstance("MD5").let { md5 ->
fun toMd5(file: File) = MessageDigest.getInstance("MD5").let { md5 ->
file.forEachBlock { bytes, size ->
md5.update(bytes, 0, size)
}
md5.digest().toHex()
md5.digest().toHexString()
}
fun toMd5(bytes: ByteArray): String =
MessageDigest.getInstance("MD5").digest(bytes).toHex()
}
}
private fun ByteArray.toHex() = buildString {
forEach {
val byte = it.toInt() and 0xff
if (byte < 16) append("0")
append(Integer.toHexString(byte))
}
}