Created
October 13, 2022 08:12
-
-
Save labibmuhajir/99aaeeab28c6b2fa613d09300d576707 to your computer and use it in GitHub Desktop.
sha-256
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
fun String.getSha256(): String { | |
val digest = MessageDigest.getInstance("SHA-256").apply { reset() } | |
val byteData: ByteArray = digest.digest(toByteArray()) | |
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { | |
Base64.getEncoder().encodeToString(byteData) | |
} else { | |
String( | |
android.util.Base64.encode(byteData, android.util.Base64.DEFAULT), | |
StandardCharsets.UTF_8 | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment