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)); }
private static byte[] Sign(X509Certificate2 cert, ITransaction transaction) { byte[] signature; using (var hasAlg = new SHA512Cng()) { using (var stream = new MemoryStream()) { var formatter = new BinaryFormatter(); formatter.Serialize(stream, transaction); var hash = hasAlg.ComputeHash(stream); signature = cert.GetRSAPrivateKey() .SignHash(hash, HashAlgorithmName.SHA512, RSASignaturePadding.Pkcs1); } } return(signature); }
private void ProcessForCertificate(string thumbprint, string propertyName) { X509Certificate2 certificate = null; try { certificate = FederationCertificate.LoadCertificateWithPrivateKey(thumbprint, new WriteVerboseDelegate(base.WriteVerbose)); } catch (LocalizedException exception) { base.WriteError(exception, ErrorCategory.InvalidData, null); } byte[] signature = FederatedDomainProofAlgorithm.GetSignature(certificate, this.DomainName.Domain); using (HashAlgorithm hashAlgorithm = new SHA512Cng()) { byte[] inArray = hashAlgorithm.ComputeHash(signature); base.WriteObject(new FederatedDomainProof(this.DomainName, propertyName, thumbprint, Convert.ToBase64String(inArray))); } }
public byte[] Hash(SecureString password, byte[] salt) { HashAlgorithm algorithm = new SHA512Cng(); byte[] hash = new byte[password.Length + salt.Length]; byte[] passwordBytes = SecureStringToByteArray(password); for (int i = 0; i < passwordBytes.Length; ++i) { hash[i] = passwordBytes[i]; } for (int i = 0; i < salt.Length; ++i) { hash[passwordBytes.Length + 1] = salt[i]; } return(algorithm.ComputeHash(hash)); }
public void Sha512Cng() { _sha512Cng.ComputeHash(_inputBytes); }
/// <summary> /// Computes the hash value for the given string <paramref name="s"/> using the <see cref="SHA512"/> algorithm. /// </summary> /// <param name="s">The string to hash.</param> /// <returns>A byte array representing the hash value.</returns> public byte[] SHA512ComputeHash(string s) => sha.ComputeHash(Encoding.UTF8.GetBytes(s));
/// <summary> /// Generates a 512-bit hash for the given data and returns the generated results as a Base-64 string. /// </summary> /// <param name="Data">The data to be hashed. Takes a string.</param> /// <returns>Hash value formatted as a Base-64 string.</returns> public static string Compute512Base64(string Data) { return(Convert.ToBase64String(SHA512.ComputeHash(System.Text.Encoding.Default.GetBytes(Data)))); }