Skip to content

Instantly share code, notes, and snippets.

@markvanwijnen
Last active March 8, 2021 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markvanwijnen/796a5c620e8c43e803347d8eb3936eaa to your computer and use it in GitHub Desktop.
Save markvanwijnen/796a5c620e8c43e803347d8eb3936eaa to your computer and use it in GitHub Desktop.
import CommonCrypto
extension String {
func hmacSHA1Hash(key: String) -> String {
var digest = [UInt8](repeating: 0, count: Int(CC_SHA1_DIGEST_LENGTH))
CCHmac(CCHmacAlgorithm(kCCHmacAlgSHA1),
key,
key.count,
self,
self.count,
&digest)
return Data(digest).base64EncodedString()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment