I'm creating a MetroStyle app and I want to generate a MD5 code for my string. So far I've used this:
public static string ComputeMD5(string str)
{
try
{
var alg = HashAlgorithmProvider.OpenAlgorithm("MD5");
IBuffer buff = CryptographicBuffer.ConvertStringToBinary(str, BinaryStringEncoding.Utf8);
var hashed = alg.HashData(buff);
var res = CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8, hashed);
return res;
}
catch (Exception ex)
{
return null;
}
}
but it throws an exception of type System.ArgumentOutOfRangeException
with the following error message:
No mapping for the Unicode character exists in the target multi-byte code page. (Exception from HRESULT: 0x80070459)
What am I doing wrong here?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…