本文整理汇总了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);
}
}