In Windows Phone 8 I was able to do something like this:
SHA1Managed s = new SHA1Managed();
UTF8Encoding enc = new UTF8Encoding();
s.ComputeHash(enc.GetBytes(password.ToCharArray()));
string hash = BitConverter.ToString(s.Hash).Replace("-", "").ToLower();
For UWP App I am doing:
IBuffer buffUtf8Msg = CryptographicBuffer.ConvertStringToBinary(password, BinaryStringEncoding.Utf8);
HashAlgorithmProvider objAlgProv = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Sha1);
IBuffer buffHash = objAlgProv.HashData(buffUtf8Msg);
if (buffHash.Length != objAlgProv.HashLength)
{
throw new Exception("There was an error creating the hash");
}
string strHashBase64 = CryptographicBuffer.EncodeToBase64String(buffHash);
string hash = strHashBase64.Replace("-", "").ToLower();
I am not getting the same result.
For example, if I had the text "Windows 8", I would get
6517856f8c3a3fda3ae28305a05d127f0e1bdb97 (Windows Phone 8.1)
and
zrefb4w6p9o64omfof0sfw4b25c= (UWP)
I dont quite know what I am doing wrong. The goal is to just get the SHA1 hash of a string.
EncodeToBase64StringwithEncodeToHexString, then you will get the same result. – user6522773 Jul 31 '16 at 5:25