1

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"

Vvk
  • 4,031
  • 29
  • 51
Mohamed Helmy
  • 821
  • 1
  • 9
  • 20
  • 8
    MD5 is not reversible – a4arpan Dec 30 '15 at 08:53
  • Look into using AES encryption rather – Fonix Dec 30 '15 at 08:55
  • oops AES is complex can i use any reversible hash easy like md5 ? – Mohamed Helmy Dec 30 '15 at 08:57
  • 1
    While md5 has its flaws the whole idea of hash-function is to be one way. I suggest that you study bit more about hashes and encryption. – Ahe Dec 30 '15 at 09:01
  • okay thanks I will search about both – Mohamed Helmy Dec 30 '15 at 09:09
  • Possible duplicate of [PHP:How to send the original password to the user when he clicks forgot password which is encrypted by using md5?](http://stackoverflow.com/questions/2780198/phphow-to-send-the-original-password-to-the-user-when-he-clicks-forgot-password) – Sebastian Simon Dec 30 '15 at 11:31
  • MD5, in-fact all cryptographic hash function are not encryption. They are one-way functions, they purposely loose information in the process, consider that the output is the same size regardless of the input no matter how big, a 1GB file will be reduced to the output size, in the case of MD5 to 16-bytes, obviously information has been lost. If you want encryption use AES. More bad news, if you think AES is difficult in order to obtain substantial security the use of a number of other cryptographic functions is necessary. Good security is not easy. – zaph Dec 30 '15 at 14:04

2 Answers2

1

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

Dmitri Pavlutin
  • 18,122
  • 8
  • 37
  • 41
1

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

Vvk
  • 4,031
  • 29
  • 51