You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.0 KiB
67 lines
2.0 KiB
using System;
|
|
using System.Collections;
|
|
using System.IO;
|
|
|
|
using Org.BouncyCastle.Asn1;
|
|
using Org.BouncyCastle.Asn1.Nist;
|
|
using Org.BouncyCastle.Asn1.Ntt;
|
|
using Org.BouncyCastle.Asn1.X509;
|
|
using Org.BouncyCastle.Cms;
|
|
using Org.BouncyCastle.Crypto.IO;
|
|
using Org.BouncyCastle.Crypto.Parameters;
|
|
using Org.BouncyCastle.Security;
|
|
using Org.BouncyCastle.Utilities;
|
|
using Org.BouncyCastle.Crypto;
|
|
using Org.BouncyCastle.Crypto.Operators;
|
|
|
|
namespace Org.BouncyCastle.Operators
|
|
{
|
|
public class CmsContentEncryptorBuilder
|
|
{
|
|
private static readonly IDictionary KeySizes = Platform.CreateHashtable();
|
|
|
|
static CmsContentEncryptorBuilder()
|
|
{
|
|
KeySizes[NistObjectIdentifiers.IdAes128Cbc] = 128;
|
|
KeySizes[NistObjectIdentifiers.IdAes192Cbc] = 192;
|
|
KeySizes[NistObjectIdentifiers.IdAes256Cbc] = 256;
|
|
|
|
KeySizes[NttObjectIdentifiers.IdCamellia128Cbc] = 128;
|
|
KeySizes[NttObjectIdentifiers.IdCamellia192Cbc] = 192;
|
|
KeySizes[NttObjectIdentifiers.IdCamellia256Cbc] = 256;
|
|
}
|
|
|
|
private static int GetKeySize(DerObjectIdentifier oid)
|
|
{
|
|
if (KeySizes.Contains(oid))
|
|
{
|
|
return (int)KeySizes[oid];
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
private readonly DerObjectIdentifier encryptionOID;
|
|
private readonly int keySize;
|
|
|
|
private readonly EnvelopedDataHelper helper = new EnvelopedDataHelper();
|
|
//private SecureRandom random;
|
|
|
|
public CmsContentEncryptorBuilder(DerObjectIdentifier encryptionOID)
|
|
: this(encryptionOID, GetKeySize(encryptionOID))
|
|
{
|
|
}
|
|
|
|
public CmsContentEncryptorBuilder(DerObjectIdentifier encryptionOID, int keySize)
|
|
{
|
|
this.encryptionOID = encryptionOID;
|
|
this.keySize = keySize;
|
|
}
|
|
|
|
public ICipherBuilderWithKey Build()
|
|
{
|
|
//return new Asn1CipherBuilderWithKey(encryptionOID, keySize, random);
|
|
return new Asn1CipherBuilderWithKey(encryptionOID, keySize, null);
|
|
}
|
|
}
|
|
}
|
|
|