Mohamed Helmy
Mohamed Helmy

Reputation: 832

swift2 decrypt MD5

Hello I just want to decrypt from md5 to 'normal string'

extension String {
func MD5() -> String {
    var data = (self as NSString).dataUsingEncoding(NSUTF8StringEncoding)
    let result = NSMutableData(length: Int(CC_MD5_DIGEST_LENGTH))
    let resultBytes = UnsafeMutablePointer<CUnsignedChar>(result!.mutableBytes)
    CC_MD5(data!.bytes, CC_LONG(data!.length), resultBytes)

    let buff = UnsafeBufferPointer<CUnsignedChar>(start: resultBytes, count: result!.length)
    let hash = NSMutableString()
    for i in buff {
        hash.appendFormat("%02x", i)
    }
    return hash as String
}

var x = "abc".MD5()

I want to get back to abc from "x"

Upvotes: 1

Views: 884

Answers (2)

Vvk
Vvk

Reputation: 4043

It's not possible that's the whole point of hashing. You can however bruteforce by going through all possibilities (using all possible digits characters in every possible order) and hashing them and checking for a collision. it was hard to reverse. also check...https://en.wikipedia.org/wiki/MD5

Upvotes: 1

Dmitri Pavlutin
Dmitri Pavlutin

Reputation: 19060

Simple: Not possible, because MD5 hash is not possible to invert.
Check about One way function

Upvotes: 1

Related Questions