GOST3410KeyGenerationParameters.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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.Security;
  7. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Parameters
  8. {
  9. public class Gost3410KeyGenerationParameters
  10. : KeyGenerationParameters
  11. {
  12. private readonly Gost3410Parameters parameters;
  13. private readonly DerObjectIdentifier publicKeyParamSet;
  14. public Gost3410KeyGenerationParameters(
  15. SecureRandom random,
  16. Gost3410Parameters parameters)
  17. : base(random, parameters.P.BitLength - 1)
  18. {
  19. this.parameters = parameters;
  20. }
  21. public Gost3410KeyGenerationParameters(
  22. SecureRandom random,
  23. DerObjectIdentifier publicKeyParamSet)
  24. : this(random, LookupParameters(publicKeyParamSet))
  25. {
  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. private static Gost3410Parameters LookupParameters(
  37. DerObjectIdentifier publicKeyParamSet)
  38. {
  39. if (publicKeyParamSet == null)
  40. throw new ArgumentNullException("publicKeyParamSet");
  41. Gost3410ParamSetParameters p = Gost3410NamedParameters.GetByOid(publicKeyParamSet);
  42. if (p == null)
  43. throw new ArgumentException("OID is not a valid CryptoPro public key parameter set", "publicKeyParamSet");
  44. return new Gost3410Parameters(p.P, p.Q, p.A);
  45. }
  46. }
  47. }
  48. #pragma warning restore
  49. #endif