本文整理汇总了C#中System.Security.Cryptography.SHA512Managed类的典型用法代码示例。如果您正苦于以下问题:C# SHA512Managed类的具体用法?C# SHA512Managed怎么用?C# SHA512Managed使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SHA512Managed类属于System.Security.Cryptography命名空间,在下文中一共展示了SHA512Managed类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Encryption2
public void Encryption2()
{
byte[] data = new byte[2];
byte[] result;
SHA512 shaM = new SHA512Managed();
result = shaM.ComputeHash(data);
}
示例2: MakeHash
private byte[] MakeHash(byte[] data)
{
using (var sha512Hash = new SHA512Managed())
{
return sha512Hash.ComputeHash(data);
}
}
示例3: EncryptOneWay
public static string EncryptOneWay(string data)
{
byte[] buf = Encoding.ASCII.GetBytes(data);
SHA512 sha = new SHA512Managed();
byte[] enc = sha.ComputeHash(buf);
return HexEncoding.ToString(enc);
}
示例4: sha512encrypt
public static string sha512encrypt(string phrase)
{
UTF8Encoding encoder = new UTF8Encoding();
SHA512Managed sha512hasher = new SHA512Managed();
byte[] hashedDataBytes = sha512hasher.ComputeHash(encoder.GetBytes(phrase));
return byteArrayToString(hashedDataBytes);
}
示例5: CreateUser
public void CreateUser(UserInfo userInfo)
{
if (userInfo == null)
{
throw new ArgumentNullException(nameof(userInfo));
}
if (string.IsNullOrWhiteSpace(userInfo.Username))
{
throw new ArgumentNullException(nameof(userInfo.Username));
}
if (string.IsNullOrWhiteSpace(userInfo.Password))
{
throw new ArgumentNullException(nameof(userInfo.Password));
}
if (UsernameExists(userInfo.Username))
{
throw new Exception("Username already exists, please enter a different username");
}
using (var shazam = new SHA512Managed())
{
var salt = GenerateSaltValue();
var passwordAndSalt = userInfo.Password + salt;
var hashedPassword = Encoding.UTF8.GetString(shazam.ComputeHash(Encoding.UTF8.GetBytes(passwordAndSalt)));
userInfo.Password = hashedPassword;
userInfo.Salt = salt;
userDal.CreateUser(userInfo);
}
}
示例6: btn_addUser_Click
// Add User buttonin logiikka
private void btn_addUser_Click(object sender, RoutedEventArgs e)
{
if (tb_password1.Password == tb_password2.Password && tb_password1.Password != "" && tb_password2.Password != "" && tb_username.Text != "") // Tarkistetaan että kentät on täytetty oikein.
{
SHA512 sha512 = new SHA512Managed(); // SHA512 cryptaus pitäisi riittää.
UTF8Encoding utf8 = new UTF8Encoding(); // SHA512 ottaa byte arrayn joten string täytyy muuttaa ennen kryptausta.
String password = BitConverter.ToString(sha512.ComputeHash(utf8.GetBytes(tb_password1.Password))); // Aika monimutkainen rivi joka muuttaa string byte arrayksi ja kryptaa sen
string dbConnectionString = @"Data Source=database.db;Version=3;"; // Määritellään sqlite tietokannan nimeksi database.db ja versioksi 3.
SQLiteConnection sqliteCon = new SQLiteConnection(dbConnectionString); // Tehdään yhteys olio sqliteCon jota voidaan käyttää myöhemmin.
try
{
sqliteCon.Open(); // Avataan sqlite yhteys
string Query = "INSERT INTO users (username, password) VALUES('" + this.tb_username.Text + "','" + password + "') "; // Syötetään uuden käyttäjän tiedot tietokantaan. Huom. kryptattu salasana.
SQLiteCommand createCommand = new SQLiteCommand(Query, sqliteCon); // Tehdään SQlite komento query ja sqlitecon argumenteilla.
createCommand.ExecuteNonQuery(); // Suoritetaan query.
sqliteCon.Close(); // Suljetaan db yhteys.
tb_username.Text = ""; // Tyhjennetään kentät ettei vahingossa upita samoja tietoja uudestaan
tb_password1.Password = "";
tb_password2.Password = "";
MessageBox.Show("User added successfully!"); // Ilmoitus käyttäjälle onnistumisesta.
}
catch (Exception ex)
{
MessageBox.Show(ex.Message); // Tai epäonnistumisesta.
}
}
else
{
MessageBox.Show("Oops, check the fields."); // Kaikki kentät pitää täyttää, ja vieläpä oikein.
}
}
示例7: GetHash
public static string GetHash(string text, HashType hashType = HashType.SHA512)
{
HashAlgorithm hashAlgorithm = null;
switch (hashType)
{
case HashType.MD5:
hashAlgorithm = new MD5CryptoServiceProvider();
break;
case HashType.SHA1:
hashAlgorithm = new SHA1Managed();
break;
case HashType.SHA256:
hashAlgorithm = new SHA256Managed();
break;
case HashType.SHA512:
hashAlgorithm = new SHA512Managed();
break;
}
return ComputeHash(text, hashAlgorithm);
}
示例8: GetPasswordHash
private string GetPasswordHash(string stringPassword)
{
using (var sha512 = new SHA512Managed())
{
return BitConverter.ToString(sha512.ComputeHash(Encoding.Default.GetBytes(stringPassword)));
}
}
示例9: CreateHashSha512
public byte[] CreateHashSha512(string userEnteredPw)
{
//userEnteredPw = userEnteredPw.Trim();
SHA512Managed sha512 = new SHA512Managed();
return sha512.ComputeHash(Encoding.UTF8.GetBytes(userEnteredPw));
}
示例10: GetHash
public static string GetHash(string text, string type, Encoding enc, string outputType = null)
{
type = type.ToLower();
byte[] message = enc.GetBytes( text );
HashAlgorithm algo = null;
switch (type)
{
case "md5":
algo = new MD5CryptoServiceProvider();
break;
case "sha1":
algo = new SHA1Managed();
break;
case "sha256":
algo = new SHA256Managed();
break;
case "sha384":
algo = new SHA384Managed();
break;
case "sha512":
algo = new SHA512Managed();
break;
default:
throw new ArgumentException("Type must be one of ['md5', 'sha1', 'sha256', 'sha384', 'sha512'].", "type");
}
return GetOutput( algo.ComputeHash( message ), outputType );
}
示例11: BufferColumnStream
public void BufferColumnStream()
{
var data = new byte[1024];
var memoryStream = new MemoryStream();
Api.JetBeginTransaction(this.sesid);
Api.JetPrepareUpdate(this.sesid, this.tableid, JET_prep.Insert);
using (var stream = new BufferedStream(new ColumnStream(this.sesid, this.tableid, this.columnidLongText), SystemParameters.LVChunkSizeMost))
{
for (int i = 0; i < 10; ++i)
{
stream.Write(data, 0, data.Length);
memoryStream.Write(data, 0, data.Length);
}
}
this.UpdateAndGotoBookmark();
Api.JetCommitTransaction(this.sesid, CommitTransactionGrbit.LazyFlush);
var hasher = new SHA512Managed();
memoryStream.Position = 0;
var expected = hasher.ComputeHash(memoryStream);
using (var stream = new BufferedStream(new ColumnStream(this.sesid, this.tableid, this.columnidLongText), SystemParameters.LVChunkSizeMost))
{
var actual = hasher.ComputeHash(stream);
CollectionAssert.AreEqual(expected, actual);
}
}
示例12: CalculateSha512Hash
public static string CalculateSha512Hash(string input)
{
var inputBytes = Encoding.UTF8.GetBytes(input);
var hasher = new SHA512Managed();
var hashBytes = hasher.ComputeHash(inputBytes);
return BitConverter.ToString(hashBytes).Replace("-", string.Empty).ToLowerInvariant();
}
示例13: VerifySHA512Hash
public static void VerifySHA512Hash(byte[] bytesA, byte[] bytesB)
{
SHA512 shaM = new SHA512Managed();
byte[] hashA = shaM.ComputeHash(bytesA);
byte[] hashB = shaM.ComputeHash(bytesB);
// Create a StringComparer an compare the hashes.
StringComparer comparer = StringComparer.OrdinalIgnoreCase;
// Create a new Stringbuilder to collect the bytes
// and create a string.
StringBuilder hashAStringBuilder = new StringBuilder();
StringBuilder hashBStringBuilder = new StringBuilder();
// Loop through each byte of the hashed data
// and format each one as a hexadecimal string.
for (int i = 0; i < hashA.Length; i++)
{
hashAStringBuilder.Append(hashA[i].ToString("x2"));
}
string inputA = hashAStringBuilder.ToString();
for (int i = 0; i < hashB.Length; i++)
{
hashBStringBuilder.Append(hashB[i].ToString("x2"));
}
string inputB = hashBStringBuilder.ToString();
if (comparer.Compare(inputA, inputB) != 0)
{
Assert.Fail("Hash not match! Expected: '{0}', but was '{1}'", inputA, inputB);
}
}
示例14: Hash
public static byte[] Hash(string s)
{
using (SHA512 shaM = new SHA512Managed())
{
return shaM.ComputeHash(Encoding.UTF8.GetBytes(s));
}
}
示例15: Proof
/// <summary>
/// Creates a new sum proof.
/// </summary>
/// <param name="r">The randomness used to encrypt the vote.</param>
/// <param name="voteSum">The sum of all votes for which to generate a proof.</param>
/// <param name="publicKey">The public key with which the vote was encrypted.</param>
/// <param name="parameters">Cryptographic Parameters.</param>
public Proof(BigInt r, Vote voteSum, BigInt publicKey, BaseParameters parameters)
{
if (r == null)
throw new ArgumentNullException("r");
if (voteSum == null)
throw new ArgumentNullException("vote");
if (publicKey == null)
throw new ArgumentNullException("publicKey");
if (parameters == null)
throw new ArgumentNullException("parameters");
BigInt r0 = parameters.Random();
T0 = publicKey.PowerMod(r0, parameters.P);
MemoryStream serializeStream = new MemoryStream();
SerializeContext serializer = new SerializeContext(serializeStream);
serializer.Write(voteSum.Ciphertext);
serializer.Write(voteSum.HalfKey);
serializer.Write(publicKey);
serializer.Write(T0);
serializer.Close();
serializeStream.Close();
SHA512Managed sha512 = new SHA512Managed();
byte[] hash = sha512.ComputeHash(serializeStream.ToArray());
C0 = hash[0] | (hash[1] << 8);
S0 = r0 + r * C0;
}