ECPrivateKeyParameters.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Globalization;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1;
  6. using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
  7. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
  8. {
  9. public class ECPrivateKeyParameters
  10. : ECKeyParameters
  11. {
  12. private readonly BigInteger d;
  13. public ECPrivateKeyParameters(
  14. BigInteger d,
  15. ECDomainParameters parameters)
  16. : this("EC", d, parameters)
  17. {
  18. }
  19. public ECPrivateKeyParameters(
  20. BigInteger d,
  21. DerObjectIdentifier publicKeyParamSet)
  22. : base("ECGOST3410", true, publicKeyParamSet)
  23. {
  24. this.d = Parameters.ValidatePrivateScalar(d);
  25. }
  26. public ECPrivateKeyParameters(
  27. string algorithm,
  28. BigInteger d,
  29. ECDomainParameters parameters)
  30. : base(algorithm, true, parameters)
  31. {
  32. this.d = Parameters.ValidatePrivateScalar(d);
  33. }
  34. public ECPrivateKeyParameters(
  35. string algorithm,
  36. BigInteger d,
  37. DerObjectIdentifier publicKeyParamSet)
  38. : base(algorithm, true, publicKeyParamSet)
  39. {
  40. this.d = Parameters.ValidatePrivateScalar(d);
  41. }
  42. public BigInteger D
  43. {
  44. get { return d; }
  45. }
  46. public override bool Equals(
  47. object obj)
  48. {
  49. if (obj == this)
  50. return true;
  51. ECPrivateKeyParameters other = obj as ECPrivateKeyParameters;
  52. if (other == null)
  53. return false;
  54. return Equals(other);
  55. }
  56. protected bool Equals(
  57. ECPrivateKeyParameters other)
  58. {
  59. return d.Equals(other.d) && base.Equals(other);
  60. }
  61. public override int GetHashCode()
  62. {
  63. return d.GetHashCode() ^ base.GetHashCode();
  64. }
  65. }
  66. }
  67. #pragma warning restore
  68. #endif