java 에서 사용하던 sha256을 그대로 kotlin 으로 변환 했더니 값이 다른 경우가 발생함...

 

아래와 같은 방식으로 처리 후 동일 값 발생 확인.

class Sha256 {
    @Throws(Exception::class)
    fun encoding(param: String): String {
        val HEX_CHARS = "0123456789ABCDEF"
        val bytes = MessageDigest
                .getInstance("SHA-256")
                .digest(param.toByteArray())
        val result = StringBuilder(bytes.size * 2)
        bytes.forEach {
            val i = it.toInt()
            result.append(HEX_CHARS[i shr 4 and 0x0f])
            result.append(HEX_CHARS[i and 0x0f])
        }
        return result.toString()
    }
}



'Development > Kotlin' 카테고리의 다른 글

When Intelli is not working.  (0) 2019.07.04
Find numbers in string in kotlin  (0) 2019.07.02
Kotlin run,with,let,apply  (0) 2018.04.09
Kotlin Study Link  (0) 2018.04.03

+ Recent posts