Sha256 Hashes in Kotlin
Here’s the translation of the SHA256 Hashes example from Go to Kotlin, formatted in Markdown suitable for Hugo:
Our first example demonstrates how to compute SHA256 hashes in Kotlin. SHA256 hashes are frequently used to compute short identities for binary or text blobs. For example, TLS/SSL certificates use SHA256 to compute a certificate’s signature.
Kotlin implements several hash functions in the java.security
package, which we can access through the MessageDigest
class.
Running the program computes the hash and prints it in a human-readable hex format.
You can compute other hashes using a similar pattern to the one shown above. For example, to compute SHA512 hashes, you would use MessageDigest.getInstance("SHA-512")
.
Note that if you need cryptographically secure hashes, you should carefully research hash strength!