public static byte[] GetStringHash(string val, byte[] salt, int length)
        {
            byte[]     secretKey = SecretKeyStorage.Instance.SecretKey;
            HMACSHA512 hmac512   = new HMACSHA512(secretKey);

            //
            // Add the data
            //

            MemoryStream ms = new MemoryStream();
            BinaryWriter bw = new BinaryWriter(ms);

            bw.Write(val);
            bw.Close();

            hmac512.TransformBlock(salt, 0, salt.Length, salt, 0);
            hmac512.TransformFinalBlock(ms.ToArray(), 0, ms.ToArray().Length);

            //
            // Return the hash
            //

            Pbkdf2 pbkdf2 = new Pbkdf2(hmac512, hmac512.Hash, secretKey);

            return(pbkdf2.GetBytes(length));
        }
        public bool Verify()
        {
            _pbkdf2 = new Pbkdf2(_hmac512, _hmac512.Hash, _hmacSalt, NumberOfRoundsForSecurEntity);
            bool result = _hmacResult.SequenceEqual(_pbkdf2.GetBytes(HashBlockLength));

            return(result);
        }
        public static byte[] GetStringColumnValueThumbprint(
            byte[] secretKey,
            string colVal,
            string extraData)
        {
            HMACSHA512 hmac512 = new HMACSHA512(secretKey);

            //
            // Add the data
            //

            MemoryStream ms = new MemoryStream();
            BinaryWriter bw = new BinaryWriter(ms);

            bw.Write(colVal);
            bw.Write(extraData);
            bw.Close();

            hmac512.TransformFinalBlock(
                ms.ToArray(),
                0,
                ms.ToArray().Length);

            //
            // Return the hash
            //

            Pbkdf2 pbkdf2 = new Pbkdf2(hmac512, hmac512.Hash, secretKey, NumberOfRoundsForSecurEntity);

            return(pbkdf2.GetBytes(HashBlockLength));
        }
        public override string ToString()
        {
            MemoryStream ms = new MemoryStream();
            BinaryWriter bw = new BinaryWriter(ms);

            bw.Write(CurrentVersion);
            bw.Write(_cipherSalt);
            bw.Write(_hmacSalt);
            bw.Write(_iv);
            _pbkdf2 = new Pbkdf2(_hmac512, _hmac512.Hash, _hmacSalt, NumberOfRoundsForSecurEntity);
            //			bw.Write(hmac512.Hash);
            bw.Write(_pbkdf2.GetBytes(HashBlockLength));
            bw.Close();

            return(Convert.ToBase64String(ms.ToArray()));
        }