Skip to content

Instantly share code, notes, and snippets.

@nocoo
Created July 24, 2014 05:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nocoo/2146ed9fbea7ae4e476b to your computer and use it in GitHub Desktop.
Save nocoo/2146ed9fbea7ae4e476b to your computer and use it in GitHub Desktop.
Swift MD5 support to String
#import <CommonCrypto/CommonCrypto.h>
import Foundation
extension String {
func md5() -> String! {
let str = self.cStringUsingEncoding(NSUTF8StringEncoding)
let strLen = CUnsignedInt(self.lengthOfBytesUsingEncoding(NSUTF8StringEncoding))
let digestLen = Int(CC_MD5_DIGEST_LENGTH)
let result = UnsafePointer<CUnsignedChar>.alloc(digestLen)
CC_MD5(str!, strLen, result)
var hash = NSMutableString()
for i in 0..<digestLen {
hash.appendFormat("%02x", result[i])
}
result.destroy()
return String(hash)
}
}
@chukiatt
Copy link

how to decrypt from c#

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment