GOST3410KeyParameters.cs 1.6 KB

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