Exemple #1
0
        /// <summary>
        /// Instantiate a transformation
        /// </summary>
        /// <param name="key">The key</param>
        /// <param name="iv">Initial Vector, or null for a zero vector.</param>
        public V1AesCrypto(ICryptoFactory factory, SymmetricKey key, SymmetricIV iv)
        {
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (key.Size != 128)
            {
                throw new ArgumentException("Key length is invalid.");
            }
            using (SymmetricAlgorithm algorithm = CreateRawAlgorithm())
            {
                iv = iv ?? new SymmetricIV(new byte[algorithm.BlockSize / 8]);
                if (iv.Length != algorithm.BlockSize / 8)
                {
                    throw new ArgumentException("The IV length must be the same as the algorithm block length.");
                }
            }

            Key = key;
            _iv = iv;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="V2CryptoBase" /> class.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="iv">The iv, or null for none.</param>
        /// <param name="keyStreamOffset">The key stream offset.</param>
        /// <exception cref="System.ArgumentNullException">factory
        /// or
        /// key
        /// or
        /// iv</exception>
        /// <exception cref="System.ArgumentException">Key length is invalid.
        /// or
        /// The IV length must be the same as the algorithm block length.</exception>
        protected void Initialize(SymmetricKey key, SymmetricIV iv, long keyStreamOffset, SymmetricAlgorithm algorithm)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }
            if (algorithm == null)
            {
                throw new ArgumentNullException("algorithm");
            }

            if (!algorithm.ValidKeySize(key.Size))
            {
                throw new ArgumentException("Key length is invalid.");
            }
            iv = iv ?? new SymmetricIV(new byte[algorithm.BlockSize / 8]);
            if (iv.Length != algorithm.BlockSize / 8)
            {
                throw new ArgumentException("The IV length must be the same as the algorithm block length.");
            }

            Key           = key;
            _iv           = iv;
            _blockCounter = keyStreamOffset / iv.Length;
            _blockOffset  = (int)(keyStreamOffset % iv.Length);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="V2AesCrypto"/> class.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="key">The key.</param>
 /// <param name="iv">The iv, or null for none.</param>
 /// <param name="keyStreamOffset">The key stream offset.</param>
 public V2AesCrypto(SymmetricKey key, SymmetricIV iv, long keyStreamOffset)
 {
     using (SymmetricAlgorithm algorithm = CreateAlgorithmInternal())
     {
         Initialize(key, iv, keyStreamOffset, algorithm);
     }
 }
        public byte[] Add(SymmetricIV right)
        {
            if (right == null)
            {
                throw new ArgumentNullException("right");
            }

            byte[] leftBytes  = GetBytes();
            byte[] rightBytes = right.GetBytes();
            byte[] result     = new byte[leftBytes.Length + rightBytes.Length];

            leftBytes.CopyTo(result, 0);
            rightBytes.CopyTo(result, leftBytes.Length);

            return(result);
        }
Exemple #5
0
 public ICrypto CreateCrypto(SymmetricKey key, SymmetricIV iv, long keyStreamOffset)
 {
     return(new V2AesCrypto(key, iv, keyStreamOffset));
 }