EncryptedKey.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
  5. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Crmf
  6. {
  7. public class EncryptedKey
  8. : Asn1Encodable, IAsn1Choice
  9. {
  10. private readonly EnvelopedData envelopedData;
  11. private readonly EncryptedValue encryptedValue;
  12. public static EncryptedKey GetInstance(object o)
  13. {
  14. if (o is EncryptedKey)
  15. {
  16. return (EncryptedKey)o;
  17. }
  18. else if (o is Asn1TaggedObject)
  19. {
  20. return new EncryptedKey(EnvelopedData.GetInstance((Asn1TaggedObject)o, false));
  21. }
  22. else if (o is EncryptedValue)
  23. {
  24. return new EncryptedKey((EncryptedValue)o);
  25. }
  26. else
  27. {
  28. return new EncryptedKey(EncryptedValue.GetInstance(o));
  29. }
  30. }
  31. public EncryptedKey(EnvelopedData envelopedData)
  32. {
  33. this.envelopedData = envelopedData;
  34. }
  35. public EncryptedKey(EncryptedValue encryptedValue)
  36. {
  37. this.encryptedValue = encryptedValue;
  38. }
  39. public virtual bool IsEncryptedValue
  40. {
  41. get { return encryptedValue != null; }
  42. }
  43. public virtual Asn1Encodable Value
  44. {
  45. get
  46. {
  47. if (encryptedValue != null)
  48. return encryptedValue;
  49. return envelopedData;
  50. }
  51. }
  52. /**
  53. * <pre>
  54. * EncryptedKey ::= CHOICE {
  55. * encryptedValue EncryptedValue, -- deprecated
  56. * envelopedData [0] EnvelopedData }
  57. * -- The encrypted private key MUST be placed in the envelopedData
  58. * -- encryptedContentInfo encryptedContent OCTET STRING.
  59. * </pre>
  60. */
  61. public override Asn1Object ToAsn1Object()
  62. {
  63. if (encryptedValue != null)
  64. {
  65. return encryptedValue.ToAsn1Object();
  66. }
  67. return new DerTaggedObject(false, 0, envelopedData);
  68. }
  69. }
  70. }
  71. #pragma warning restore
  72. #endif