Last active
          January 24, 2022 15:33 
        
      - 
      
- 
        Save jstn/787da74ab4be9d4cf3cb to your computer and use it in GitHub Desktop. 
Revisions
- 
        jstn revised this gist Sep 6, 2016 . 2 changed files with 3 additions and 1 deletion.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -1 +0,0 @@ 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,6 @@ // requires a bridging header with this: // #import <CommonCrypto/CommonCrypto.h> func MD5(_ string: String) -> String? { let length = Int(CC_MD5_DIGEST_LENGTH) var digest = [UInt8](repeating: 0, count: length) 
- 
        jstn revised this gist Sep 6, 2016 . No changes.There are no files selected for viewing
- 
        jstn revised this gist Sep 6, 2016 . 2 changed files with 11 additions and 13 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ #import <CommonCrypto/CommonCrypto.h> 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 charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,12 @@ func MD5(_ string: String) -> String? { let length = Int(CC_MD5_DIGEST_LENGTH) var digest = [UInt8](repeating: 0, count: length) if let d = string.data(using: String.Encoding.utf8) { d.withUnsafeBytes { (body: UnsafePointer<UInt8>) in CC_MD5(body, CC_LONG(d.count), &digest) } } return (0..<length).reduce("") { $0 + String(format: "%02x", digest[$1]) } } 
- 
        jstn revised this gist Aug 5, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,7 @@ func MD5(string: String) -> String { let a = UnsafeBufferPointer<CUnsignedChar>(start: resultBytes, length: result.length) let hash = NSMutableString() for i in a { hash.appendFormat("%02x", i) } 
- 
        jstn revised this gist Aug 5, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,7 @@ func MD5(string: String) -> String { let a = UnsafeBufferPointer<CUnsignedChar>(start: resultBytes, length: result.length) let hash = NSMutableString() for i in a { hash.appendFormat("%02x", i) } return hash 
- 
        jstn revised this gist Aug 4, 2014 . 1 changed file with 3 additions and 5 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -1,13 +1,11 @@ func MD5(string: String) -> String { let data = (string as NSString).dataUsingEncoding(NSUTF8StringEncoding) let result = NSMutableData(length: Int(CC_MD5_DIGEST_LENGTH)) let resultBytes = UnsafeMutablePointer<CUnsignedChar>(result.bytes) CC_MD5(data.bytes, CC_LONG(data.length), resultBytes) let a = UnsafeBufferPointer<CUnsignedChar>(start: resultBytes, length: result.length) let hash = NSMutableString() for i in a { hash.appendFormat("%02x", a[Int(i)]) } 
- 
        jstn revised this gist Aug 3, 2014 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,15 @@ func MD5(string: String) -> String { let data = string.bridgeToObjectiveC().dataUsingEncoding(NSUTF8StringEncoding) let result = NSMutableData(length: Int(CC_MD5_DIGEST_LENGTH)) let resultBytes = UnsafePointer<CUnsignedChar>(result.bytes) CC_MD5(data.bytes, CC_LONG(data.length), resultBytes) let a = UnsafeArray<CUnsignedChar>(start: resultBytes, length: result.length) let hash = NSMutableString() for i in a { hash.appendFormat("%02x", a[Int(i)]) } return hash 
- 
        jstn revised this gist Aug 3, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ func MD5(string: String) -> String { let data = string.bridgeToObjectiveC().dataUsingEncoding(NSUTF8StringEncoding) var result = NSMutableData(length: Int(CC_MD5_DIGEST_LENGTH)) let bytes = UnsafePointer<CUnsignedChar>(result.mutableBytes) CC_MD5(data.bytes, CC_LONG(data.length), bytes) 
- 
        jstn revised this gist Aug 3, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ func MD5(string: String) -> String { let data = string.bridgeToObjectiveC().dataUsingEncoding(NSUTF8StringEncoding) let result = NSMutableData(length: Int(CC_MD5_DIGEST_LENGTH)) let bytes = UnsafePointer<CUnsignedChar>(result.mutableBytes) CC_MD5(data.bytes, CC_LONG(data.length), bytes) 
- 
        jstn created this gist Aug 3, 2014 .There are no files selected for viewingThis 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ func MD5(string: String) -> String { let data = string.bridgeToObjectiveC().dataUsingEncoding(NSUTF8StringEncoding) let result = NSMutableData(length: Int(CC_MD5_DIGEST_LENGTH)) let bytes = UnsafePointer<CUnsignedChar>(result.bytes) CC_MD5(data.bytes, CC_LONG(data.length), bytes) let hash = NSMutableString() let a = UnsafeArray<CUnsignedChar>(start: bytes, length: result.length) for i in 0..<Int(CC_MD5_DIGEST_LENGTH) { hash.appendFormat("%02x", a[i]) } return hash }