This repository has been archived by the owner on Jan 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Hashing
Jong Wook Kim edited this page Feb 2, 2017
·
1 revision
여러 종류의 해시 알고리즘을 간단하게 쓸 수 있는 도구입니다. 내부적으로 Guava를 사용합니다.
import com.kakao.mango.hashing._
println(Md5("hello")) // 5d41402abc4b2a76b9719d911017c592
println(Sha256("hello")) // 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
println(Sha512("hello")) // 9b71d224bd62f3785d96d46ad3ea3d73319bfbc2890caadae2dff72519673ca72323c3d99ba5c11d7c7acc6e14b8c5da0c4663475c2e5c3adef46f73bcdec043
println(Murmur3_32("hello")) // 47fa8b24
println(Murmur3_128("hello")) // 029bbd41b3a7d8cb191dae486a901e5b
// 12345를 seed로 사용한 mmh3
val mmh3: Hash = Murmur3_32(12345)
println(mmh3("hello")) // b7ceca4e
String타입의 hexdigest를 리턴하며, 해시의 바이트 배열이 필요한 경우 Md5.bytes("hello")
처럼 사용할 수 있습니다.
Murmur3_32
의 경우 다른 라이브러리들은 32비트 정수를 리턴하는 경우가 많은데, 그 정수의 16진수 표현과 mango의 hexdigest와는 차이가 있습니다. 첫 번째 바이트부터 문자열로 인코딩하는 hexdigest와 LSB가 우측에 표시되는 16진수 정수 표현의 순서가 반대이기 때문입니다. 이 방식은 Murmur3_128
과의 일관성이 있습니다.