Last active
February 3, 2023 19:07
-
-
Save bubudrc/b572fa64dc4d18dd803f2ee652ac01e7 to your computer and use it in GitHub Desktop.
HMAC Using SHA1 with Secret Key (Works for other HMAC algorithms) for CryptoKit
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
import Foundation | |
import CryptoKit | |
extension String { | |
func hmacUsingSHA1(_ secretString: String) -> String { | |
let key = SymmetricKey(data: secretString.data(using: .utf8)!) | |
let signature = HMAC<Insecure.SHA1>.authenticationCode(for: self.data(using: .utf8)!, using: key) | |
return Data(signature).map { String(format: "%02hhx", $0) }.joined() | |
} | |
} | |
print("my_string_to_hash".hmacUsingSHA1("SECRET_KEY")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment