KeyParameter.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto;
  5. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
  6. {
  7. public class KeyParameter
  8. : ICipherParameters
  9. {
  10. private readonly byte[] m_key;
  11. public KeyParameter(byte[] key)
  12. {
  13. if (key == null)
  14. throw new ArgumentNullException(nameof(key));
  15. m_key = (byte[])key.Clone();
  16. }
  17. public KeyParameter(byte[] key, int keyOff, int keyLen)
  18. {
  19. if (key == null)
  20. throw new ArgumentNullException(nameof(key));
  21. if (keyOff < 0 || keyOff > key.Length)
  22. throw new ArgumentOutOfRangeException(nameof(keyOff));
  23. if (keyLen < 0 || keyLen > (key.Length - keyOff))
  24. throw new ArgumentOutOfRangeException(nameof(keyLen));
  25. m_key = new byte[keyLen];
  26. Array.Copy(key, keyOff, m_key, 0, keyLen);
  27. }
  28. #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
  29. public KeyParameter(ReadOnlySpan<byte> key)
  30. {
  31. m_key = key.ToArray();
  32. }
  33. #endif
  34. public byte[] GetKey()
  35. {
  36. return (byte[])m_key.Clone();
  37. }
  38. }
  39. }
  40. #pragma warning restore
  41. #endif