Last active
February 11, 2018 11:17
-
-
Save telliott99/b648b36813a70d84b0f1 to your computer and use it in GitHub Desktop.
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 | |
func doIt() { | |
let s = "The quick brown fox jumps over the lazy dog." | |
let n = Int(CC_MD5_DIGEST_LENGTH) | |
let len = CC_LONG(s.utf8.count) | |
let ctx = UnsafeMutablePointer<CC_MD5_CTX>.alloc(1) | |
var digest = Array<UInt8>(count:n, repeatedValue:0) | |
CC_MD5_Init(ctx) | |
CC_MD5_Update(ctx, s, len) | |
CC_MD5_Final(&digest, ctx) | |
ctx.dealloc(1) | |
let hL = digest.map { String(format:"%02x", $0) } | |
print(hL.reduce("", combine: +)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is no need to allocate
CC_MD5_CTX
.