質問

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

役に立ちましたか?

解決

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top