c# - How to generate similar hash password using sql server? -
cryptography algorithm md5.
in c#, using following code generate password:-
private md5 _md5; var plain = asciiencoding.default.getbytes('admin'); var hashed = _md5.computehash(plain); var shashed = asciiencoding.default.getstring(hashed); console.write(shashed);
result is: !#/)zw¥§c‰jj€Ã
when use sql server code generate password:-
declare @hashthis varchar(100); select @hashthis = convert(varchar(100),'admin'); select hashbytes('md5', @hashthis); go
result is: 0x21232f297a57a5a743894a0e4a801fc3
i using same algorithm. how can generate same hash value in sql server?
your c# code , sql code both computing same hash value, sql formatting result hex string while c# code attempting cast bytes of hash value directly ascii characters (which not). same result in c# use bitconverter class:
var shashed = "0x" + system.bitconverter.tostring(hashed).replace("-", "");
output:
0x21232f297a57a5a743894a0e4a801fc3
Comments
Post a Comment