SymmetricCipher.cs 2.6 KB

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