ParametersWithSalt.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities;
  6. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
  7. {
  8. /// <summary> Cipher parameters with a fixed salt value associated with them.</summary>
  9. public class ParametersWithSalt
  10. : ICipherParameters
  11. {
  12. private readonly ICipherParameters m_parameters;
  13. private readonly byte[] m_salt;
  14. public ParametersWithSalt(ICipherParameters parameters, byte[] salt)
  15. : this(parameters, salt, 0, salt.Length)
  16. {
  17. }
  18. public ParametersWithSalt(ICipherParameters parameters, byte[] salt, int saltOff, int saltLen)
  19. {
  20. m_parameters = parameters;
  21. m_salt = Arrays.CopyOfRange(salt, saltOff, saltOff + saltLen);
  22. }
  23. #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER || UNITY_2021_2_OR_NEWER
  24. public ParametersWithSalt(ICipherParameters parameters, ReadOnlySpan<byte> salt)
  25. {
  26. m_parameters = parameters;
  27. m_salt = salt.ToArray();
  28. }
  29. #endif
  30. public byte[] GetSalt()
  31. {
  32. return m_salt;
  33. }
  34. public ICipherParameters Parameters => m_parameters;
  35. }
  36. }
  37. #pragma warning restore
  38. #endif