I am using MD5 function to encrypt sensitive data, How I can decrypt the data back to actual data.
Ex -
data set_1;
member='Anthony';
member2=put(md5(member), hex32.);
put member2=;
run;
Encrypted value -
20F1AEB7819D7858684C898D1E98C1BB
How I can convert this encrypted value back to original value.
Short answer is, you can't. MD5 output for two different inputs can be the same so it is not 1-to-1 function so you can't have an inverse.
All the best
Bart
This is not possible. It creates a fixed-length result for any input, which means it loses content. You can therefore (theoretically) find an infinity of sources resulting in the same hash.
With enough computing power, you can easily find a solution, but not the solution.
Another important aspect for you, might be the fact, that MD5 is not safe!!!
Several weaknesses have been found.
See: https://en.wikipedia.org/wiki/MD5
Therefore you might want to switch to "a more safer" encryption algorithm, that has been implemented as a function in SAS. For example the "sha-2 (secure hash algorithm 2)":
It depends for what you use it. Encoding of passwords, no, anonymization of data, yes.
Why do you hash the value?
And why do you want to revert?
The only viable solution is to store the input and output pairs together.
As pointed out earlier by several people, no way to revert. And it has to be checked where to use MD5 and where not:
It is easy this way to e.g. check if content of a file was modified, so you see a different MD5 value than expected. Or you want to find duplicate files, not by name but by content. Had this yesterday, so MD5 over complete folder structure and show "MD5-hash: filename", sort by hash, see >potential< duplicates. I say potential since of course you have the risk of clashes - different content produces the same hash. Rare but possible, more like the more entries you have. For this careful search to reduce what to look at, MD5 is ideal and very fast.
For that "clash" reason, using an MD5 to shorten concatenated strings used in table JOINs can be very risky depending on data volume. Fell into that trap once at customer site, very hard to identify if you don't know what you are looking at.
Finally, when hearing "reverse an MD5" or similar, first thought is always that someone tries to look at something they should not be looking at...
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.