DsaPublicBcpgKey.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Math;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Bcpg
  6. {
  7. /// <remarks>Base class for a DSA public key.</remarks>
  8. public class DsaPublicBcpgKey
  9. : BcpgObject, IBcpgKey
  10. {
  11. private readonly MPInteger p, q, g, y;
  12. /// <param name="bcpgIn">The stream to read the packet from.</param>
  13. public DsaPublicBcpgKey(
  14. BcpgInputStream bcpgIn)
  15. {
  16. this.p = new MPInteger(bcpgIn);
  17. this.q = new MPInteger(bcpgIn);
  18. this.g = new MPInteger(bcpgIn);
  19. this.y = new MPInteger(bcpgIn);
  20. }
  21. public DsaPublicBcpgKey(
  22. BigInteger p,
  23. BigInteger q,
  24. BigInteger g,
  25. BigInteger y)
  26. {
  27. this.p = new MPInteger(p);
  28. this.q = new MPInteger(q);
  29. this.g = new MPInteger(g);
  30. this.y = new MPInteger(y);
  31. }
  32. /// <summary>The format, as a string, always "PGP".</summary>
  33. public string Format
  34. {
  35. get { return "PGP"; }
  36. }
  37. /// <summary>Return the standard PGP encoding of the key.</summary>
  38. public override byte[] GetEncoded()
  39. {
  40. try
  41. {
  42. return base.GetEncoded();
  43. }
  44. catch (Exception)
  45. {
  46. return null;
  47. }
  48. }
  49. public override void Encode(
  50. BcpgOutputStream bcpgOut)
  51. {
  52. bcpgOut.WriteObjects(p, q, g, y);
  53. }
  54. public BigInteger G
  55. {
  56. get { return g.Value; }
  57. }
  58. public BigInteger P
  59. {
  60. get { return p.Value; }
  61. }
  62. public BigInteger Q
  63. {
  64. get { return q.Value; }
  65. }
  66. public BigInteger Y
  67. {
  68. get { return y.Value; }
  69. }
  70. }
  71. }
  72. #pragma warning restore
  73. #endif