SymmetricCipher.cs 2.7 KB

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