Created
February 24, 2018 07:42
-
-
Save ecmadao/c1fd642cbff9bd7202f7782ebf2b5fd9 to your computer and use it in GitHub Desktop.
Swift4 HMAC-SHA1-BASE64
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 CommonCrypto | |
extension String { | |
func hmac(key: String) -> String { | |
var digest = [UInt8](repeating: 0, count: Int(CC_SHA1_DIGEST_LENGTH)) | |
CCHmac(CCHmacAlgorithm(kCCHmacAlgSHA1), key, key.count, self, self.count, &digest) | |
let data = Data(bytes: digest) | |
return data.base64EncodedString() | |
} | |
} |
Author
ecmadao
commented
Feb 24, 2018
- CommonCrypto
- Crypto
- CryptoSwift
Thanks,helps me a lot!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment