简体   繁体   中英

Convert Byte Array to String in Kotlin

I'm trying to generate MD5 of a string in my android code using kotlin..

val md5 = MessageDigest.getInstance("MD5")
val hash = md5.digest(queryToSign.toByteArray(Charset.defaultCharset())).toString()

But this gives me:

[B@118072

Any thoughts?

Solved it.. Use BigInteger

val md5 = MessageDigest.getInstance("MD5")
val hash = BigInteger(1, md5.digest(queryToSign.toByteArray(Charset.defaultCharset()))).toString(16)

byteArrayOf(80,87,68).decodeToString()

= PWD

click here to see how it works

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM