HMACSHA1 Hash Different from desktop to WinCE

T

Tomppa

How can I create a hash of a string on the desktop using a salt value and
get the same results on my WinCE device?

I use the same code on the desktop and pc with the same hash of the same
string with different results.

I the string I am hashing is a guid string.

Desktop framework 2.0 CF framework 2.0 WinCE 5

Thanks in advance...


public static string GetHashFromString(string stringValue)

{

StringBuilder sb = new StringBuilder();

try

{

System.Text.ASCIIEncoding encoding=new System.Text.ASCIIEncoding();

byte[] fileBytes = encoding.GetBytes(stringValue);

// generate hash

HMACSHA1 hmac = new HMACSHA1();


string key = RegistryHelper.HashKey;

if (key.Length > 0)

{

hmac.Key = Encoding.ASCII.GetBytes(key);

}

else

{

hmac.Key = Encoding.ASCII.GetBytes("");

}

hmac.ComputeHash(fileBytes);

// convert hash to hex string

for (int i = 0; i < hmac.Hash.Length; i++)

{

sb.Append(hmac.Hash.ToString("X2"));

}

}

catch (Exception ex)

{

Debug.WriteLine(ex.Message);

}

return sb.ToString();

}
 
T

Tomppa

My bad,

This does work.

My salt value was null on one end and an expty string on the other.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top