using System.Linq; namespace Renci.SshNet.Security.Cryptography.Ciphers { /// /// Base class for cipher mode implementations /// public abstract class CipherMode { /// /// Gets the cipher. /// protected BlockCipher Cipher; /// /// Gets the IV vector. /// protected byte[] IV; /// /// Holds block size of the cipher. /// protected int _blockSize; /// /// Initializes a new instance of the class. /// /// The iv. protected CipherMode(byte[] iv) { IV = iv; } /// /// Initializes the specified cipher mode. /// /// The cipher. internal void Init(BlockCipher cipher) { Cipher = cipher; _blockSize = cipher.BlockSize; IV = IV.Take(_blockSize).ToArray(); } /// /// Encrypts the specified region of the input byte array and copies the encrypted data to the specified region of the output byte array. /// /// The input data to encrypt. /// The offset into the input byte array from which to begin using data. /// The number of bytes in the input byte array to use as data. /// The output to which to write encrypted data. /// The offset into the output byte array from which to begin writing data. /// /// The number of bytes encrypted. /// public abstract int EncryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset); /// /// Decrypts the specified region of the input byte array and copies the decrypted data to the specified region of the output byte array. /// /// The input data to decrypt. /// The offset into the input byte array from which to begin using data. /// The number of bytes in the input byte array to use as data. /// The output to which to write decrypted data. /// The offset into the output byte array from which to begin writing data. /// /// The number of bytes decrypted. /// public abstract int DecryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int outputOffset); } }