/// <summary>
 /// Hash email address using SHA-256 hashing algorithm.
 /// </summary>
 /// <param name="digest">Provides the algorithm for SHA-256.</param>
 /// <param name="email">The email address to hash.</param>
 /// <returns>Hash email address using SHA-256 hashing algorithm.</returns>
 private static String ToSha256String(GeneralDigest digest, String email)
 {
     byte[] data        = Encoding.UTF8.GetBytes(email);
     byte[] digestBytes = new byte[digest.GetDigestSize()];
     digest.BlockUpdate(data, 0, data.Length);
     digest.DoFinal(digestBytes, 0);
     return(BitConverter.ToString(digestBytes).Replace("-", string.Empty));
 }
Ejemplo n.º 2
0
        private static byte[] ComputeDigest(GeneralDigest digest, byte[] input)
        {
            digest.BlockUpdate(input, 0, input.Length);
            var output = new byte[digest.GetDigestSize()];

            digest.DoFinal(output, 0);
            return(output);
        }
Ejemplo n.º 3
0
        private string GetDigestValue(GeneralDigest digest)
        {
            var buffer = new byte[digest.GetDigestSize()];

            digest.DoFinal(buffer, 0);

            return(Convert.ToBase64String(buffer));
        }
Ejemplo n.º 4
0
        static public byte[] Digest(byte[] data, GeneralDigest digest)
        {
            var hashed = new byte[digest.GetDigestSize()];

            digest.BlockUpdate(data, 0, data.Length);
            digest.DoFinal(hashed, 0);
            return(hashed);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a human readable fingerprint for this certificate. This fingerprint may be
        /// compared by a user with an other certificate's fingerprint to proof their equality.
        /// </summary>
        protected static string CreateFingerprint(GeneralDigest a_digestGenerator, byte[] a_data)
        {
            var digestData = new byte[a_digestGenerator.GetDigestSize()];

            a_digestGenerator.BlockUpdate(a_data, 0, a_data.Length);
            a_digestGenerator.DoFinal(digestData, 0);
            return(string.Join(":", digestData.Select(x => x.ToString("X2"))));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Hash a string value using SHA-256 hashing algorithm.
        /// </summary>
        /// <param name="digest">Provides the algorithm for SHA-256.</param>
        /// <param name="value">The string value (e.g. an email address) to hash.</param>
        /// <returns>The hashed value.</returns>
        private static String ToSha256String(GeneralDigest digest, String value)
        {
            byte[] data        = Encoding.UTF8.GetBytes(value);
            byte[] digestBytes = new byte[digest.GetDigestSize()];
            digest.BlockUpdate(data, 0, data.Length);
            digest.DoFinal(digestBytes, 0);

            // Convert the byte array into an unhyphenated hexadecimal string.
            return(BitConverter.ToString(digestBytes).Replace("-", string.Empty));
        }
Ejemplo n.º 7
0
 private static byte[] HashIt(GeneralDigest hashAlgo, byte[] data, int offset = 0, int len = 0)
 {
     byte[] result;
     lock (hashAlgo)
     {
         hashAlgo.Reset();
         hashAlgo.BlockUpdate(data, offset, len == 0 ? data.Length - offset : len);
         result = new byte[hashAlgo.GetDigestSize()];
         hashAlgo.DoFinal(result, 0);
     }
     return(result);
 }