0

I've encrypted application name in my c# app using MD5, so when constructing the connection string the application name is passed to SQL as encrypted. I would like to decrypt in SQL server the value to see if there is a match? How can I get the original text in SQL ?

asked Feb 10, 2021 at 22:21
1
  • Any reason you are not using SSL/TLS encryption anyway? Commented Feb 14, 2021 at 5:42

2 Answers 2

1

Hashes like MD5 are by definition one-way: you can't decrypt them by design. This is how many applications store secrets like passwords. A better solution would be to store a list of applications and their hashed values in a database table, then compare your submitted hash to the stored hashes to find a match.

answered Feb 11, 2021 at 3:49
0

I don't believe this is possible natively in SQL Server since MD5 is a one-way (apparently loss-full) hash. Here's a good StackOverflow answer that goes over MD5 in general.

SQL Server has a built in function to generate hashes called HASHBYTES() which maybe you could leverage (and one of the other hashing algorithms that are loss-less) to potentially generate a hash string that is reversible. But I have feeling even that might not be possible to do.

answered Feb 10, 2021 at 22:50
2
  • Hashes are by definition one-way. You can't decrypt them. You would need to keep a table of app names with their hashes in the database and compare the submitted hash to the stored hashes to find a match. Commented Feb 11, 2021 at 2:29
  • @pmdba Right, that's probably a better solution than trying to implement an algorithm that involves decrypting hashes. You should probably post that as an answer for OP. Technically one can create their own hashing function that is deterministic (such as converting every character to its respective ASCII character code, incrementing it by 1 - looping when getting to the end of character set, and then converting back to a character) and therefore reversible, but I assume any standard hash function is nom-reversible. Commented Feb 11, 2021 at 3:26

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.