Click here to Skip to main content
15,903,388 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Okay. My salt value is ???? i not sure why here is my method for the salt and hash

Salt method

UnicodeEncoding utf16 = new UnicodeEncoding();

if (utf16 != null)
{

Random random = new Random(unchecked((int)DateTime.Now.Ticks));

if (random != null)
{

byte[] saltValue = new byte[8];

random.NextBytes(saltValue);

string saltValueString = utf16.GetString(saltValue);

Hash method

UnicodeEncoding encoding = new UnicodeEncoding();

SHA512Managed hashing = new SHA512Managed();

string salt = string.Empty;

if (tb_password.Text != null && hashing != null && encoding != null)
{

if (salt == null)
{
// Generate a salt string.
salt = encoding.GetString(saltValue);
}

byte[] binarySaltValue = new byte[8];
binarySaltValue[0] = byte.Parse(salt.Substring(0, 2), System.Globalization.NumberStyles.HexNumber, CultureInfo.InvariantCulture.NumberFormat);
binarySaltValue[1] = byte.Parse(salt.Substring(2, 2), System.Globalization.NumberStyles.HexNumber, CultureInfo.InvariantCulture.NumberFormat);
binarySaltValue[2] = byte.Parse(salt.Substring(4, 2), System.Globalization.NumberStyles.HexNumber, CultureInfo.InvariantCulture.NumberFormat);
binarySaltValue[3] = byte.Parse(salt.Substring(6, 2), System.Globalization.NumberStyles.HexNumber, CultureInfo.InvariantCulture.NumberFormat);


byte[] valueToHash = new byte[8 + encoding.GetByteCount(tb_password.Text)];
byte[] binaryPassword = encoding.GetBytes(tb_password.Text);

binarySaltValue.CopyTo(valueToHash, 0);
binaryPassword.CopyTo(valueToHash, 8);

byte[] hashValue = hashing.ComputeHash(valueToHash);

string hashedPassword = salt;

foreach (byte hexdigit in hashValue)
{
hashedPassword += hexdigit.ToString("X2", CultureInfo.InvariantCulture.NumberFormat);
}
Posted
Comments
[no name] 19-Jul-14 11:23am    
IF your (rather strange) code would compile it would work. To get it to work use Encoding.Unicode.GetString(saltValue);

FYI reposting the same questions over and over and over gets really annoying.
ZurdoDev 19-Jul-14 22:20pm    
What is your question?

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900