Skip to content

Instantly share code, notes, and snippets.

@jkereako
Last active January 12, 2024 17:25
Show Gist options
  • Save jkereako/ef851307476c164ac0186284588a868e to your computer and use it in GitHub Desktop.
Save jkereako/ef851307476c164ac0186284588a868e to your computer and use it in GitHub Desktop.
Hashing in Swift
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