本文整理汇总了C#中System.Security.Cryptography.SHA1CryptoServiceProvider.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# SHA1CryptoServiceProvider.Clear方法的具体用法?C# SHA1CryptoServiceProvider.Clear怎么用?C# SHA1CryptoServiceProvider.Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.SHA1CryptoServiceProvider
的用法示例。
在下文中一共展示了SHA1CryptoServiceProvider.Clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: encriptarCadena
public static string encriptarCadena(string cadena)
{
SHA1CryptoServiceProvider elProveedor = new SHA1CryptoServiceProvider();
byte[] vectoBytes = System.Text.Encoding.UTF8.GetBytes(cadena);
byte[] inArray = elProveedor.ComputeHash(vectoBytes);
elProveedor.Clear();
return Convert.ToBase64String(inArray);
}
示例3: HashStringSHA1
public static string HashStringSHA1(string textToHash)
{
System.Security.Cryptography.SHA1CryptoServiceProvider SHA1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
byte[] byteValue = System.Text.Encoding.UTF8.GetBytes(textToHash);
byte[] byteHash = SHA1.ComputeHash(byteValue);
SHA1.Clear();
return Convert.ToBase64String(byteHash);
}
示例4: ComputeHash
/// <summary>
/// Computes a hash using SHA1
/// </summary>
/// <param name="Input">Input string</param>
/// <returns>A hash of the input string using SHA1</returns>
public static string ComputeHash(string Input)
{
SHA1CryptoServiceProvider SHA1 = new SHA1CryptoServiceProvider();
byte[] InputArray = System.Text.Encoding.ASCII.GetBytes(Input);
byte[] HashedArray = SHA1.ComputeHash(InputArray);
SHA1.Clear();
return BitConverter.ToString(HashedArray).Replace("-", "");
}
示例5: SHA1Encrypt
/// <summary>
/// SHA1加密
/// </summary>
/// <param name="insertStr"></param>
/// <returns></returns>
public static string SHA1Encrypt(string insertStr)
{
byte[] tmpByte;
SHA1 sha1 = new SHA1CryptoServiceProvider();
tmpByte = sha1.ComputeHash(GetKeyByteArray(insertStr));
sha1.Clear();
return GetStringValue(tmpByte);
}
示例6: ComputingResult
public void ComputingResult()
{
UTF8Encoding utf8 = new UTF8Encoding();
byte[] textWithSaltBytes = utf8.GetBytes(string.Concat(PlainText, Salt));
HashAlgorithm hasher = new SHA1CryptoServiceProvider();
byte[] hashedBytes = hasher.ComputeHash(textWithSaltBytes);
hasher.Clear();
result = Convert.ToBase64String(hashedBytes);
}
示例7: EncryptToSHA1
public static string EncryptToSHA1(string str)
{
SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
byte[] str1 = Encoding.UTF8.GetBytes(str);
byte[] str2 = sha1.ComputeHash(str1);
sha1.Clear();
(sha1 as IDisposable).Dispose();
return ToHexString(str2);
}
示例8: Encriptar
/// <summary>
/// Encripta una Cadena con el Método Hash
/// </summary>
/// <param name="cadena">Cadena a encriptar</param>
public static string Encriptar(string cadena)
{
HashAlgorithm hashValue = new SHA1CryptoServiceProvider();
byte[] byteValue = Encoding.UTF8.GetBytes(cadena);
byte[] byteHash = hashValue.ComputeHash(byteValue);
hashValue.Clear();
return Convert.ToBase64String(byteHash);
}
示例9: FromString
public static string FromString(string input, HashType hashtype)
{
Byte[] clearBytes;
Byte[] hashedBytes;
string output = String.Empty;
switch (hashtype)
{
case HashType.RIPEMD160:
clearBytes = new UTF8Encoding().GetBytes(input);
RIPEMD160 myRIPEMD160 = RIPEMD160Managed.Create();
hashedBytes = myRIPEMD160.ComputeHash(clearBytes);
output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
break;
case HashType.MD5:
clearBytes = new UTF8Encoding().GetBytes(input);
hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
break;
case HashType.SHA1:
clearBytes = Encoding.UTF8.GetBytes(input);
SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
sha1.ComputeHash(clearBytes);
hashedBytes = sha1.Hash;
sha1.Clear();
output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
break;
case HashType.SHA256:
clearBytes = Encoding.UTF8.GetBytes(input);
SHA256 sha256 = new SHA256Managed();
sha256.ComputeHash(clearBytes);
hashedBytes = sha256.Hash;
sha256.Clear();
output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
break;
case HashType.SHA384:
clearBytes = Encoding.UTF8.GetBytes(input);
SHA384 sha384 = new SHA384Managed();
sha384.ComputeHash(clearBytes);
hashedBytes = sha384.Hash;
sha384.Clear();
output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
break;
case HashType.SHA512:
clearBytes = Encoding.UTF8.GetBytes(input);
SHA512 sha512 = new SHA512Managed();
sha512.ComputeHash(clearBytes);
hashedBytes = sha512.Hash;
sha512.Clear();
output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
break;
}
return output;
}
示例10: CreateSaltedPassword
/// <summary>
/// Creates a slated version of an input Password
/// </summary>
/// <param name="salt">Salt of Password</param>
/// <param name="password">Clear Password</param>
/// <param name="iterations">Number of times to iterate Salt</param>
/// <returns></returns>
public string CreateSaltedPassword(string salt, string password, int iterations)
{
SHA1CryptoServiceProvider SHA1 = new SHA1CryptoServiceProvider();
byte[] byteValue = System.Text.Encoding.UTF8.GetBytes(salt + password);
do
{
byteValue = SHA1.ComputeHash(byteValue);
} while (--iterations > 0);
SHA1.Clear();
return Convert.ToBase64String(byteValue);
}
示例11: GenKey
byte[] GenKey(byte[] key)
{
for (int x = 0; x < 10000; x++)
{
SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
sha1.TransformBlock(key, 0, key.Length, key, 0);
key = sha1.TransformFinalBlock(ASCIIEncoding.ASCII.GetBytes("fuckoff"), 0, 7);
sha1.Clear();
}
return key;
}
示例12: Salt
public static string Salt(string salt, string password)
{
var sha1 = new SHA1CryptoServiceProvider();
var byteValue = Encoding.UTF8.GetBytes(salt + password);
var byteHash = sha1.ComputeHash(byteValue);
sha1.Clear();
return Convert.ToBase64String(byteHash);
}
示例13: ComputeHash
public static String ComputeHash(byte[] buffer)
{
SHA1CryptoServiceProvider hashProvider1 = new SHA1CryptoServiceProvider();
byte[] sha1Hash = hashProvider1.ComputeHash(buffer);
StringBuilder sha1Text = new StringBuilder();
foreach (byte iByte in sha1Hash)
{
sha1Text.AppendFormat("{0:x2}", iByte);
}
hashProvider1.Clear();
return sha1Text.ToString();
}
示例14: SHA1Encrypt
/// <summary>
/// sha1 加密字符串
/// </summary>
/// <param name="sourceString"></param>
/// <returns></returns>
public static string SHA1Encrypt(string sourceString)
{
if (string.IsNullOrEmpty(sourceString))
return string.Empty;
byte[] bytRes = Encoding.UTF8.GetBytes(sourceString);
HashAlgorithm iSHA = new SHA1CryptoServiceProvider();
byte[] bytHash = iSHA.ComputeHash(bytRes);
iSHA.Clear();
StringBuilder sbEnText = new StringBuilder();
foreach (byte byt in bytHash)
{
sbEnText.AppendFormat("{0:x2}", byt);
}
return sbEnText.ToString();
}
示例15: Salt
internal static string Salt(string salt, string password)
{
var sha1 = new SHA1CryptoServiceProvider();
// Convert the string into an array of bytes.
byte[] byteValue = Encoding.UTF8.GetBytes(salt + password);
// Compute the hash value.
byte[] byteHash = sha1.ComputeHash(byteValue);
// Dispose the unmanaged cryptographic object.
sha1.Clear();
// Convert the byte array back into a string.
return Convert.ToBase64String(byteHash);
}