mirrored from https://www.bouncycastle.org/repositories/bc-csharp
-
Notifications
You must be signed in to change notification settings - Fork 602
Expand file tree
/
Copy pathCMSEnvelopedData.cs
More file actions
89 lines (71 loc) · 3.12 KB
/
Copy pathCMSEnvelopedData.cs
File metadata and controls
89 lines (71 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
using System;
using System.IO;
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.Cms;
using Org.BouncyCastle.Asn1.X509;
namespace Org.BouncyCastle.Cms
{
/**
* containing class for an CMS Enveloped Data object
*/
public class CmsEnvelopedData
{
private readonly ContentInfo m_contentInfo;
private readonly EnvelopedData m_envelopedData;
private readonly OriginatorInformation m_originatorInformation;
private readonly RecipientInformationStore m_recipientInfoStore;
public CmsEnvelopedData(byte[] envelopedData)
: this(CmsUtilities.ReadContentInfo(envelopedData))
{
}
public CmsEnvelopedData(Stream envelopedData)
: this(CmsUtilities.ReadContentInfo(envelopedData))
{
}
public CmsEnvelopedData(ContentInfo contentInfo)
{
m_contentInfo = contentInfo ?? throw new ArgumentNullException(nameof(contentInfo));
m_envelopedData = CmsUtilities.SafeGetContent(contentInfo, EnvelopedData.GetInstance);
var originatorInfo = m_envelopedData.OriginatorInfo;
m_originatorInformation = originatorInfo == null ? null : new OriginatorInformation(originatorInfo);
//
// read the recipients
//
Asn1Set recipientInfos = m_envelopedData.RecipientInfos;
//
// read the encrypted content info
//
var encryptedContentInfo = m_envelopedData.EncryptedContentInfo;
CmsReadable readable = CmsUtilities.ProcessEncryptedContent(encryptedContentInfo);
CmsSecureReadable secureReadable = new CmsEnvelopedHelper.CmsEnvelopedSecureReadable(
encryptedContentInfo.ContentEncryptionAlgorithm, readable);
//
// build the RecipientInformationStore
//
m_recipientInfoStore = CmsEnvelopedHelper.BuildRecipientInformationStore(recipientInfos, secureReadable);
}
public OriginatorInformation OriginatorInformation => m_originatorInformation;
public AlgorithmIdentifier EncryptionAlgorithmID =>
EnvelopedData.EncryptedContentInfo.ContentEncryptionAlgorithm;
/**
* return the object identifier for the content encryption algorithm.
*/
// TODO[api] Return the OID itself
public string EncryptionAlgOid => EncryptionAlgorithmID.Algorithm.GetID();
/**
* return a store of the intended recipients for this message
*/
public RecipientInformationStore GetRecipientInfos() => m_recipientInfoStore;
public ContentInfo ContentInfo => m_contentInfo;
public EnvelopedData EnvelopedData => m_envelopedData;
/**
* return a table of the unprotected attributes indexed by
* the OID of the attribute.
*/
public Asn1.Cms.AttributeTable GetUnprotectedAttributes() => EnvelopedData.UnprotectedAttrs?.ToAttributeTable();
/**
* return the ASN.1 encoded representation of this object.
*/
public byte[] GetEncoded() => m_contentInfo.GetEncoded();
}
}