BookmarkSubscribeRSS Feed
PRAVIN_JAIN
Calcite | Level 5

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. 

6 REPLIES 6
yabwon
Amethyst | Level 16

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Kurt_Bremser
Super User

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.

FK1
Lapis Lazuli | Level 10 FK1
Lapis Lazuli | Level 10

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)":

 

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=lefunctionsref&docsetTarg...

 

LinusH
Tourmaline | Level 20

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.

Data never sleeps
MatthiasB
Fluorite | Level 6

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...

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 6255 views
  • 2 likes
  • 6 in conversation