Last active
February 22, 2017 09:53
-
-
Save nenadvulic/1e83516a68fc78a04075b909b69c7669 to your computer and use it in GitHub Desktop.
SHA1 in Swift 3
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
func hmacsha1(_ data:Data!, secret key:Data!) -> Data! { | |
let cHMAC = UnsafeMutablePointer<CUnsignedChar>.allocate(capacity:Int(CC_SHA1_DIGEST_LENGTH)) | |
key.withUnsafeBytes {(keyBytes: UnsafePointer<UInt8>)->Void in | |
data.withUnsafeBytes {(dataBytes: UnsafePointer<UInt8>)->Void in | |
CCHmac(CCHmacAlgorithm(kCCHmacAlgSHA1),keyBytes, key.count, dataBytes, data.count, cHMAC) | |
} | |
} | |
return Data(bytes:cHMAC, count:Int(CC_SHA1_DIGEST_LENGTH)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment