CMSEnvelopedData.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.IO;
  5. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1;
  6. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
  7. using Best.HTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
  8. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Cms
  9. {
  10. /**
  11. * containing class for an CMS Enveloped Data object
  12. */
  13. public class CmsEnvelopedData
  14. {
  15. internal RecipientInformationStore recipientInfoStore;
  16. internal ContentInfo contentInfo;
  17. private AlgorithmIdentifier encAlg;
  18. private Asn1Set unprotectedAttributes;
  19. public CmsEnvelopedData(
  20. byte[] envelopedData)
  21. : this(CmsUtilities.ReadContentInfo(envelopedData))
  22. {
  23. }
  24. public CmsEnvelopedData(
  25. Stream envelopedData)
  26. : this(CmsUtilities.ReadContentInfo(envelopedData))
  27. {
  28. }
  29. public CmsEnvelopedData(
  30. ContentInfo contentInfo)
  31. {
  32. this.contentInfo = contentInfo;
  33. EnvelopedData envData = EnvelopedData.GetInstance(contentInfo.Content);
  34. //
  35. // read the recipients
  36. //
  37. Asn1Set recipientInfos = envData.RecipientInfos;
  38. //
  39. // read the encrypted content info
  40. //
  41. EncryptedContentInfo encInfo = envData.EncryptedContentInfo;
  42. this.encAlg = encInfo.ContentEncryptionAlgorithm;
  43. CmsReadable readable = new CmsProcessableByteArray(encInfo.EncryptedContent.GetOctets());
  44. CmsSecureReadable secureReadable = new CmsEnvelopedHelper.CmsEnvelopedSecureReadable(
  45. this.encAlg, readable);
  46. //
  47. // build the RecipientInformationStore
  48. //
  49. this.recipientInfoStore = CmsEnvelopedHelper.BuildRecipientInformationStore(
  50. recipientInfos, secureReadable);
  51. this.unprotectedAttributes = envData.UnprotectedAttrs;
  52. }
  53. public AlgorithmIdentifier EncryptionAlgorithmID
  54. {
  55. get { return encAlg; }
  56. }
  57. /**
  58. * return the object identifier for the content encryption algorithm.
  59. */
  60. public string EncryptionAlgOid
  61. {
  62. get { return encAlg.Algorithm.Id; }
  63. }
  64. /**
  65. * return a store of the intended recipients for this message
  66. */
  67. public RecipientInformationStore GetRecipientInfos()
  68. {
  69. return recipientInfoStore;
  70. }
  71. /**
  72. * return the ContentInfo
  73. */
  74. public ContentInfo ContentInfo
  75. {
  76. get { return contentInfo; }
  77. }
  78. /**
  79. * return a table of the unprotected attributes indexed by
  80. * the OID of the attribute.
  81. */
  82. public Asn1.Cms.AttributeTable GetUnprotectedAttributes()
  83. {
  84. if (unprotectedAttributes == null)
  85. return null;
  86. return new Asn1.Cms.AttributeTable(unprotectedAttributes);
  87. }
  88. /**
  89. * return the ASN.1 encoded representation of this object.
  90. */
  91. public byte[] GetEncoded()
  92. {
  93. return contentInfo.GetEncoded();
  94. }
  95. }
  96. }
  97. #pragma warning restore
  98. #endif