CMSEnvelopedData.cs 3.1 KB

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