KeyParameter.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. namespace SharpCompress.Crypto
  3. {
  4. public class KeyParameter
  5. : ICipherParameters
  6. {
  7. private readonly byte[] key;
  8. public KeyParameter(
  9. byte[] key)
  10. {
  11. if (key == null)
  12. {
  13. throw new ArgumentNullException(nameof(key));
  14. }
  15. this.key = (byte[])key.Clone();
  16. }
  17. public KeyParameter(
  18. byte[] key,
  19. int keyOff,
  20. int keyLen)
  21. {
  22. if (key == null)
  23. {
  24. throw new ArgumentNullException(nameof(key));
  25. }
  26. if (keyOff < 0 || keyOff > key.Length)
  27. {
  28. throw new ArgumentOutOfRangeException(nameof(keyOff));
  29. }
  30. if (keyLen < 0 || (keyOff + keyLen) > key.Length)
  31. {
  32. throw new ArgumentOutOfRangeException(nameof(keyLen));
  33. }
  34. this.key = new byte[keyLen];
  35. Array.Copy(key, keyOff, this.key, 0, keyLen);
  36. }
  37. public byte[] GetKey()
  38. {
  39. return (byte[])key.Clone();
  40. }
  41. }
  42. }