-
-
Save BrandonRoehl/5233deb8b84bbac90d23a6e3dce2660f to your computer and use it in GitHub Desktop.
get md5 hash from Data in swift
This file contains hidden or 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 CommonCrypto | |
| extension Data { | |
| var md5 : String { | |
| var digest = [UInt8](repeating: 0, count: Int(CC_MD5_DIGEST_LENGTH)) | |
| _ = self.withUnsafeBytes { bytes in | |
| CC_MD5(bytes, CC_LONG(self.count), &digest) | |
| } | |
| var digestHex = "" | |
| for index in 0..<Int(CC_MD5_DIGEST_LENGTH) { | |
| digestHex += String(format: "%02x", digest[index]) | |
| } | |
| return digestHex | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just forked because I always have to remember the imports