Esempio n. 1
0
        protected override void EncryptRecord(DisposeContext d, IBufferOffsetSize input)
        {
            ICryptoTransform cipher;

            if (!Cipher.HasFixedIV)
            {
                EncryptionAlgorithm.GenerateIV();
                cipher = d.Add(EncryptionAlgorithm.CreateEncryptor());
            }
            else
            {
                cipher = encryptionCipher;
            }

            if (!Cipher.HasFixedIV)
            {
                Buffer.BlockCopy(EncryptionAlgorithm.IV, 0, input.Buffer, input.Offset, BlockSize);
            }

            var ret = cipher.TransformBlock(input.Buffer, input.Offset + HeaderSize, input.Size - HeaderSize, input.Buffer, input.Offset + HeaderSize);

            if (ret <= 0 || ret != input.Size - HeaderSize)
            {
                throw new InvalidOperationException();
            }

            if (Cipher.HasFixedIV)
            {
                var IV = new byte [BlockSize];
                Buffer.BlockCopy(input.Buffer, input.Offset + input.Size - BlockSize, IV, 0, BlockSize);
                EncryptionAlgorithm.IV = IV;
            }
        }
Esempio n. 2
0
        protected override void EncryptRecord(DisposeContext d, IBufferOffsetSize buffer)
        {
            ICryptoTransform cipher;

            if (!Cipher.HasFixedIV)
            {
                EncryptionAlgorithm.GenerateIV();
                cipher = d.Add(EncryptionAlgorithm.CreateEncryptor());
            }
            else
            {
                cipher = encryptionCipher;
            }

            if (!Cipher.HasFixedIV)
            {
                Buffer.BlockCopy(EncryptionAlgorithm.IV, 0, buffer.Buffer, buffer.Offset, BlockSize);
            }

            cipher.TransformBlock(buffer.Buffer, buffer.Offset + HeaderSize, buffer.Size - HeaderSize, buffer.Buffer, buffer.Offset + HeaderSize);
        }