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 pathRecipientInformation.cs
More file actions
92 lines (77 loc) · 2.87 KB
/
Copy pathRecipientInformation.cs
File metadata and controls
92 lines (77 loc) · 2.87 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
90
91
92
using System;
using System.IO;
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Security;
using Org.BouncyCastle.Utilities;
namespace Org.BouncyCastle.Cms
{
public abstract class RecipientInformation
{
internal RecipientID rid = new RecipientID();
internal AlgorithmIdentifier keyEncAlg;
internal CmsSecureReadable secureReadable;
private byte[] resultMac;
internal RecipientInformation(AlgorithmIdentifier keyEncAlg, CmsSecureReadable secureReadable)
{
this.keyEncAlg = keyEncAlg;
this.secureReadable = secureReadable;
}
internal string GetContentAlgorithmName()
{
AlgorithmIdentifier algorithm = secureReadable.Algorithm;
//return CmsEnvelopedHelper.Instance.GetSymmetricCipherName(algorithm.Algorithm.Id);
return algorithm.Algorithm.Id;
}
public RecipientID RecipientID => rid;
public AlgorithmIdentifier KeyEncryptionAlgorithmID => keyEncAlg;
/// <summary>Return the object identifier for the key encryption algorithm.</summary>
public string KeyEncryptionAlgOid => keyEncAlg.Algorithm.GetID();
/// <summary>
/// Return the ASN.1 encoded key encryption algorithm parameters, or null if there aren't any.
/// </summary>
public Asn1Object KeyEncryptionAlgParams => keyEncAlg.Parameters?.ToAsn1Object();
internal CmsTypedStream GetContentFromSessionKey(KeyParameter sKey)
{
CmsReadable readable = secureReadable.GetReadable(sKey);
try
{
return new CmsTypedStream(readable.GetInputStream());
}
catch (IOException e)
{
throw new CmsException("error getting .", e);
}
}
public byte[] GetContent(ICipherParameters key)
{
try
{
return CmsUtilities.StreamToByteArray(GetContentStream(key).ContentStream);
}
catch (IOException e)
{
throw new Exception("unable to parse internal stream: " + e);
}
}
/// <summary>
/// Return the MAC calculated for the content stream. Note: this call is only meaningful once all the content
/// has been read.
/// </summary>
public byte[] GetMac()
{
if (resultMac == null)
{
object cryptoObject = secureReadable.CryptoObject;
if (cryptoObject is IMac mac)
{
resultMac = MacUtilities.DoFinal(mac);
}
}
return Arrays.Clone(resultMac);
}
public abstract CmsTypedStream GetContentStream(ICipherParameters key);
}
}