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 ?

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

2 Answers 2


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.


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.

  • 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.
    – pmdba
    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.
    – J.D.
    Commented Feb 11, 2021 at 3:26

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.