本文整理汇总了C#中System.Security.Cryptography.SHA1CryptoServiceProvider.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# System.Security.Cryptography.SHA1CryptoServiceProvider.Dispose方法的具体用法?C# System.Security.Cryptography.SHA1CryptoServiceProvider.Dispose怎么用?C# System.Security.Cryptography.SHA1CryptoServiceProvider.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.SHA1CryptoServiceProvider
的用法示例。
在下文中一共展示了System.Security.Cryptography.SHA1CryptoServiceProvider.Dispose方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Generate
public static string Generate()
{
// Generate random
var rnd = new System.Security.Cryptography.RNGCryptoServiceProvider();
var entropy = new byte[bytes - 4];
try {
rnd.GetBytes(entropy);
} finally {
rnd.Dispose();
}
// Hash
var sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
byte[] hash;
try {
hash = sha.ComputeHash(entropy);
} finally {
sha.Dispose();
}
// Compute output
var raw = new byte[bytes];
Array.Copy(entropy, 0, raw, 0, bytes - 4);
Array.Copy(hash, 0, raw, bytes - 4, 4);
// Convert to Base64
return Convert.ToBase64String(raw).Replace('+', '!').Replace('/', '~');
}
示例2: Validate
public static bool Validate(string sid)
{
// Basic sanity checks
if (null == sid) return false;
if (sid.Length != 32) return false;
// Decode Base64
byte[] raw;
try {
raw = Convert.FromBase64String(sid.Replace('!', '+').Replace('~', '/'));
} catch (FormatException) {
return false; // Not valid Base64
}
// Break into components
var entropy = new byte[bytes - 4];
var hash = new byte[4];
Array.Copy(raw, 0, entropy, 0, bytes - 4);
Array.Copy(raw, bytes - 4, hash, 0, 4);
// Hash
var sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
byte[] buffer;
try {
buffer = sha.ComputeHash(entropy);
} finally {
sha.Dispose();
}
var checkhash = new byte[4];
Array.Copy(buffer, 0, checkhash, 0, 4);
// Check hash
if (!hash.ByteArraysEqual(checkhash)) return false;
return true;
}
示例3: Main
public static string root = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); // string root points to MyDocuments
#endregion Fields
#region Methods
static void Main(string[] args)
{
if (args.Length > 0)
{
if (args[0] == "-v")
{
Console.WriteLine("asdasd");
if (File.Exists(prefs + "/gkey"))
{
using (System.IO.StreamReader sr = new System.IO.StreamReader(prefs + "/gkey"))
{
string data = sr.ReadToEnd();
string[] f = data.Split('\n');
sr.Dispose();
if (f[0] == "accepted")
{
string HASH = f[1].ToString();
using (System.Security.Cryptography.SHA1CryptoServiceProvider sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider())
{
string hashsum = string.Empty; // Empty storage allocator
byte[] da = sha1.ComputeHash(Encoding.Unicode.GetBytes(prefs + "/gkey")); // byte array
foreach (byte by in data)
{
hashsum += String.Format("{0,2:X2}", by); // :-)
}
if (hashsum.ToString() != HASH.ToString())
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("SECURITY COMPROMISED!\n\nSHA1 HASH MODIFIED!\nRECORD DOES NOT MATCH G_KEY!\n\nCACHE WILL BE DELETED FOR SECURITY.");
Console.Read();
}
else ;
sha1.Dispose();
try
{
Directory.Delete(prefs);
}
catch { ; }
}
}
}
}
}
}
else
{
Console.Write("This is not a standalone application.");
}
}