本文整理汇总了C#中System.Security.Cryptography.SHA1CryptoServiceProvider.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# SHA1CryptoServiceProvider.Dispose方法的具体用法?C# SHA1CryptoServiceProvider.Dispose怎么用?C# SHA1CryptoServiceProvider.Dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.SHA1CryptoServiceProvider
的用法示例。
在下文中一共展示了SHA1CryptoServiceProvider.Dispose方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Encrypt_static
/// <summary>
/// SHA1CryptoServiceProvider 类的哈希大小为 160 位
/// 此类型的任何公共static成员都是线程安全的。但不保证所有实例成员都是线程安全的
/// </summary>
private static string Encrypt_static(string clearText, Encoding encode)
{
SHA1 sha = null;
try
{
byte[] originalBytes = encode.GetBytes(clearText); //Encoding.UTF8.GetBytes(clearText);
sha = new SHA1CryptoServiceProvider();
byte[] data = sha.ComputeHash(originalBytes);
//return BitConverter.ToString(data); //将指定的字节数组的每个元素的数值转换为它的等效十六进制字符串表示形式
StringBuilder builder = new StringBuilder();
foreach (var item in data)
{
builder.Append(item.ToString("X2"));//将该哈希作为 32 字符的十六进制格式字符串返回
}
return builder.ToString();
}
catch (ArgumentNullException) { return clearText; }
catch (EncoderFallbackException) { return clearText; }
catch (ObjectDisposedException) { return clearText; }
catch (Exception) { return clearText; }
finally
{
if (sha != null)
{
sha.Clear();
sha.Dispose();
}
sha = null;
}
}
示例2: GetSha1
/// <summary>
/// This will return the SHA-1 has of a string.
/// </summary>
/// <param name="myString"></param>
/// <returns></returns>
public static byte[] GetSha1(this string myString)
{
var data = myString.ToBytes();
SHA1 sha = new SHA1CryptoServiceProvider();
var result = sha.ComputeHash(data);
sha.Dispose();
return result;
}
示例3: SetKey
public void SetKey(byte[] key)
{
Key = key;
SHA1 digest = new SHA1CryptoServiceProvider();
key = digest.ComputeHash(key);
digest.Dispose();
Log.Info("[ENCRYPTION-KEY]", DumpData(key));
encryption = new ARC4(key);
decryption = new ARC4(key);
}
示例4: Encryption
public Encryption(byte[] key = null)
{
if (key == null)
{
key = new byte[8];
Random generator = new Random();
generator.NextBytes(key);
generator = null;
}
Key = key;
SHA1 digest = new SHA1CryptoServiceProvider();
key = digest.ComputeHash(key);
digest.Dispose();
Log.Info("[ENCRYPTION-KEY]", DumpData(key));
encryption = new ARC4(key);
decryption = new ARC4(key);
}
示例5: Encryption
public Encryption(byte[] key = null)
{
if (key == null)
{
key = new byte[8];
Random generator = new Random();
generator.NextBytes(key);
generator = null;
}
Key = key;
SHA1 digest = new SHA1CryptoServiceProvider();
key = digest.ComputeHash(key);
digest.Dispose();
Console.Write("New key:");
for (int i = 0; i < 20; i++)
{
Console.Write(" " + key[i]);
}
Console.WriteLine();
encryption = new ARC4(key);
decryption = new ARC4(key);
}
示例6: Login
public void Login(String email, String password)
{
Encoding enc = Encoding.ASCII;
byte[] buffer = new byte[0];
String pass = "";
try
{
buffer = enc.GetBytes(password);
}
catch (Exception e)
{
}
SHA1CryptoServiceProvider cryptoTransformSHA1 = new SHA1CryptoServiceProvider();
try
{
pass = BitConverter.ToString(cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "");
}
catch (Exception e)
{
}
cryptoTransformSHA1.Dispose();
pass = pass.ToLower();
SocketMessage sm = new SocketMessage("LOG");
sm.Arguments.Add(email);
sm.Arguments.Add(pass);
this.writeMessage(sm);
}
示例7: SHA1
/// <summary>
/// SHA1 加密,返回大写字符串
/// </summary>
/// <param name="content">需要加密字符串</param>
/// <param name="encode">指定加密编码</param>
/// <returns>返回40位大写字符串</returns>
public static string SHA1(string content, Encoding encode)
{
try
{
SHA1 sha1 = new SHA1CryptoServiceProvider();
byte[] bytes_in = encode.GetBytes(content);
byte[] bytes_out = sha1.ComputeHash(bytes_in);
sha1.Dispose();
string result = BitConverter.ToString(bytes_out);
result = result.Replace("-", "");
return result;
}
catch (Exception ex)
{
throw new Exception("SHA1加密出错:" + ex.Message);
}
}
示例8: Sha1
public string Sha1(string value)
{
if(value.IsNull())
throw new ArgumentNullException("value");
var x = new SHA1CryptoServiceProvider();
var data = Encoding.UTF8.GetBytes(value);
data = x.ComputeHash(data);
#if false
x.Dispose();
#endif
var ret = string.Empty;
for(var i = 0; i < data.Length; i++)
ret += data[i].ToString("x2").ToLower();
return ret;
}
示例9: GetSignature
/// <summary>
/// Get signature for the chunk.
/// </summary>
/// <param name="array">The data of the chunk.</param>
/// <returns>The signature instance.</returns>
private SignatureObject GetSignature(byte[] array)
{
if (this.FileContent.Length <= 250 * 1024 * 1024)
{
SHA1 sha = new SHA1CryptoServiceProvider();
byte[] temp = sha.ComputeHash(array);
sha.Dispose();
SignatureObject signature = new SignatureObject();
signature.SignatureData = new BinaryItem(temp);
return signature;
}
else
{
throw new NotImplementedException("When the file size is larger than 250MB, the signature method is not implemented.");
}
}
示例10: GetSHA1Signature
/// <summary>
/// Get signature with SHA1 algorithm.
/// </summary>
/// <param name="array">The input data.</param>
/// <returns>An instance of SignatureObject.</returns>
private SignatureObject GetSHA1Signature(byte[] array)
{
SHA1 sha = new SHA1CryptoServiceProvider();
byte[] temp = sha.ComputeHash(array);
sha.Dispose();
SignatureObject signature = new SignatureObject();
signature.SignatureData = new BinaryItem(temp);
return signature;
}
示例11: GetSingleChunkSignature
/// <summary>
/// Get the signature for single chunk.
/// </summary>
/// <param name="header">The data of file header.</param>
/// <param name="dataFile">The data of data file.</param>
/// <returns>An instance of SignatureObject.</returns>
private SignatureObject GetSingleChunkSignature(byte[] header, byte[] dataFile)
{
SHA1 sha = new SHA1CryptoServiceProvider();
byte[] headerSignature = sha.ComputeHash(header);
sha.Dispose();
byte[] singleSignature = null;
if (SharedContext.Current.CellStorageVersionType.MinorVersion >= 2)
{
singleSignature = new byte[dataFile.Length];
for (int i = 0; i < headerSignature.Length; i++)
{
singleSignature[i] = (byte)(headerSignature[i] ^ dataFile[i]);
}
}
else
{
List<byte> tmp = new List<byte>();
tmp.AddRange(headerSignature);
tmp.AddRange(dataFile);
singleSignature = tmp.ToArray();
}
SignatureObject signature = new SignatureObject();
signature.SignatureData = new BinaryItem(singleSignature);
return signature;
}
示例12: GetHash
/// <summary>
/// Obtain a hash value for a given string.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static string GetHash(string value)
{
byte[] clearBytes = Encoding.UTF8.GetBytes(value);
SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
sha1.ComputeHash(clearBytes);
byte[] hashedBytes = sha1.Hash;
sha1.Dispose();
return BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
}
示例13: GenerateFileHash
public static string GenerateFileHash(Stream Source)
{
SHA1 shar = new SHA1CryptoServiceProvider();
byte[] result = shar.ComputeHash(Source);
shar.Dispose();
StringBuilder output = new StringBuilder();
foreach (byte x in result)
{
output.Append(string.Format("{0:x2}", x));
}
return output.ToString();
}