RsaPublicBcpgKey.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Math;
  5. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Bcpg
  6. {
  7. /// <remarks>Base class for an RSA public key.</remarks>
  8. public class RsaPublicBcpgKey
  9. : BcpgObject, IBcpgKey
  10. {
  11. private readonly MPInteger n, e;
  12. /// <summary>Construct an RSA public key from the passed in stream.</summary>
  13. public RsaPublicBcpgKey(
  14. BcpgInputStream bcpgIn)
  15. {
  16. this.n = new MPInteger(bcpgIn);
  17. this.e = new MPInteger(bcpgIn);
  18. }
  19. /// <param name="n">The modulus.</param>
  20. /// <param name="e">The public exponent.</param>
  21. public RsaPublicBcpgKey(
  22. BigInteger n,
  23. BigInteger e)
  24. {
  25. this.n = new MPInteger(n);
  26. this.e = new MPInteger(e);
  27. }
  28. public BigInteger PublicExponent
  29. {
  30. get { return e.Value; }
  31. }
  32. public BigInteger Modulus
  33. {
  34. get { return n.Value; }
  35. }
  36. /// <summary>The format, as a string, always "PGP".</summary>
  37. public string Format
  38. {
  39. get { return "PGP"; }
  40. }
  41. /// <summary>Return the standard PGP encoding of the key.</summary>
  42. public override byte[] GetEncoded()
  43. {
  44. try
  45. {
  46. return base.GetEncoded();
  47. }
  48. catch (Exception)
  49. {
  50. return null;
  51. }
  52. }
  53. public override void Encode(
  54. BcpgOutputStream bcpgOut)
  55. {
  56. bcpgOut.WriteObjects(n, e);
  57. }
  58. }
  59. }
  60. #pragma warning restore
  61. #endif