GOST3410KeyParameters.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. using System;
  3. using Org.BouncyCastle.Asn1;
  4. using Org.BouncyCastle.Asn1.CryptoPro;
  5. using Org.BouncyCastle.Math;
  6. namespace Org.BouncyCastle.Crypto.Parameters
  7. {
  8. public abstract class Gost3410KeyParameters
  9. : AsymmetricKeyParameter
  10. {
  11. private readonly Gost3410Parameters parameters;
  12. private readonly DerObjectIdentifier publicKeyParamSet;
  13. protected Gost3410KeyParameters(
  14. bool isPrivate,
  15. Gost3410Parameters parameters)
  16. : base(isPrivate)
  17. {
  18. this.parameters = parameters;
  19. }
  20. protected Gost3410KeyParameters(
  21. bool isPrivate,
  22. DerObjectIdentifier publicKeyParamSet)
  23. : base(isPrivate)
  24. {
  25. this.parameters = LookupParameters(publicKeyParamSet);
  26. this.publicKeyParamSet = publicKeyParamSet;
  27. }
  28. public Gost3410Parameters Parameters
  29. {
  30. get { return parameters; }
  31. }
  32. public DerObjectIdentifier PublicKeyParamSet
  33. {
  34. get { return publicKeyParamSet; }
  35. }
  36. // TODO Implement Equals/GetHashCode
  37. private static Gost3410Parameters LookupParameters(
  38. DerObjectIdentifier publicKeyParamSet)
  39. {
  40. if (publicKeyParamSet == null)
  41. throw new ArgumentNullException("publicKeyParamSet");
  42. Gost3410ParamSetParameters p = Gost3410NamedParameters.GetByOid(publicKeyParamSet);
  43. if (p == null)
  44. throw new ArgumentException("OID is not a valid CryptoPro public key parameter set", "publicKeyParamSet");
  45. return new Gost3410Parameters(p.P, p.Q, p.A);
  46. }
  47. }
  48. }
  49. #endif