diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2019-01-31 19:26:09 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2019-01-31 19:26:09 +0700 |
commit | 65b588a45feb07f27716288ff15f784b5bf73812 (patch) | |
tree | 41d4d9e5d939e32008460cee18d6fc3dd6857ce0 /crypto/src/cms/EnvelopedDataHelper.cs | |
parent | removed unnecessary extra ECGOST3410 class (diff) | |
download | BouncyCastle.NET-ed25519-65b588a45feb07f27716288ff15f784b5bf73812.tar.xz |
Fixes and tidying up for release
Diffstat (limited to 'crypto/src/cms/EnvelopedDataHelper.cs')
-rw-r--r-- | crypto/src/cms/EnvelopedDataHelper.cs | 118 |
1 files changed, 45 insertions, 73 deletions
diff --git a/crypto/src/cms/EnvelopedDataHelper.cs b/crypto/src/cms/EnvelopedDataHelper.cs index fe5bc2a97..6d1c7bb3a 100644 --- a/crypto/src/cms/EnvelopedDataHelper.cs +++ b/crypto/src/cms/EnvelopedDataHelper.cs @@ -1,4 +1,6 @@ -using System.Collections; +using System; +using System.Collections; + using Org.BouncyCastle.Asn1; using Org.BouncyCastle.Asn1.Nist; using Org.BouncyCastle.Asn1.Oiw; @@ -12,7 +14,6 @@ using Org.BouncyCastle.Crypto.Parameters; using Org.BouncyCastle.Crypto.Utilities; using Org.BouncyCastle.Security; using Org.BouncyCastle.Utilities; -using Org.BouncyCastle.Crypto.Utilites; namespace Org.BouncyCastle.Cms { @@ -20,20 +21,15 @@ namespace Org.BouncyCastle.Cms { private static readonly IDictionary BaseCipherNames = Platform.CreateHashtable(); private static readonly IDictionary MacAlgNames = Platform.CreateHashtable(); - - private static readonly IDictionary prfs = Platform.CreateHashtable(); - - - public delegate IDigest DigestCreator(); + //private static readonly IDictionary PrfDigests = Platform.CreateHashtable(); static EnvelopedDataHelper() { - prfs.Add(PkcsObjectIdentifiers.IdHmacWithSha1, new DigestProvider(delegate () { return new Sha1Digest(); })); - prfs.Add(PkcsObjectIdentifiers.IdHmacWithSha224, new DigestProvider(delegate () { return new Sha224Digest(); })); - prfs.Add(PkcsObjectIdentifiers.IdHmacWithSha256, new DigestProvider(delegate () { return new Sha256Digest(); })); - prfs.Add(PkcsObjectIdentifiers.IdHmacWithSha384, new DigestProvider(delegate () { return new Sha384Digest(); })); - prfs.Add(PkcsObjectIdentifiers.IdHmacWithSha512, new DigestProvider(delegate () { return new Sha512Digest(); })); - + //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"); @@ -47,77 +43,53 @@ namespace Org.BouncyCastle.Cms MacAlgNames.Add(PkcsObjectIdentifiers.RC2Cbc, "RC2Mac"); } - static IDigest GetPrf(AlgorithmIdentifier algID) - { - return ((DigestCreator)prfs[algID]).Invoke(); - } - - - static IWrapper CreateRFC3211Wrapper(DerObjectIdentifier algorithm) - - { - if (NistObjectIdentifiers.IdAes128Cbc.Equals(algorithm) - || NistObjectIdentifiers.IdAes192Cbc.Equals(algorithm) - || NistObjectIdentifiers.IdAes256Cbc.Equals(algorithm)) - { - return new Rfc3211WrapEngine(new AesEngine()); - } - 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) - + //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(new AesEngine()); + // } + // 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.GetKey().Length * 8, random); } - public CipherKeyGenerator CreateKeyGenerator(DerObjectIdentifier algorithm, SecureRandom random) - + public CipherKeyGenerator CreateKeyGenerator(DerObjectIdentifier algorithm, SecureRandom random) { return CipherKeyGeneratorFactory.CreateKeyGenerator(algorithm, random); } - - - } - - // This exists because we can't directly put a delegate in a map as it is - // not an object. - internal class DigestProvider - { - private readonly EnvelopedDataHelper.DigestCreator creator; - - public DigestProvider(EnvelopedDataHelper.DigestCreator creator) - { - this.creator = creator; - } - - public IDigest Create() - { - return creator.Invoke(); - } } } |