本文整理汇总了C#中System.Security.Cryptography.SHA512Managed.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# SHA512Managed.Dispose方法的具体用法?C# SHA512Managed.Dispose怎么用?C# SHA512Managed.Dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.SHA512Managed
的用法示例。
在下文中一共展示了SHA512Managed.Dispose方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculaHash
/// <summary>
/// Retorna el hash en format string de l'string paràmetre
/// </summary>
/// <param name="textIn"> és el text del qual volem calcular el hash</param>
/// <returns> retorna un string amb el hash resultat o null si hi ha error</returns>
static string CalculaHash(string textIn)
{
try
{
// Convertim l'string a un array de bytes
byte[] bytesIn = UTF8Encoding.UTF8.GetBytes(textIn);
// Instanciar classe per fer hash
SHA512Managed SHA512 = new SHA512Managed();
// Calcular hash
byte[] hashResult = SHA512.ComputeHash(bytesIn);
// Si volem mostrar el hash per pantalla o guardar-lo en un arxiu de text
// cal convertir-lo a un string
String textOut = BitConverter.ToString(hashResult, 0);
// Eliminem la classe instanciada
SHA512.Dispose();
return textOut;
}
catch (Exception)
{
Console.WriteLine("Error calculant el hash");
Console.ReadKey(true);
return null;
}
}
示例2: GetSHA2_512
/// <summary>
/// This will return the 512 bit SHA-2 hash.
/// </summary>
/// <param name="myString"></param>
/// <returns></returns>
public static byte[] GetSHA2_512(this string myString)
{
var data = myString.ToBytes();
SHA512 shaM = new SHA512Managed();
var result = shaM.ComputeHash(data);
shaM.Dispose();
return result;
}
示例3: CreatePasswordHash
public static string CreatePasswordHash(string _password, string _salt)
{
string saltAndPwd = String.Concat(_password, _salt);
SHA512 sha512 = new System.Security.Cryptography.SHA512Managed();
byte[] sha512Bytes = System.Text.Encoding.Default.GetBytes(saltAndPwd);
byte[] cryString = sha512.ComputeHash(sha512Bytes);
string hashedPwd = string.Empty;
for (int i = 0; i < cryString.Length; i++)
{
hashedPwd += cryString[i].ToString("X");
}
sha512.Clear();
sha512.Dispose();
return hashedPwd;
}
示例4: Main
static void Main(string[] args)
{
String textIn = null;
Console.Write("Entra text: ");
while (textIn==null)
textIn = Console.ReadLine();
// Convertim l'string a un array de bytes
byte[] bytesIn = UTF8Encoding.UTF8.GetBytes(textIn);
// Instanciar classe per fer hash
SHA512Managed SHA512 = new SHA512Managed();
// Calcular hash
byte[] hashResult = SHA512.ComputeHash(bytesIn);
// Si volem mostrar el hash per pantalla o guardar-lo en un arxiu de text
// cal convertir-lo a un string
String textOut = BitConverter.ToString(hashResult, 0);
Console.WriteLine("Hash {0}", textOut);
Console.ReadKey();
// Eliminem la classe instanciada
SHA512.Dispose();
}
示例5: ComputeHash
public static string ComputeHash(string plaintext, Supported_HA hash, byte[] salt)
{
int minSaltLength = 4;
int maxSaltLenght = 6;
byte[] SaltBytes = null;
if(salt!=null)
{
SaltBytes = salt;
}
else
{
Random r = new Random();
int SaltLenght = r.Next(minSaltLength, maxSaltLenght);
SaltBytes = new byte[SaltLenght];
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
rng.GetNonZeroBytes(SaltBytes);
rng.Dispose();
}
byte[] plaintData = ASCIIEncoding.UTF8.GetBytes(plaintext);
byte[] plainDataAndSalt = new byte[plaintData.Length + SaltBytes.Length];
for(int x=0; x<plaintData.Length;x++)
{
plainDataAndSalt[x] = plaintData[x];
}
for (int n = 0; n < SaltBytes.Length; n++)
plainDataAndSalt[plaintData.Length + n] = SaltBytes[n];
byte[] hashValue = null;
switch(hash)
{
case Supported_HA.SHA256:
SHA256Managed sha= new SHA256Managed();
hashValue= sha.ComputeHash(plainDataAndSalt);
sha.Dispose();
break;
case Supported_HA.SHA384:
SHA384Managed sha1 = new SHA384Managed();
hashValue = sha1.ComputeHash(plainDataAndSalt);
sha1.Dispose();
break;
case Supported_HA.SHA512:
SHA512Managed sha2 = new SHA512Managed();
hashValue = sha2.ComputeHash(plainDataAndSalt);
sha2.Dispose();
break;
}
byte[] resuflt = new byte[hashValue.Length + SaltBytes.Length];
for (int x = 0; x < hashValue.Length; x++)
resuflt[x] = hashValue[x];
for (int n = 0; n < SaltBytes.Length; n++)
resuflt[hashValue.Length + n] = SaltBytes[n];
return Convert.ToBase64String(resuflt);
}