ElGamalPublicBcpgKey.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 an ElGamal public key.</remarks>
  8. public class ElGamalPublicBcpgKey
  9. : BcpgObject, IBcpgKey
  10. {
  11. internal MPInteger p, g, y;
  12. public ElGamalPublicBcpgKey(
  13. BcpgInputStream bcpgIn)
  14. {
  15. this.p = new MPInteger(bcpgIn);
  16. this.g = new MPInteger(bcpgIn);
  17. this.y = new MPInteger(bcpgIn);
  18. }
  19. public ElGamalPublicBcpgKey(
  20. BigInteger p,
  21. BigInteger g,
  22. BigInteger y)
  23. {
  24. this.p = new MPInteger(p);
  25. this.g = new MPInteger(g);
  26. this.y = new MPInteger(y);
  27. }
  28. /// <summary>The format, as a string, always "PGP".</summary>
  29. public string Format
  30. {
  31. get { return "PGP"; }
  32. }
  33. /// <summary>Return the standard PGP encoding of the key.</summary>
  34. public override byte[] GetEncoded()
  35. {
  36. try
  37. {
  38. return base.GetEncoded();
  39. }
  40. catch (Exception)
  41. {
  42. return null;
  43. }
  44. }
  45. public BigInteger P
  46. {
  47. get { return p.Value; }
  48. }
  49. public BigInteger G
  50. {
  51. get { return g.Value; }
  52. }
  53. public BigInteger Y
  54. {
  55. get { return y.Value; }
  56. }
  57. public override void Encode(
  58. BcpgOutputStream bcpgOut)
  59. {
  60. bcpgOut.WriteObjects(p, g, y);
  61. }
  62. }
  63. }
  64. #pragma warning restore
  65. #endif