sql server - C# Hash SHA256Managed is not equal to TSQL SHA2_256 -


i using hashed passwords salt (the username).

problem hashed values of c# not equal initial values add database tsql script.

tsql:

update [users] set password = hashbytes('sha2_256', 'test123'+upper([username])) go; 

c#:

var passbytes = new unicodeencoding().getbytes(pass); var saltbytes = new unicodeencoding().getbytes(username.toupper());  var datatohash = new byte[passbytes.length + saltbytes.length]; array.copy(passbytes, datatohash, passbytes.length); array.copy(saltbytes, datatohash, saltbytes.length);  var sha = new sha256managed(); return sha.computehash(datatohash); 

i guess has encoding. have no idea how fix this.

username varchar(50)

the db existing 1 changing varchar not easy.

i tried:

update [users] set password = hashbytes('sha2_256', n'test123'+upper([username])) go; 

if sql server database configured use default collation of sql_latin1_general_cp1_ci_as, in c# code, use code page 1252 convert characters bytes. thus, equivalent of

hashbytes('sha2_256', 'test123' + upper([username])) 

is

byte[] data = encoding.getencoding(1252).getbytes("test123" + username.toupper()); var sha = new sha256managed(); byte[] hash = sha.computehash(data); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -