C# Hash SHA256Managed is not equal to TSQL SHA2_256 - c#

I am using hashed passwords with a salt (the username).
Problem is that the hashed values of c# are not equal to the initial values I add to the database by a 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 it has something to do with the encoding.
But i have no idea how to fix this.
UserName is varchar(50)
The DB is an existing one so changing the varchar will not be so easy.
I already tried:
UPDATE [Users]
SET Password = HASHBYTES('SHA2_256', N'test123'+UPPER([UserName]))
GO;

After struggling to get this to work, here is a sample of what I finally got to work:
public string Hash(string input)
{
using (SHA256 hasher = SHA256.Create())
{
// Convert the input string to a byte array and compute the hash.
byte[] data = hasher.ComputeHash(Encoding.Unicode.GetBytes(input));
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder();
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("X2"));
}
// Return the hexadecimal string.
return sBuilder.ToString();
}
}
TSQL
declare #input as nvarchar(max) = 'Test';
select #input;
declare #hash as varbinary(max) = HASHBYTES('SHA2_256', #input );
select #hash;
declare #result as nvarchar(max) = CONVERT(NVARCHAR(MAX), #hash, 2);
select #result;
These will produce identical results.
Note that this is using a nvarchar datatype, not a varchar.

If your SQL Server database is configured to use the default collation of SQL_Latin1_General_CP1_CI_AS, then in your C# code, use code page 1252 to convert characters to bytes. Thus, the 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);

Hashes work on bytes, not on characters. What you're doing is Hash(StringToBytes(str)). Your StringToBytes step is different. In SQL you are using ANSI varchar strings and in C# UTF-16 strings. Decide which one you want and use that. I recommend Unicode (nvarchar).

