/// <summary>
        /// 2.3.4.7 ECMA-376 Document Encryption Key Generation (Standard Encryption)
        /// </summary>
        private static byte[] GenerateEcma376SecretKey(string password, byte[] saltValue, HashIdentifier hashIdentifier, int keySize, int verifierHashSize)
        {
            byte[] hash;
            using (var hashAlgorithm = CryptoHelpers.Create(hashIdentifier))
            {
                hash = hashAlgorithm.ComputeHash(CryptoHelpers.Combine(saltValue, System.Text.Encoding.Unicode.GetBytes(password)));
                for (int i = 0; i < 50000; i++)
                {
                    hash = hashAlgorithm.ComputeHash(CryptoHelpers.Combine(BitConverter.GetBytes(i), hash));
                }

                hash = hashAlgorithm.ComputeHash(CryptoHelpers.Combine(hash, BitConverter.GetBytes(0)));

                // The algorithm in this 'DeriveKey' function is the bit that's not clear from the documentation
                hash = DeriveKey(hash, hashAlgorithm, keySize, verifierHashSize);
            }

            Array.Resize(ref hash, keySize / 8);

            return(hash);
        }
Exemple #2
0
 public override SymmetricAlgorithm CreateCipher()
 {
     return(CryptoHelpers.CreateCipher(CipherAlgorithm, KeyBits, BlockSize * 8, CipherChaining));
 }
Exemple #3
0
        public override byte[] GenerateBlockKey(int blockNumber, byte[] secretKey)
        {
            var salt = CryptoHelpers.Combine(secretKey, BitConverter.GetBytes(blockNumber));

            return(CryptoHelpers.HashBytes(salt, HashIdentifier.MD5));
        }
Exemple #4
0
 public override SymmetricAlgorithm CreateCipher()
 {
     return(CryptoHelpers.CreateCipher(CipherIdentifier.RC4, 0, 0, 0));
 }
 /// <summary>
 /// 2.3.5.2 RC4 CryptoAPI Encryption Key Generation
 /// </summary>
 private static byte[] GenerateCryptoApiSecretKey(string password, byte[] saltValue, HashIdentifier hashAlgorithm, int keySize)
 {
     return(CryptoHelpers.HashBytes(CryptoHelpers.Combine(saltValue, System.Text.Encoding.Unicode.GetBytes(password)), hashAlgorithm));
 }
 public override SymmetricAlgorithm CreateCipher()
 {
     return(CryptoHelpers.CreateCipher(CipherAlgorithm, KeySize, BlockSize, CipherMode.ECB));
 }