-1

i came to know that Sql server2008 introduce HASHBYTES() which use md5 to encrypt any string like this way Select HASHBYTES( 'md5', 'demo' ) and the the code used to decrypt like this way

Select CONVERT(VARCHAR(MAX), HASHBYTES( 'md5', 'demo' ), 2) 

but when i try this second select statement it is showing the value in encrypted format. so how to decrypt the demo as text. thanks

Thomas
  • 33,544
  • 126
  • 357
  • 626

1 Answers1

2

It's one way hashing; you can't get back original form. It is not possible to decrypt a hash. What is the purpose though?

if you are just trying to compare this hash value with some other then you can do something like

IF HASHBYTES('md5', 'demo') = HASHBYTES('md5',@param) 
    PRINT 'Match!';

EDIT:

Hashing does not encrypt the original value at all. Hashing instead applies a one-way mathematical algorithm to the original value, resulting in a binary value.

It's mainly used for storing password. so, the password will be stored in hash format. When user provides credential (id/password); it doesn't decrypt the stored password; rather, user provided password will be hashed with the same algorithm and that hash value will be compared with the stored hash value (as shown a code example above).

Rahul
  • 76,197
  • 13
  • 71
  • 125
  • @Thomas, short answer "NO". It's a hash value and not encryption. How will you decrypt. – Rahul May 14 '14 at 13:03
  • @Thomas, see edited answer for an explanation. Don't forget to accept the answer if it helped. – Rahul May 14 '14 at 13:13
  • can u tell me if i want to encrypt and decrypt data in sql server then how i can do that. – Thomas May 14 '14 at 13:16
  • @Thomas, see here http://blog.sqlauthority.com/2009/04/28/sql-server-introduction-to-sql-server-encryption-and-symmetric-key-encryption-tutorial-with-script/ – Rahul May 14 '14 at 13:19