我正在創建一個MetroStyle應用程序,我想爲我的字符串生成一個MD5代碼。到目前爲止,我用這個:如何使用C#爲我的WinRT應用程序生成MD5哈希碼?
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;
}
}
但它拋出System.ArgumentOutOfRangeException
類型與以下錯誤消息的異常:
No mapping for the Unicode character exists in the target multi-byte code page. (Exception from HRESULT: 0x80070459)
我在做什麼錯在這裏?
哪一行會引發異常? –
'return res;'之前的行我的意思是'var res = ...' –