mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -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
|
package com.beust.kobalt.maven
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.rmi.toHexString
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.file.Files
|
|
||||||
import java.nio.file.Paths
|
|
||||||
import java.security.MessageDigest
|
import java.security.MessageDigest
|
||||||
|
|
||||||
public class Md5 {
|
public class Md5 {
|
||||||
companion object {
|
companion object {
|
||||||
fun toMd5(file: File) =
|
fun toMd5(file: File) = MessageDigest.getInstance("MD5").let { md5 ->
|
||||||
MessageDigest.getInstance("MD5").let { md5 ->
|
file.forEachBlock { bytes, size ->
|
||||||
file.forEachBlock { bytes, size ->
|
md5.update(bytes, 0, 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))
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue