Created
August 2, 2018 14:47
-
-
Save es0329/f2d8c1deeba79e97d023eaebe833f744 to your computer and use it in GitHub Desktop.
Compute hash for arbitrary input.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.util.Base64 | |
import java.security.MessageDigest | |
fun computeHash(input: String, algorithm: String = "SHA-256"): String { | |
// https://developer.android.com/reference/java/security/MessageDigest | |
val messageDigest = MessageDigest.getInstance(algorithm).apply { | |
update(input.toByteArray()) | |
} | |
return Base64.encodeToString(messageDigest.digest(), Base64.DEFAULT) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment