/// <summary> /// Returns a hash value from a byte array. /// </summary> /// <param name="input">The byte array to hash.</param> /// <param name="bits">The length of the hash (256, 384, or 512).</param> /// <returns></returns> private static Byte[] BytesToHash(Byte[] input, Int32 bits) { Byte[] hash = new Byte[0]; switch (bits) { case 256: hash = new SHA256Cng().ComputeHash(input); break; case 384: hash = new SHA384Cng().ComputeHash(input); break; case 512: hash = new SHA512Cng().ComputeHash(input); break; default: hash = new SHA256Cng().ComputeHash(input); break; } return(hash); }
public static bool CreateSHA512HashForFile(string filename, out string hashbase64) { hashbase64 = ""; if (!File.Exists(filename)) { return(false); } try { { Byte[] hash = null; using (Stream inputStream = File.OpenRead(filename)) { using (HashAlgorithm sha = new SHA512Cng()) { hash = sha.ComputeHash(inputStream); } } hashbase64 = Convert.ToBase64String(hash); return(true); } } catch { return(false); } }
/// <summary> /// Hash the data passed using the hash size specified defaulting to 256 if nothing is specified. /// </summary> /// <param name="data">The data to get a hash value (signature).</param> /// <param name="hashSize">The hash size to use (1, 256, 384 or 512)</param> /// <returns>A Byte[] the is a unique signature of the data passed.</returns> public static Byte[] SHACngHash(Byte[] data, Int32 hashSize) { Byte[] lHash = null; if (data != null) { if (hashSize == 512) { using (SHA512Cng sha = new SHA512Cng()) { lHash = sha.ComputeHash(data); } } else if (hashSize == 384) { using (SHA384Cng sha = new SHA384Cng()) { lHash = sha.ComputeHash(data); } } else if (hashSize == 256) { using (SHA256Cng sha = new SHA256Cng()) { lHash = sha.ComputeHash(data); } } else { using (SHA1Cng sha = new SHA1Cng()) { lHash = sha.ComputeHash(data); } } } return(lHash); }
public static byte[] ToSHA512(this byte[] s) { using (var sha512 = new SHA512Cng()) { return(sha512.ComputeHash(s)); } }
// Token: 0x06000E63 RID: 3683 RVA: 0x00056AF8 File Offset: 0x00054CF8 private void PopulatePolicyHash() { SharingPolicyDomain[] array = null; if (this.policy.Domains != null) { array = new SharingPolicyDomain[this.policy.Domains.Count]; for (int i = 0; i < this.policy.Domains.Count; i++) { array[i] = this.policy.Domains[i]; } Array.Sort <SharingPolicyDomain>(array, (SharingPolicyDomain a, SharingPolicyDomain b) => StringComparer.OrdinalIgnoreCase.Compare(a.Domain, b.Domain)); } StringBuilder stringBuilder = new StringBuilder("V1.0", 200); stringBuilder.Append(this.policy.Enabled); if (array != null) { foreach (SharingPolicyDomain sharingPolicyDomain in array) { stringBuilder.Append(","); stringBuilder.Append(sharingPolicyDomain.Domain); stringBuilder.Append(":"); stringBuilder.Append(sharingPolicyDomain.Actions.ToString()); } } string text = stringBuilder.ToString(); SharingPolicyCache.Tracer.TraceDebug <string>(0L, "String representation of policy: {0}", text); byte[] bytes = Encoding.ASCII.GetBytes(text); using (SHA512Cng sha512Cng = new SHA512Cng()) { this.hash = sha512Cng.ComputeHash(bytes); } }
private void MainUI_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { if (counter == 4) { counter = 0; } keys[counter] = e; counter++; var KeyString = ""; byte[] DataHash = new byte[1]; foreach (var item in keys) { if (item != null) { KeyString += ("" + item.KeyData).Remove(0, 1); } } try { DataHash = SHA512Cng.Create().ComputeHash(BitConverter.GetBytes(Convert.ToInt32(KeyString))); } catch (Exception) { } if (DataHash.SequenceEqual(DataBuffer)) { new Thread(FadeCalcOut).Start(); Array.Clear(keys, 0, keys.Length); populate(); } }
/// <summary> /// Computes the SHA512 Salted Hash of a password. /// </summary> /// <param name="password">The password to hash.</param> /// <param name="salt">The salt.</param> /// <returns>A SHA512 hash of the password.</returns> public byte[] ComputeHash_ShaSalt(string password, byte[] salt) { var sha = new SHA512Cng(); var concatStr = _stringHandler.GetBytes(String.Concat(password, salt)); return(sha.ComputeHash(concatStr)); }
public static async Task <byte[]> CopyWithHash(string srcpath, string dstpath) { var bufferQ = new BufferBlock <Buffer>(); var computeQ = new BufferBlock <Buffer>(); var writeQ = new BufferBlock <Buffer>(); // バッファは適当に4つ for (int i = 0; i < 4; ++i) { bufferQ.Post(new Buffer() { buffer = new byte[2 * 1024 * 1024] }); } var sha512 = new SHA512Cng(); using (var src = File.OpenRead(srcpath)) using (var dst = File.Create(dstpath)) await Task.WhenAll( ReadFile(bufferQ, computeQ, src), ComputeHash(computeQ, writeQ, sha512), WriteFile(writeQ, bufferQ, dst)); return(sha512.Hash); }
public static byte[] ToSHA512Cng(this string s, Encoding encoding) { using (var sha512 = new SHA512Cng()) { return(sha512.ComputeHash(s.GetBytes(encoding))); } }
public static String ComputeSHA512(byte[] bytes) { using (var hashAlgorithmImpl = new SHA512Cng()) { var hashBytes = hashAlgorithmImpl.ComputeHash(bytes); return(String.Concat(hashBytes.Select(b => b.ToString("x2")))); } }
private static byte[] GetSHA512Hash(string filePath) { using (var shaHasher = new SHA512Cng()) using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { return(shaHasher.ComputeHash(fileStream)); } }
public string Encrypt(string password) { SHA512 test = SHA512Cng.Create(); byte[] passHash = Encoding.UTF8.GetBytes(password); byte[] Encrypted = test.ComputeHash(passHash); password = GetStringFromHash(Encrypted); return(password); }
/// <summary> /// CheckSum512 method implementation /// </summary> public static byte[] CheckSum512(byte[] value) { byte[] hash = null; using (SHA512 sha512 = SHA512Cng.Create()) { hash = sha512.ComputeHash(value); } return(hash); }
public static byte[] hashNoSalt(string plaintext) { SHA512Cng hashFunc = new SHA512Cng(); byte[] plainBytes = System.Text.Encoding.ASCII.GetBytes(plaintext); byte[] toHash = new byte[plainBytes.Length]; plainBytes.CopyTo(toHash, 0); return(hashFunc.ComputeHash(toHash)); }
public static string Sha512Cng(this string self) { using (var sha512cng = new SHA512Cng()) { return(sha512cng.ComputeHash(Encoding.UTF8.GetBytes(self)) .Select(hash => hash.ToString("x2")) .Join(string.Empty)); } }
/// <summary> /// Method of hashing and salting /// </summary> /// <param name="element">the string element to encrypt</param> /// <returns>the encrypt element</returns> public static byte[] SalAndHash(string element) { Encoding u8 = Encoding.UTF8; byte[] textAsByte = u8.GetBytes($"u0n2p5e7u4D9e@s)a!laGùe$pa,erCi{element}u0n2p5e57dncpo3édzpa,erCi"); SHA512 sha512 = SHA512Cng.Create(); byte[] hash = sha512.ComputeHash(textAsByte); return(hash); }
internal static byte[] Hash(string plaintext, byte[] salt) { SHA512Cng hashFunc = new SHA512Cng(); byte[] plainBytes = System.Text.Encoding.ASCII.GetBytes(plaintext); byte[] toHash = new byte[plainBytes.Length + salt.Length]; plainBytes.CopyTo(toHash, 0); salt.CopyTo(toHash, plainBytes.Length); return(hashFunc.ComputeHash(toHash)); }
static public string hash(string chaine) { byte[] textAsByte = Encoding.Default.GetBytes(chaine); SHA512 sha512 = SHA512Cng.Create(); byte[] hash = sha512.ComputeHash(textAsByte); return(Convert.ToBase64String(hash)); }
public static byte[] Hash(string plaintext, byte[] salt) { var hashFunc = new SHA512Cng(); var plainBytes = Encoding.ASCII.GetBytes(plaintext); var toHash = new byte[plainBytes.Length + salt.Length]; plainBytes.CopyTo(toHash, 0); salt.CopyTo(toHash, plainBytes.Length); return(hashFunc.ComputeHash(toHash)); }
private string GetPinHash(string pin) { string pinHash; using (var crypto = new SHA512Cng()) { pinHash = Encoding.ASCII.GetString(crypto.ComputeHash(Encoding.ASCII.GetBytes(pin))); } return(pinHash); }
public static byte[] hash(string pPlainText, byte[] pSalt) { SHA512Cng hashFunc = new SHA512Cng(); byte[] plainBytes = Encoding.ASCII.GetBytes(pPlainText); byte[] toBeHashed = new byte[plainBytes.Length + pSalt.Length]; plainBytes.CopyTo(toBeHashed, 0); pSalt.CopyTo(toBeHashed, plainBytes.Length); return(hashFunc.ComputeHash(toBeHashed)); }
public string getGeneratedCode(string email) { string code = string.Empty; SHA512 codedEmail = SHA512Cng.Create(); email += email + getDateOnString(); byte[] passHash = Encoding.UTF8.GetBytes(email); byte[] Encrypted = codedEmail.ComputeHash(passHash); code = getStringFromHash(Encrypted); return(code); }
public string GetPasswordHash(Guid salt, string password) { var hash = new SHA512Cng(); var concatString = password + salt; var passwordByteArray = Encoding.Default.GetBytes(concatString); hash.ComputeHash(passwordByteArray); var hashPassword = Encoding.Default.GetString(hash.Hash); return(hashPassword); }
public byte[] GetHash(byte[] sourceBuffer) { try { var sha512Cng = SHA512Cng.Create(); return(sha512Cng.ComputeHash(sourceBuffer)); } catch (Exception e) { Debug.WriteLine($"SHA512Cng service GetSHA512CngHash error: {e.Message}"); return(default(byte[])); } }
/// <summary> /// 计算文件的 sha512 值 /// </summary> /// <param name="path">要计算 MD5 值的文件名和路径</param> /// <returns>MD5 值16进制字符串</returns> public static string GetFileSHA512(string path) { if (System.IO.File.Exists(path) == false) { return(string.Empty); } FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read); SHA512 sha512 = SHA512Cng.Create(); byte[] hashByts = sha512.ComputeHash(fs); return(ConvertHashBytes(hashByts)); }
/// <summary></summary> public void Dispose() { if (_AesServices != null) { _AesServices.Clear(); _AesServices = null; } if (_MD5Services != null) { _MD5Services.Dispose(); _MD5Services = null; } if (_SHA1Services != null) { _SHA1Services.Dispose(); _SHA1Services = null; } if (_SHA256Services != null) { _SHA256Services.Dispose(); _SHA256Services = null; } if (_SHA384Services != null) { _SHA384Services.Dispose(); _SHA384Services = null; } if (_SHA512Services != null) { _SHA512Services.Dispose(); _SHA512Services = null; } if (_Pkcs11Library != null) { _Pkcs11Library.Dispose(); _Pkcs11Library = null; } if (_Randomness != null) { _Randomness.Dispose(); _Randomness = null; } if (_RsaServices != null) { _RsaServices.Clear(); _RsaServices = null; } }
private byte[] HashData <T>(T data) { byte[] hash; using (var hasAlg = new SHA512Cng()) { using (var stream = new MemoryStream()) { var formatter = new BinaryFormatter(); formatter.Serialize(stream, data); hash = hasAlg.ComputeHash(stream); } } return(hash); }
private static string ComputeArchivedFileHash(SevenZipArchiver pArchiver, ArchiveFileInfo pFile) { if (pFile.Size == 0) { return("#ZERO-LENGTH"); } byte[] hash; using (Stream stream = pArchiver.ExtractArchivedFileToStream(pFile.FileName)) { SHA512Cng sha512 = new SHA512Cng(); hash = sha512.ComputeHash(stream); } return(Utils.HexaBinString(hash)); }
/// <summary> /// hashing + salting /// </summary> /// <param name="unHashedString"></param> /// <returns></returns> public string Hash(string unHashedString) { int i = 0; StringBuilder tmpHashStr = new StringBuilder(); SHA512Cng crypto = new SHA512Cng(); byte[] bytePass = Encoding.UTF32.GetBytes(unHashedString); byte[] byteHashPass = crypto.ComputeHash(bytePass); foreach (var item in byteHashPass) { tmpHashStr.Append((item.ToString() + i.ToString())); ++i; } return(tmpHashStr.ToString()); }
private static string ComputeFileHash(string pFileName) { FileInfo info = new FileInfo(pFileName); if (info.Length == 0) { return("#ZERO-LENGTH"); } byte[] hash; using (FileStream stream = File.OpenRead(pFileName)) { SHA512Cng sha512 = new SHA512Cng(); hash = sha512.ComputeHash(stream); } return(Utils.HexaBinString(hash)); }