How to generate MD5 hash code for my WinRT app using C#?

前端 未结 1 1746
滥情空心
滥情空心 2020-12-09 16:39

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)
    {         


        
相关标签:
1条回答
  • 2020-12-09 17:15

    OK. I've found how to do this. Here's the final code:

        public static string ComputeMD5(string str)
        {
            var alg = HashAlgorithmProvider.OpenAlgorithm(HashAlgorithmNames.Md5);
            IBuffer buff = CryptographicBuffer.ConvertStringToBinary(str, BinaryStringEncoding.Utf8);
            var hashed = alg.HashData(buff);
            var res = CryptographicBuffer.EncodeToHexString(hashed);
            return res;
        }
    
    0 讨论(0)
提交回复
热议问题