RsaKeyParameters.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. using System;
  3. using Org.BouncyCastle.Crypto;
  4. using Org.BouncyCastle.Math;
  5. namespace Org.BouncyCastle.Crypto.Parameters
  6. {
  7. public class RsaKeyParameters
  8. : AsymmetricKeyParameter
  9. {
  10. private readonly BigInteger modulus;
  11. private readonly BigInteger exponent;
  12. public RsaKeyParameters(
  13. bool isPrivate,
  14. BigInteger modulus,
  15. BigInteger exponent)
  16. : base(isPrivate)
  17. {
  18. if (modulus == null)
  19. throw new ArgumentNullException("modulus");
  20. if (exponent == null)
  21. throw new ArgumentNullException("exponent");
  22. if (modulus.SignValue <= 0)
  23. throw new ArgumentException("Not a valid RSA modulus", "modulus");
  24. if (exponent.SignValue <= 0)
  25. throw new ArgumentException("Not a valid RSA exponent", "exponent");
  26. this.modulus = modulus;
  27. this.exponent = exponent;
  28. }
  29. public BigInteger Modulus
  30. {
  31. get { return modulus; }
  32. }
  33. public BigInteger Exponent
  34. {
  35. get { return exponent; }
  36. }
  37. public override bool Equals(
  38. object obj)
  39. {
  40. RsaKeyParameters kp = obj as RsaKeyParameters;
  41. if (kp == null)
  42. {
  43. return false;
  44. }
  45. return kp.IsPrivate == this.IsPrivate
  46. && kp.Modulus.Equals(this.modulus)
  47. && kp.Exponent.Equals(this.exponent);
  48. }
  49. public override int GetHashCode()
  50. {
  51. return modulus.GetHashCode() ^ exponent.GetHashCode() ^ IsPrivate.GetHashCode();
  52. }
  53. }
  54. }
  55. #endif