MD5ė 128ė¹ķø ķ“ģė„¼ ģģ±ķė ģķøķ ķ“ģ ķØģģ
ėė¤.
ėė¶ė¶ ė¬“ź²°ģ± ź²ģ¬ė„¼ ģķ“ ģ¬ģ©ėė¤ ģøģ¦ģ ģķ“ ģ¬ģ©ėė ź²½ģ°ė” ė³ķź³ ģģµėė¤.
ź°ģ ź°ģ ķģ ź°ģ 32ģ(16byte)ģ ķ“ģķØģė„¼ ģģ±ķ©ėė¤.
ģė¬“ė¦¬ ķ° ė°ģ“ķ°ė ź°ģ 32ģģ ķ“ģķØģė„¼ ģģ±ķźø° ėė¬øģ, ė°ģ“ķ°ģ ģ ķØģ±ģ ź²ģ¬ķźø° ģ¢ģµėė¤.
class Md5{
fun encrypt(password: String): String = with(MessageDigest.getInstance("MD5")){
this.update(password.toByteArray())
this.digest()
}
.let {
val sb = StringBuilder()
for (b in it) {
sb.append(String.format("%02x", b))
}
sb.toString()
}
fun verify(raw:String,encrypted:String): Boolean = encrypt(raw) == encrypted
}
-------------------------------------------------------------------------------------
fun main(args: Array<String>) {
val target = "Junnyland"
val md5=Md5()
val encrypt = md5.encrypt(target )
println(md5.verify(target,encrypt)) // true
}