mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 00:17:11 -07:00
Fix MD5.
This commit is contained in:
parent
8c445952b0
commit
7aaffc03e1
1 changed files with 6 additions and 19 deletions
|
@ -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 ->
|
||||
file.forEachBlock { bytes, size ->
|
||||
md5.update(bytes, 0, size)
|
||||
}
|
||||
md5.digest().toHex()
|
||||
fun toMd5(file: File) = MessageDigest.getInstance("MD5").let { md5 ->
|
||||
file.forEachBlock { bytes, size ->
|
||||
md5.update(bytes, 0, size)
|
||||
}
|
||||
|
||||
fun toMd5(bytes: ByteArray): String =
|
||||
MessageDigest.getInstance("MD5").digest(bytes).toHex()
|
||||
md5.digest().toHexString()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun ByteArray.toHex() = buildString {
|
||||
forEach {
|
||||
val byte = it.toInt() and 0xff
|
||||
if (byte < 16) append("0")
|
||||
append(Integer.toHexString(byte))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue