本文整理匯總了C#中System.Security.Cryptography.MD5CryptoServiceProvider.GetType方法的典型用法代碼示例。如果您正苦於以下問題:C# MD5CryptoServiceProvider.GetType方法的具體用法?C# MD5CryptoServiceProvider.GetType怎麽用?C# MD5CryptoServiceProvider.GetType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Security.Cryptography.MD5CryptoServiceProvider
的用法示例。
在下文中一共展示了MD5CryptoServiceProvider.GetType方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
static void Main(string[] args)
{
//geração de hash com MD5
StreamReader sr = new StreamReader("Arquivo.txt");
String mensagem = sr.ReadToEnd();
sr.Close();
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] bytes = Encoding.Default.GetBytes(mensagem);
byte[] hash = md5.ComputeHash(bytes);
Gravar(hash, md5.GetType().Name);
Process.Start("notepad", String.Format("{0}.hash", md5.GetType().Name));
}
示例2: GenerateChecksum
/// <summary>
/// Generate a checksum.
/// </summary>
/// <param name="fullPath">The full path of the file to generate a checksum for.</param>
public void GenerateChecksum(string fullPath)
{
using (FileStream file = new FileStream(fullPath, FileMode.Open,FileAccess.Read,FileShare.Read))
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] retVal = md5.ComputeHash(file);
file.Close();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < retVal.Length; i++)
{
sb.Append(retVal[i].ToString("x2"));
}
Checksum = sb.ToString();
ChecksumType = md5.GetType().ToString();
}
}
示例3: VerifyChecksum
/// <summary>
/// Verify a checksum.
/// </summary>
/// <param name="fullPath">The path to the file.</param>
public void VerifyChecksum(string fullPath)
{
MD5 md5 = new MD5CryptoServiceProvider();
if (md5.GetType().ToString().Equals(ChecksumType))
{
using (FileStream file = new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
byte[] retVal = md5.ComputeHash(file);
file.Close();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < retVal.Length; i++)
{
sb.Append(retVal[i].ToString("x2"));
}
if (!Checksum.Equals(sb.ToString()))
throw new ApplicationException("Checksum does not match for file " + fullPath);
}
}
else
{
throw new ApplicationException("Unknown checksum type: " + ChecksumType);
}
}