summary refs log tree commit diff
path: root/crypto/src/cms/EnvelopedDataHelper.cs
blob: 9dcfe033bd62256ecda8c9663ec53089b94c768a (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
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
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Crypto.Utilities;
using Org.BouncyCastle.Security;

namespace Org.BouncyCastle.Cms
{
    internal class EnvelopedDataHelper
    {
        //private static readonly IDictionary<DerObjectIdentifier, string> BaseCipherNames =
        //    new Dictionary<DerObjectIdentifier, string>();
        //private static readonly IDictionary<DerObjectIdentifier, string> MacAlgNames =
        //    new Dictionary<DerObjectIdentifier, string>();
        //private static readonly IDictionary<DerObjectIdentifier, string> PrfDigests =
        //    new Dictionary<DerObjectIdentifier, string>();

        //static EnvelopedDataHelper()
        //{
        //    PrfDigests.Add(PkcsObjectIdentifiers.IdHmacWithSha1, "SHA-1");
        //    PrfDigests.Add(PkcsObjectIdentifiers.IdHmacWithSha224, "SHA-224");
        //    PrfDigests.Add(PkcsObjectIdentifiers.IdHmacWithSha256, "SHA-256");
        //    PrfDigests.Add(PkcsObjectIdentifiers.IdHmacWithSha384, "SHA-384");
        //    PrfDigests.Add(PkcsObjectIdentifiers.IdHmacWithSha512, "SHA-512");

        //    BaseCipherNames.Add(PkcsObjectIdentifiers.DesEde3Cbc, "DESEDE");
        //    BaseCipherNames.Add(NistObjectIdentifiers.IdAes128Cbc, "AES");
        //    BaseCipherNames.Add(NistObjectIdentifiers.IdAes192Cbc, "AES");
        //    BaseCipherNames.Add(NistObjectIdentifiers.IdAes256Cbc, "AES");

        //    MacAlgNames.Add(PkcsObjectIdentifiers.DesEde3Cbc, "DESEDEMac");
        //    MacAlgNames.Add(NistObjectIdentifiers.IdAes128Cbc, "AESMac");
        //    MacAlgNames.Add(NistObjectIdentifiers.IdAes192Cbc, "AESMac");
        //    MacAlgNames.Add(NistObjectIdentifiers.IdAes256Cbc, "AESMac");
        //    MacAlgNames.Add(PkcsObjectIdentifiers.RC2Cbc, "RC2Mac");
        //}

        //internal static IDigest GetPrf(AlgorithmIdentifier algID)
        //{
        //    string digestName = (string)PrfDigests[algID];

        //    return DigestUtilities.GetDigest(digestName);
        //}

        //internal static IWrapper CreateRfc3211Wrapper(DerObjectIdentifier algorithm)
        //{
        //    if (NistObjectIdentifiers.IdAes128Cbc.Equals(algorithm)
        //        || NistObjectIdentifiers.IdAes192Cbc.Equals(algorithm)
        //        || NistObjectIdentifiers.IdAes256Cbc.Equals(algorithm))
        //    {
        //        return new Rfc3211WrapEngine(AesUtilities.CreateEngine());
        //    }
        //    else if (PkcsObjectIdentifiers.DesEde3Cbc.Equals(algorithm))
        //    {
        //        return new Rfc3211WrapEngine(new DesEdeEngine());
        //    }
        //    else if (OiwObjectIdentifiers.DesCbc.Equals(algorithm))
        //    {
        //        return new Rfc3211WrapEngine(new DesEngine());
        //    }
        //    else if (PkcsObjectIdentifiers.RC2Cbc.Equals(algorithm))
        //    {
        //        return new Rfc3211WrapEngine(new RC2Engine());
        //    }
        //    else
        //    {
        //        throw new CmsException("cannot recognise wrapper: " + algorithm);
        //    }
        //}

        public static object CreateContentCipher(bool forEncryption, ICipherParameters encKey,
             AlgorithmIdentifier encryptionAlgID)
        {
            return CipherFactory.CreateContentCipher(forEncryption, encKey, encryptionAlgID);
        }

        public AlgorithmIdentifier GenerateEncryptionAlgID(DerObjectIdentifier encryptionOID, KeyParameter encKey,
            SecureRandom random)
        {
            return AlgorithmIdentifierFactory.GenerateEncryptionAlgID(encryptionOID, encKey.KeyLength * 8, random);
        }

        public CipherKeyGenerator CreateKeyGenerator(DerObjectIdentifier algorithm, SecureRandom random)
        {
            return CipherKeyGeneratorFactory.CreateKeyGenerator(algorithm, random);
        }
    }
}