本文整理汇总了C#中MD5.ComputeHash方法的典型用法代码示例。如果您正苦于以下问题:C# MD5.ComputeHash方法的具体用法?C# MD5.ComputeHash怎么用?C# MD5.ComputeHash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MD5
的用法示例。
在下文中一共展示了MD5.ComputeHash方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMd5Hash
//The following method was taken straight from the documentation
static string GetMd5Hash(MD5 md5Hash, string input)
{
// Convert the input string to a byte array and compute the hash.
byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder sBuilder = new StringBuilder();
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
// Return the hexadecimal string.
return sBuilder.ToString();
}
示例2: GetMd5Hash
/**
* Computer a md5 hash from a stream.
*
* @param MD5 cMd5 - The md5 instance.
* @param Stream cStream - The input stream.
* @return string - The md5 hash.
*/
private string GetMd5Hash(MD5 cMd5, Stream cStream)
{
// Convert the input stream to a byte array and compute the hash.
byte[] aData = cMd5.ComputeHash(cStream);
// Use a Stringbuilder to collect the bytes
// and create a string.
m_cTextBuf.Length = 0;
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = 0; i < aData.Length; i++)
{
m_cTextBuf.Append(aData[i].ToString("x2"));
}
// Return the hexadecimal string.
return m_cTextBuf.ToString();
}