Last active
January 12, 2024 17:25
-
-
Save jkereako/ef851307476c164ac0186284588a868e to your computer and use it in GitHub Desktop.
Hashing in Swift
This file contains hidden or 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 CryptoKit | |
/// Hashes a string and returns it as a string. | |
func hash(_ string: String) -> String { | |
guard let data = string.data(using: .utf8) else { return "null" } | |
return SHA256 | |
.hash(data: data) | |
.map { String(format: "%02x", $0) } | |
.joined() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment