summary refs log tree commit diff
path: root/crypto/src/crypto/operators/CmsKeyTransRecipientInfoGenerator.cs
blob: 048014f22548b9247306434ab096ef68c8d83c06 (plain) (blame)
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
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Cms;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.X509;

namespace Org.BouncyCastle.Operators
{
    public class CmsKeyTransRecipientInfoGenerator: KeyTransRecipientInfoGenerator
    {
        private IKeyWrapper keyWrapper;

        public CmsKeyTransRecipientInfoGenerator(X509Certificate recipCert, IKeyWrapper keyWrapper): base(new Asn1.Cms.IssuerAndSerialNumber(recipCert.IssuerDN, new DerInteger(recipCert.SerialNumber)))
        {
            this.keyWrapper = keyWrapper;
        }

        public CmsKeyTransRecipientInfoGenerator(byte[] subjectKeyID, IKeyWrapper keyWrapper) : base(subjectKeyID)
        {
            this.keyWrapper = keyWrapper;
        }

        protected override AlgorithmIdentifier AlgorithmDetails
        {
            get
            {
                return (AlgorithmIdentifier)keyWrapper.AlgorithmDetails;
            }
        }

        protected override byte[] GenerateWrappedKey(Crypto.Parameters.KeyParameter contentKey)
        {
            return keyWrapper.Wrap(contentKey.GetKey()).Collect();
        }
    }
}