Reputation: 217
I try to get a md5 hash :
String clearKey = "test";
IBuffer buffEntry = CryptographicBuffer.ConvertStringToBinary(clearKey, BinaryStringEncoding.Utf8);
HashAlgorithmProvider algProvider = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Md5);
IBuffer buffHashed = algProvider.HashData(buffEntry);
byte[] bytesKey;
CryptographicBuffer.CopyToByteArray(buffHashed, out bytesKey);
Debug.WriteLine(String.Format("bytesKey lenght : {0}", bytesKey.Length));
Why my result has a size of 16 bytes? How to get a classical 32 Bytes result?
thank you for your help,
Upvotes: 0
Views: 928
Reputation: 108830
MD5 has a 128 bit or 16 byte output. So it's wrong to expect 32 bytes. I assume with 32 bytes, you mean a hex encoded string, where each byte maps to two characters, resulting in a 32 character string.
In metro you can CryptographicBuffer.EncodeToHexString
. to convert bytes to a hex string.
In your case this becomes:
string md5Hex = CryptographicBuffer.EncodeToHexStringbuffHashed(buffEntry);
Upvotes: 3