예제 #1
0
        /// <summary>Calculate the counter and iv, update the decryptor.</summary>
        /// <exception cref="System.IO.IOException"/>
        private void UpdateDecryptor(Decryptor decryptor, long position, byte[] iv)
        {
            long counter = GetCounter(position);

            codec.CalculateIV(initIV, counter, iv);
            decryptor.Init(key, iv);
        }
예제 #2
0
        private void AssertIVCalculation(CryptoCodec codec, byte[] initIV, long counter,
                                         byte[] Iv)
        {
            codec.CalculateIV(initIV, counter, Iv);
            BigInteger iv   = new BigInteger(1, Iv);
            BigInteger @ref = CalculateRef(initIV, counter);

            Assert.True("Calculated IV don't match with the reference", iv.
                        Equals(@ref));
        }
예제 #3
0
        /// <summary>
        /// Update the
        /// <see cref="encryptor"/>
        /// : calculate counter and
        /// <see cref="padding"/>
        /// .
        /// </summary>
        /// <exception cref="System.IO.IOException"/>
        private void UpdateEncryptor()
        {
            long counter = streamOffset / codec.GetCipherSuite().GetAlgorithmBlockSize();

            padding = unchecked ((byte)(streamOffset % codec.GetCipherSuite().GetAlgorithmBlockSize
                                            ()));
            inBuffer.Position(padding);
            // Set proper position for input data.
            codec.CalculateIV(initIV, counter, iv);
            encryptor.Init(key, iv);
        }