Exemple #1
0
 /// <summary>
 /// Decrypts the specified data.
 /// </summary>
 /// <param name="data">The data.</param>
 /// <param name="key">The key.</param>
 /// <param name="salt">The salt.</param>
 /// <param name="hashingAlgorithm">The hashing algorithm.</param>
 /// <param name="passwordIterations">The password iterations.</param>
 /// <param name="initialVector">The initial vector. 16 ASCII characters long.</param>
 /// <param name="keySize">
 /// Size of the key. Can be 64 (DES only), 128 (AES), 192 (AES and Triple DES), or 256 (AES)
 /// </param>
 /// <returns>The decrypted data.</returns>
 public byte[] Decrypt(byte[] data, byte[] key, byte[] salt, HashingAlgorithms hashingAlgorithm, int passwordIterations, byte[] initialVector, int keySize)
 {
     if (data == null || key == null || salt == null || initialVector == null)
     {
         return(Array.Empty <byte>());
     }
     using PasswordDeriveBytes TempKey = new PasswordDeriveBytes(key, salt, hashingAlgorithm.ToString(), passwordIterations);
     return(Decrypt(data, TempKey, initialVector, keySize));
 }
Exemple #2
0
        /// <summary>
        /// Hashes the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <param name="algorithm">The algorithm to use.</param>
        /// <returns>The hash of the data.</returns>
        public byte[] Hash(byte[] data, HashingAlgorithms algorithm)
        {
            var HashingAlgorithm = Hashes.FirstOrDefault(x => string.Equals(x.Name, algorithm.ToString(), StringComparison.OrdinalIgnoreCase));

            if (HashingAlgorithm == null)
            {
                return(Array.Empty <byte>());
            }
            return(HashingAlgorithm.Hash(data));
        }