Created
June 19, 2019 08:57
-
-
Save zonble/abb59b110d7c8960c3e0734f9a96b919 to your computer and use it in GitHub Desktop.
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 UIKit | |
| import CryptoKit | |
| import CommonCrypto | |
| let str = "Boom boom boom boom boom boom" | |
| // CryptoKit | |
| func MD5CryptoKit(string: String) -> Data { | |
| string.data(using:.utf8)!.withUnsafeBytes { ptr in | |
| Data(Insecure.MD5.hash(bufferPointer: ptr).map { $0 }[0..<Insecure.MD5.byteCount]) | |
| } | |
| } | |
| MD5CryptoKit(string: str).base64EncodedString() | |
| // Common Crypto | |
| func MD5CommonCrypto(string: String) -> Data { | |
| let length = Int(CC_MD5_DIGEST_LENGTH) | |
| let messageData = string.data(using:.utf8)! | |
| var digestData = Data(count: length) | |
| _ = digestData.withUnsafeMutableBytes { digestBytes -> UInt8 in | |
| messageData.withUnsafeBytes { messageBytes -> UInt8 in | |
| if let messageBytesBaseAddress = messageBytes.baseAddress, let digestBytesBlindMemory = digestBytes.bindMemory(to: UInt8.self).baseAddress { | |
| let messageLength = CC_LONG(messageData.count) | |
| CC_MD5(messageBytesBaseAddress, messageLength, digestBytesBlindMemory) | |
| } | |
| return 0 | |
| } | |
| } | |
| return digestData | |
| } | |
| MD5CommonCrypto(string: str).base64EncodedString() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