| | | 1 | | using System; |
| | | 2 | | |
| | | 3 | | namespace Renci.SshNet.Security.Cryptography |
| | | 4 | | { |
| | | 5 | | /// <summary> |
| | | 6 | | /// Base class for symmetric cipher implementations. |
| | | 7 | | /// </summary> |
| | | 8 | | public abstract class SymmetricCipher : Cipher |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Gets the key. |
| | | 12 | | /// </summary> |
| | 5728 | 13 | | protected byte[] Key { get; private set; } |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Initializes a new instance of the <see cref="SymmetricCipher"/> class. |
| | | 17 | | /// </summary> |
| | | 18 | | /// <param name="key">The key.</param> |
| | | 19 | | /// <exception cref="ArgumentNullException"><paramref name="key"/> is <see langword="null"/>.</exception> |
| | 5535 | 20 | | protected SymmetricCipher(byte[] key) |
| | 5535 | 21 | | { |
| | 5535 | 22 | | if (key is null) |
| | 0 | 23 | | { |
| | 0 | 24 | | throw new ArgumentNullException(nameof(key)); |
| | | 25 | | } |
| | | 26 | | |
| | 5535 | 27 | | Key = key; |
| | 5535 | 28 | | } |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Encrypts the specified region of the input byte array and copies the encrypted data to the specified region |
| | | 32 | | /// </summary> |
| | | 33 | | /// <param name="inputBuffer">The input data to encrypt.</param> |
| | | 34 | | /// <param name="inputOffset">The offset into the input byte array from which to begin using data.</param> |
| | | 35 | | /// <param name="inputCount">The number of bytes in the input byte array to use as data.</param> |
| | | 36 | | /// <param name="outputBuffer">The output to which to write encrypted data.</param> |
| | | 37 | | /// <param name="outputOffset">The offset into the output byte array from which to begin writing data.</param> |
| | | 38 | | /// <returns> |
| | | 39 | | /// The number of bytes encrypted. |
| | | 40 | | /// </returns> |
| | | 41 | | public abstract int EncryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int o |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// Decrypts the specified region of the input byte array and copies the decrypted data to the specified region |
| | | 45 | | /// </summary> |
| | | 46 | | /// <param name="inputBuffer">The input data to decrypt.</param> |
| | | 47 | | /// <param name="inputOffset">The offset into the input byte array from which to begin using data.</param> |
| | | 48 | | /// <param name="inputCount">The number of bytes in the input byte array to use as data.</param> |
| | | 49 | | /// <param name="outputBuffer">The output to which to write decrypted data.</param> |
| | | 50 | | /// <param name="outputOffset">The offset into the output byte array from which to begin writing data.</param> |
| | | 51 | | /// <returns> |
| | | 52 | | /// The number of bytes decrypted. |
| | | 53 | | /// </returns> |
| | | 54 | | public abstract int DecryptBlock(byte[] inputBuffer, int inputOffset, int inputCount, byte[] outputBuffer, int o |
| | | 55 | | } |
| | | 56 | | } |