Esempio n. 1
0
            /// <summary>
            /// Calculate a unique hash for a non-null series of bytes (Uses SHA256 by default)
            /// </summary>
            /// <param name="bytesToHash">Non-null list of bytes upon which to calculate hash</param>
            /// <param name="hashSalt">(optional) Additional text that you want to use to add addtional 'secrecy' to your hash.  If provided uses HMAC256 instead of SHA256</param>
            /// <returns>Base64 encoded string of hash.  The value is suitable for storing in databases but might need to be HtmlEncoded if used in query strings or displayed on web pages</returns>
            public static byte[] Hash(byte[] bytesToHash, byte[] hashSalt = null)
            {
                if (hashSalt == null)
                {
                    var simpleKey = HashKeySimple.Create(_defaultSimpleHashMode);
                    return(simpleKey.Hash(bytesToHash));
                }

                var keyedHasher = HashKeySalted.Create(_defaultSaltedHashMode, hashSalt);

                return(keyedHasher.Hash(bytesToHash));
            }
Esempio n. 2
0
        /// <summary>
        /// Create a key using a specific Crypto.HashModesKeyed and specific salt.
        /// </summary>
        /// <param name="hashMode">One of the Crypto.HashModesKeyed constants</param>
        /// <param name="salt">Non-null salt value to use in hashing operations</param>
        /// <returns>Newly created key</returns>
        public static HashKeySalted Create(string hashMode, byte[] salt)
        {
            var key = new HashKeySalted();

            key.Properties.Add(new KeyProperty()
            {
                PropertyType = Crypto.PropertyTypes.HashSaltedMode,
                Value        = hashMode,
                ValueType    = Crypto.PropertyValueTypes.String
            });
            key.Segments.Add(Crypto.SegmentTypes.HashSalt, salt);
            return(key);
        }
Esempio n. 3
0
        /// <summary>
        /// Create a key using a specific Crypto.HashModesKeyed and specific salt.
        /// </summary>
        /// <param name="hashMode">One of the Crypto.HashModesKeyed constants</param>
        /// <param name="salt">Non-null salt value to use in hashing operations</param>
        /// <returns>Newly created key</returns>
        public static HashKeySalted Create(string hashMode, byte[] salt)
        {
            var key = new HashKeySalted();
            key.Properties.Add(new KeyProperty()
            {
				PropertyType = Crypto.PropertyNames.HashSaltedMode,
                Value = hashMode,
                ValueType = Crypto.PropertyValueTypes.String
            });
			key.Segments.Add(Crypto.SegmentNames.HashSalt, salt);
            return key;
        }