Encoding.UTF8.GetBytes(input) = HASHBYTES('SHA2_256', #varcharVariable);
Encoding.Unicode.GetBytes(input) = HASHBYTES('SHA2_256', #nvarcharVariable);

Related

how to compute a hash in C# with the correct coding?

when I get a hash from C# I seem to get a different value then when I do it in sql server.
Take this query
declare #test table (value nvarchar(100))
insert into #test values ('1234'), (N'1234')
select 'from db' as source, t.value, HASHBYTES('SHA2_256', t.value) as result from #test t
union all
select 'fixed ascii', '1234', HASHBYTES('SHA2_256', '1234')
union all
select 'fixed unicode', N'1234', HASHBYTES('SHA2_256', N'1234')
the result is
source
value
result
from db
1234
0x4F37C061F1854F9682F543FECB5EE9D652C803235970202DE97C6E40C8361766
from db
1234
0x4F37C061F1854F9682F543FECB5EE9D652C803235970202DE97C6E40C8361766
fixed ascii
1234
0x03AC674216F3E15C761EE1A5E255F067953623C8B388B4459E13F978D7C846F4
fixed unicode
1234
0x4F37C061F1854F9682F543FECB5EE9D652C803235970202DE97C6E40C8361766
As you can see in the result, only the fixed ascii version has a different result, as I would also expect since the column has datatype nvarchar
Now I want to get the hash in C#
private string GetStringSha256Hash(string text, System.Text.Encoding coding)
{
string result = "";
if (String.IsNullOrEmpty(text) == false)
{
using (var sha = new System.Security.Cryptography.SHA256Managed())
{
byte[] textData = coding.GetBytes(text);
byte[] hash = sha.ComputeHash(textData);
result = BitConverter.ToString(hash).Replace("-", String.Empty);
}
}
return result;
}
string dbPass = TextEditPass.Text;
string hashedPassUTF8 = GetStringSha256Hash(dbPass, System.Text.Encoding.UTF8);
string hashedPassASCII = GetStringSha256Hash(dbPass, System.Text.Encoding.ASCII);
The result is the same for each call to GetStringSha256Hash
03AC674216F3E15C761EE1A5E255F067953623C8B388B4459E13F978D7C846F4
and it is the same as the ascii result from the database.
So my question is, how can I do it in C# do get the unicode result, when I have to start from the value of a simple textBox ?
I just want to make sure that the C# application will never say a value from the DB is not correct because of differences in text encoding.

Getting issue when convert c# code to PHP as below

I am running this code:
var timeStamp = DateTime.UtcNow;
var sharedSecret = "xx";
var saltedString = timeStamp.ToString("2021-01-07T16:42:33.619667Z") + sharedSecret;
//Encoding saltedString using Unicode little-endian byte order
byte[] encodedSaltedString = Encoding.Unicode.GetBytes(saltedString);
//Hashing Algorithm used is SHA512
HashAlgorithm hash = new SHA512Managed();
//Compute Hash of encodedSaltedString
byte[] hashedEncodedString = hash.ComputeHash(encodedSaltedString);
//Convert hashed array to base64-encoded string
string signature = Convert.ToBase64String(hashedEncodedString);
I am then getting this result in C#:
"gQhjrLnY6fo44EeaaWaUBE1PY/8oEIRsUcK3AMSCVUCYMM4vRfxvQEEggXaHTF0GQbw4w2HbWArX1k6NnkzJFg=="
I converted to this code as below, but I am getting an issue. Can I get some help on this?
$timestamp = "2021-01-07T16:42:33.619667Z";
$sharedSecret = 'xx';
$saltedString = $timestamp.$sharedSecret;
$utf=mb_convert_encoding($saltedString, "UTF-16LE");
$signature = base64_encode(hash('sha512', $utf));
IN PHP I am getting this result:
ODEwODYzYWNiOWQ4ZTlmYTM4ZTA0NzlhNjk2Njk0MDQ0ZDRmNjNmZjI4MTA4NDZjNTFjMmI3MDBjNDgyNTU0MDk4MzBjZTJmNDVmYzZmNDA0MTIwODE3Njg3NGM1ZDA2NDFiYzM4YzM2MWRiNTgwYWQ3ZDY0ZThkOWU0Y2M5MTY=
But both should be same. The c# one is correct, I want the same in the php code as well.
From the PHP docs for hash:
hash ( string $algo , string $data , bool $binary = false ) : string|false
binary
   When set to true, outputs raw binary data. false outputs lowercase hexits.
You're not passing a value for $binary, so it's returning a string of hexadecimal characters.
The C# HashAlgorithm.ComputeHash method on the other hand binary data.
Since you're base64-encoding the result, you're presumably expecting the hash function to return binary data. You therefore need to pass true as the value for $binary:
$signature = base64_encode(hash('sha512', $utf, true));

I cannot create a md5-hash code with T-SQL like in C#

I'm posting data to a web service.
But before I send the data to the web service, I have to get the md5-hash code and add it to the soap data.
For the code in #sendData, I am expected to generate the md5-hash code
58a457d0b2e566048e0a2a046bd68045
declare #sendData varchar(max)='PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPEludm9pY2UKICAgIHhtbG5zOmNhYz0idXJuOm9hc2lzOm5hbWVzOnNwZWNpZmljYXRpb246dWJsOnNjaGVtYTp4c2Q6Q29tbW9uQWdncmVnYXRlQ29tcG9uZW50cy0yIgogICAgeG1sbnM6Y2JjPSJ1cm46b2FzaXM6bmFtZXM6c3BlY2lmaWNhdGlvbjp1Ymw6c2NoZW1hOnhzZDpDb21tb25CYXNpY0NvbXBvbmVudHMtMiIKICAgIHhtbG5zOnVkdD0idXJuOnVuOnVuZWNlOnVuY2VmYWN0OmRhdGE6c3BlY2lmaWNhdGlvbjpVbnF1YWxpZmllZERhdGFUeXBlc1NjaGVtYU1vZHVsZToyIgogICAgeG1sbnM6Y2N0cz0idXJuOnVuOnVuZWNlOnVuY2VmYWN0OmRvY3VtZW50YXRpb246MiIKICAgIHhtbG5zOmV4dD0idXJuOm9hc2lzOm5hbWVzOnNwZWNpZmljYXRpb246dWJsOnNjaGVtYTp4c2Q6Q29tbW9uRXh0ZW5zaW9uQ29tcG9uZW50cy0yIgogICAgeG1sbnM6cWR0PSJ1cm46b2FzaXM6bmFtZXM6c3BlY2lmaWNhdGlvbjp1Ymw6c2NoZW1hOnhzZDpRdWFsaWZpZWREYXRhdHlwZXMtMiIKICAgIHhtbG5zOnVibHRyPSJ1cm46b2FzaXM6bmFtZXM6c3BlY2lmaWNhdGlvbjp1Ymw6c2NoZW1hOnhzZDpUdXJraXNoQ3VzdG9taXphdGlvbkV4dGVuc2lvbkNvbXBvbmVudHMiCiAgICB4bWxuczpkcz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC8wOS94bWxkc2lnIyIgICAgICAgICAgeG1sbnM6eHN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ICAgICAgICAgICAgICAgICA8Y2JjOk5hbWU+S0RWPC9jYmM6TmFtZT4KICAgICAgICAgICAgICAgICAgICAgICAgPGNiYzpUYXhUeXBlQ29kZT4wMDE1PC9jYmM6VGF4VHlwZUNvZGU+CiAgICAgICAgICAgICAgICAgICAgPC9jYWM6VGF4U2NoZW1lPgogICAgICAgICAgICAgICAgPC9jYWM6VGF4Q2F0ZWdvcnk+CiAgICAgICAgICAgIDwvY2FjOlRheFN1YnRvdGFsPgogICAgICAgIDwvY2FjOlRheFRvdGFsPgogICAgICAgIDxjYWM6SXRlbT4KICAgICAgICAgICAgPGNiYzpOYW1lPjE8L2NiYzpOYW1lPgogICAgICAgICAgICA8Y2FjOlNlbGxlcnNJdGVtSWRlbnRpZmljYXRpb24+CiAgICAgICAgICAgICAgICA8Y2JjOklEPjE8L2NiYzpJRD4KICAgICAgICAgICAgPC9jYWM6U2VsbGVyc0l0ZW1JZGVudGlmaWNhdGlvbj4KICAgICAgICA8L2NhYzpJdGVtPgogICAgICAgIDxjYWM6UHJpY2U+CiAgICAgICAgICAgIDxjYmM6UHJpY2VBbW91bnQgY3VycmVuY3lJRD0iVVNEIj4xPC9jYmM6UHJpY2VBbW91bnQ+CiAgICAgICAgPC9jYWM6UHJpY2U+CiAgICA8L2NhYzpJbnZvaWNlTGluZT4KPC9JbnZvaWNlPgo='
SELECT
CONVERT(CHAR(32), HashBytes('MD5', #sendData), 2) AS 'hashCode'
but as a result of this the md5-hash code returned is
4D5A74F92C5B7154247AF52AF3FD13D0
I tried entering #sendData data from many online md5-hash generation sites. T-SQL's hash code seems correct.
When I said you created the hash code incorrectly, they sent me C# code.
But I use classic ASP, Python, SQL Server T-SQL, can I create a hash code like here?
public static string GetMD5Hash(byte[] inputData)
{
MD5 md5Hash = new MD5CryptoServiceProvider();
byte[] data = md5Hash.ComputeHash(inputData);
StringBuilder sBuilder = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
return sBuilder.ToString();
}
The difference is caused by the fact that the C# code is not hashing the string itself, it is hashing the binary value that is encoded in base64 as that string.
string inputString = "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPEludm9pY2UKICAgIHhtbG5zOmNhYz0idXJuOm9hc2lzOm5hbWVzOnNwZWNpZmljYXRpb246dWJsOnNjaGVtYTp4c2Q6Q29tbW9uQWdncmVnYXRlQ29tcG9uZW50cy0yIgogICAgeG1sbnM6Y2JjPSJ1cm46b2FzaXM6bmFtZXM6c3BlY2lmaWNhdGlvbjp1Ymw6c2NoZW1hOnhzZDpDb21tb25CYXNpY0NvbXBvbmVudHMtMiIKICAgIHhtbG5zOnVkdD0idXJuOnVuOnVuZWNlOnVuY2VmYWN0OmRhdGE6c3BlY2lmaWNhdGlvbjpVbnF1YWxpZmllZERhdGFUeXBlc1NjaGVtYU1vZHVsZToyIgogICAgeG1sbnM6Y2N0cz0idXJuOnVuOnVuZWNlOnVuY2VmYWN0OmRvY3VtZW50YXRpb246MiIKICAgIHhtbG5zOmV4dD0idXJuOm9hc2lzOm5hbWVzOnNwZWNpZmljYXRpb246dWJsOnNjaGVtYTp4c2Q6Q29tbW9uRXh0ZW5zaW9uQ29tcG9uZW50cy0yIgogICAgeG1sbnM6cWR0PSJ1cm46b2FzaXM6bmFtZXM6c3BlY2lmaWNhdGlvbjp1Ymw6c2NoZW1hOnhzZDpRdWFsaWZpZWREYXRhdHlwZXMtMiIKICAgIHhtbG5zOnVibHRyPSJ1cm46b2FzaXM6bmFtZXM6c3BlY2lmaWNhdGlvbjp1Ymw6c2NoZW1hOnhzZDpUdXJraXNoQ3VzdG9taXphdGlvbkV4dGVuc2lvbkNvbXBvbmVudHMiCiAgICB4bWxuczpkcz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC8wOS94bWxkc2lnIyIgICAgICAgICAgeG1sbnM6eHNpPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYS1pbnN0YW5j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AgICAgICAgICAgICAgICAgICAgPGNiYzpUYXhUeXBlQ29kZT4wMDE1PC9jYmM6VGF4VHlwZUNvZGU+CiAgICAgICAgICAgICAgICAgICAgPC9jYWM6VGF4U2NoZW1lPgogICAgICAgICAgICAgICAgPC9jYWM6VGF4Q2F0ZWdvcnk+CiAgICAgICAgICAgIDwvY2FjOlRheFN1YnRvdGFsPgogICAgICAgIDwvY2FjOlRheFRvdGFsPgogICAgICAgIDxjYWM6SXRlbT4KICAgICAgICAgICAgPGNiYzpOYW1lPjE8L2NiYzpOYW1lPgogICAgICAgICAgICA8Y2FjOlNlbGxlcnNJdGVtSWRlbnRpZmljYXRpb24+CiAgICAgICAgICAgICAgICA8Y2JjOklEPjE8L2NiYzpJRD4KICAgICAgICAgICAgPC9jYWM6U2VsbGVyc0l0ZW1JZGVudGlmaWNhdGlvbj4KICAgICAgICA8L2NhYzpJdGVtPgogICAgICAgIDxjYWM6UHJpY2U+CiAgICAgICAgICAgIDxjYmM6UHJpY2VBbW91bnQgY3VycmVuY3lJRD0iVVNEIj4xPC9jYmM6UHJpY2VBbW91bnQ+CiAgICAgICAgPC9jYWM6UHJpY2U+CiAgICA8L2NhYzpJbnZvaWNlTGluZT4KPC9JbnZvaWNlPgo=";
//byte[] inputData=Encoding.ASCII.GetBytes(inputString);
byte[] inputData = Convert.FromBase64String(inputString);
Console.WriteLine(GetMD5Hash(inputData));
To do the same thing in T-SQL, you can use something like this:
declare #sendData varchar(max)='PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPEludm9pY2UKICAgIHhtbG5zOmNhYz0idXJuOm9hc2lzOm5hbWVzOnNwZWNpZmljYXRpb246dWJsOnNjaGVtYTp4c2Q6Q29tbW9uQWdncmVnYXRlQ29tcG9uZW50cy0yIgogICAgeG1sbnM6Y2JjPSJ1cm46b2FzaXM6bmFtZXM6c3BlY2lmaWNhdGlvbjp1Ymw6c2NoZW1hOnhzZDpDb21tb25CYXNpY0NvbX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EyPC9jYmM6SUQ+CiAgICAgICAgICAgIDwvY2FjOlBhcnR5SWRlbnRpZmljYXRpb24+CiAgICAgICAgICAgIDxjYWM6UGFydHlOYW1lPgogICAgICAgICAgICAgICAgPGNiYzpOYW1lPlJvdGEgODA0MzwvY2JjOk5hbWU+CiAgICAgICAgICAgIDwvY2FjOlBhcnR5TmFtZT4KICAgICAgICAgICAgPGNhYzpQb3N0YWxBZGRyZXNzPgogICAgICAgICAgICAgICAgPGNiYzpDaXR5U3ViZGl2aXNpb25OYW1lPk1lY2lkaXlla8O2eTwvY2JjOkNpdHlTdWJkaXZpc2lvbk5hbWU+CiAgICAgICAgICAgICAgICA8Y2JjOkNpdHlOYW1lPsSwU1RBTkJVTDwvY2JjOkNpdHlOYW1lPgogICAgICAgICAgICAgICAgPGNhYzpDb3VudHJ5PgogICAgICAgICAgICAgICAgICAgIDxjYmM6TmFtZT5Uw5xSS8SwWUU8L2NiYzpOYW1lPgogICAgICAgICAgICAgICAgPC9jYWM6Q291bnRyeT4KICAgICAgICAgICAgPC9jYWM6UG9zdGFsQWRkcmVzcz4KICAgICAgICAgICAgPGNhYzpQYXJ0eVRheFNjaGVtZT4KICAgICAgICAgICAgICAgIDxjYWM6VGF4U2NoZW1lPgogICAgICAgICAgICAgICAgICAgIDxjYmM6TmFtZT5TQVJJWUVSPC9jYmM6TmFtZT4KICAgICAgICAgICAgICAgIDwvY2FjOlRheFNjaGVtZT4KICAgICAgICAgICAgPC9jYWM6UGFydHlUYXhTY2hlbWU+CiAgICAgICAgICAgIDxjYWM6Q29udGFjdD4KICAgICAgICAgICAgICAgIDxjYmM6RWxlY3Ryb25pY01haWw+YmFoYXIuZHVybXVzQGVmaW5hbnMuY29tLnRyPC9jYmM6RWxlY3Ryb25pY01haWw+CiAgICAgICAgICAgIDwvY2FjOkNvbnRhY3Q+CiAgICAgICAgPC9jYWM6UGFydHk+CiAgICA8L2NhYzpBY2NvdW50aW5nU3VwcGxpZXJQYXJ0eT4KICAgIDxjYWM6QWNjb3VudGluZ0N1c3RvbWVyUGFydHk+CiAgICAgICAgPGNhYzpQYXJ0eT4KICAgICAgICAgICAgPGNhYzpQYXJ0eUlkZW50aWZpY2F0aW9uPgogICAgICAgICAgICAgICAgPGNiYzpJRCBzY2hlbWVJRD0iVktOIj4xMjAxODMwNTEyPC9jYmM6SUQ+CiAgICAgICAgICAgIDwvY2FjOlBhcnR5SWRlbnRpZmljYXRpb24+CiAgICAgICAgICAgIDxjYWM6UGFydHlOYW1lPgogICAgICAgICAgICAgICAgPGNiYzpOYW1lPlJvdGEgODQ0MzwvY2JjOk5hbWU+CiAgICAgICAgICAgIDwvY2FjOlBhcnR5TmFtZT4KICAgICAgICAgICAgPGNhYzpQb3N0YWxBZGRyZXNzPgogICAgICAgICAgICAgICAgPGNiYzpDaXR5U3ViZGl2aXNpb25OYW1lPnRlc3Q8L2NiYzpDaXR5U3ViZGl2aXNpb25OYW1lPgogICAgICAgICAgICAgICAgPGNiYzpDaXR5TmFtZT50ZXM8L2NiYzpDaXR5TmFtZT4KICAgICAgICAgICAgICAgIDxjYWM6Q291bnRyeT4KICAgICAgICAgICAgICAgICAgICA8Y2JjOk5hbWU+QVZVU1RSQUxZQSBPS1lBTlVTVTwvY2JjOk5hbWU+CiAgICAgICAgICAgICAgICA8L2NhYzpDb3VudHJ5PgogICAgICAgICAgICA8L2NhYzpQb3N0YWxBZGRyZXNzPgogICAgICAgICAgICA8Y2FjOlBhcnR5VGF4U2NoZW1lPgogICAgICAgICAgICAgICAgPGNhYzpUYXhTY2hlbWU+CiAgICAgICAgICAgICAgICAgICAgPGNiYzpOYW1lPnRlc3Q8L2NiYzpOYW1lPgogICAgICAgICAgICAgICAgPC9jYWM6VGF4U2NoZW1lPgogICAgICAgICAgICA8L2NhYzpQYXJ0eVRheFNjaGVtZT4KICAgICAgICA8L2NhYzpQYXJ0eT4KICAgIDwvY2FjOkFjY291bnRpbmdDdXN0b21lclBhcnR5PgogICAgPGNhYzpQYXltZW50TWVh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W50IGN1cnJlbmN5SUQ9IlVTRCI+MS4wMDwvY2JjOkFtb3VudD4KICAgICAgICAgICAgPGNiYzpCYXNlQW1vdW50IGN1cnJlbmN5SUQ9IlVTRCI+MTAuMDA8L2NiYzpCYXNlQW1vdW50PgogICAgICAgIDwvY2FjOkFsbG93YW5jZUNoYXJnZT4KICAgICAgICA8Y2FjOlRheFRvdGFsPgogICAgICAgICAgICA8Y2JjOlRheEFtb3VudCBjdXJyZW5jeUlEPSJVU0QiPjEuNjI8L2NiYzpUYXhBbW91bnQ+CiAgICAgICAgICAgIDxjYWM6VGF4U3VidG90YWw+CiAgICAgICAgICAgICAgICA8Y2JjOlRheGFibGVBbW91bnQgY3VycmVuY3lJRD0iVVNEIj45LjAwPC9jYmM6VGF4YWJsZUFtb3VudD4KICAgICAgICAgICAgICAgIDxjYmM6VGF4QW1vdW50IGN1cnJlbmN5SUQ9IlVTRCI+MS42MjwvY2JjOlRheEFtb3VudD4KICAgICAgICAgICAgICAgIDxjYmM6UGVyY2VudD4xODwvY2JjOlBlcmNlbnQ+CiAgICAgICAgICAgICAgICA8Y2FjOlRheENhdGVnb3J5PgogICAgICAgICAgICAgICAgICAgIDxjYWM6VGF4U2NoZW1lPgogICAgICAgICAgICAgICAgICAgICAgICA8Y2JjOk5hbWU+S0RWPC9jYmM6TmFtZT4KICAgICAgICAgICAgICAgICAgICAgICAgPGNiYzpUYXhUeXBlQ29kZT4wMDE1PC9jYmM6VGF4VHlwZUNvZGU+CiAgICAgICAgICAgICAgICAgICAgPC9jYWM6VGF4U2NoZW1lPgogICAgICAgICAgICAgICAgPC9jYWM6VGF4Q2F0ZWdvcnk+CiAgICAgICAgICAgIDwvY2FjOlRheFN1YnRvdGFsPgogICAgICAgIDwvY2FjOlRheFRvdGFsPgogICAgICAgIDxjYWM6SXRlbT4KICAgICAgICAgICAgPGNiYzpOYW1lPjE8L2NiYzpOYW1lPgogICAgICAgICAgICA8Y2FjOlNlbGxlcnNJdGVtSWRlbnRpZmljYXRpb24+CiAgICAgICAgICAgICAgICA8Y2JjOklEPjE8L2NiYzpJRD4KICAgICAgICAgICAgPC9jYWM6U2VsbGVyc0l0ZW1JZGVudGlmaWNhdGlvbj4KICAgICAgICA8L2NhYzpJdGVtPgogICAgICAgIDxjYWM6UHJpY2U+CiAgICAgICAgICAgIDxjYmM6UHJpY2VBbW91bnQgY3VycmVuY3lJRD0iVVNEIj4xPC9jYmM6UHJpY2VBbW91bnQ+CiAgICAgICAgPC9jYWM6UHJpY2U+CiAgICA8L2NhYzpJbnZvaWNlTGluZT4KPC9JbnZvaWNlPgo='
DECLARE #binaryData VARBINARY(MAX)=(SELECT CAST(N'' AS XML).value('xs:base64Binary(sql:column("BASE64_COLUMN"))', 'VARBINARY(MAX)') FROM (SELECT #sendData AS BASE64_COLUMN) x)
--SELECT CONVERT(XML,CONVERT(VARCHAR(MAX),#binaryData))
SELECT CONVERT(CHAR(32),HashBytes('MD5',#binaryData),2) as 'hashCode'

SHA1 encryption trouble

I have a problem with the password encryption.
I would like to have the password encrypted like those not highlighted in the picture.
I wrote the following c# code:
SHA1CryptoServiceProvider x = new SHA1CryptoServiceProvider();
//byte[] bs = System.Text.Encoding.Unicode.GetBytes(password);
//byte[] bs = System.Text.Encoding.UTF32.GetBytes(password);
byte[] bs = System.Text.Encoding.UTF8.GetBytes(password);
bs = x.ComputeHash(bs);
var s = new StringBuilder();
foreach (byte b in bs)
{
s.Append(b.ToString("x2").ToLower());
}
new UserService().ChangeUserPassword(username, s.ToString());
to encrypt the password in the correct way I using the following SQL code that I want remove:
CAST(hashbytes('SHA1',#newuserpassword) as nvarchar)
this is the result:
Looking at the docs for CONVERT, I suspect you just want:
CONVERT(nvarchar, hashbytes('SHA1',#newuserpassword), 2)
Where 2 is the style which converts to hex without a leading 0x. I suggest you specify the length of the nvarchar though, which should be 40 (20 bytes, 2 characters per byte).
I strongly advise you to abandon storing binary data in characters. Still, if you need to keep it for legacy reasons, here is the translation of the SQL statement:
byte[] bytes = ...; //your binary data here
var nastilyBrokenChars =
Enumerable.Range(0, bytes.Length / 2)
.Select(i => (char)BitConverter.GetInt16(bytes, i * 2))
.ToArray();
string nastilyBrokenString = new string(nastilyBrokenChars);
As you can, I'm stuffing two bytes into each char. This by itself is a lossless conversion. But I wouldn't trust that storing this data into SQL Server (and comparing it later) is loss-less.

Getting different encryption results between C#.Net and Oracle

I want to encrypt some strings based on SHA1 algorithm in both C#.Net and Oracle 10g.
My algorithm in C#.Net:
string salt = "123";
System.Security.Cryptography.SHA1 sha = System.Security.Cryptography.SHA1.Create();
byte[] preHash = System.Text.Encoding.UTF32.GetBytes(salt);
byte[] hash = sha.ComputeHash(preHash);
string password = System.Convert.ToBase64String(hash);
password = password.Substring(0, 8);
// password value is: "7yP7/lkJ"
In Oracle:
Create Or Replace Function Sha1(P_Value Varchar2,P_Length Number) Return Varchar2
Is
P_String Varchar2(2000) := P_Value ;
L_Hash_Value_Raw Raw (100);
Lv_Hash_Value_Varchar Varchar2 (40);
Begin
L_Hash_Value_Raw := Dbms_Crypto.Hash (Src => Utl_Raw.Cast_To_Raw(P_String),
Typ => Dbms_Crypto.Hash_Sh1);
-- Convert Into Varchar2
Select Utl_Raw.Cast_To_Varchar2(Utl_Encode.Base64_Encode(L_Hash_Value_Raw))
Into Lv_Hash_Value_Varchar
From Dual;
Lv_Hash_Value_Varchar := Substr(Lv_Hash_Value_Varchar,0,P_Length);
Return Lv_Hash_Value_Varchar;
End;
Oracle's invokation:
select SHA1('123', 8) from dual; -- Result: "QLOAFWMI"
Maybe my general question is what is the difference between Oracle (PL/SQL) and .Net regarding encryption/raw/hex levels? I guess that answer would solve this specific problem.
you use wrong encoding. try the following code:
string salt = "123";
System.Security.Cryptography.SHA1 sha = System.Security.Cryptography.SHA1.Create();
byte[] preHash = System.Text.Encoding.UTF8.GetBytes(salt);
byte[] hash = sha.ComputeHash(preHash);
string password = System.Convert.ToBase64String(hash);
password = password.Substring(0, 8);

Categories

Resources