init commit

This commit is contained in:
2025-10-09 09:57:24 +09:00
commit 4d551bd74f
6636 changed files with 1218703 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
using System.Collections;
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.Nist;
using Org.BouncyCastle.Asn1.Ntt;
using Org.BouncyCastle.Cms;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Operators;
using Org.BouncyCastle.Utilities;
namespace Org.BouncyCastle.Operators;
public class CmsContentEncryptorBuilder
{
private static readonly IDictionary KeySizes;
private readonly DerObjectIdentifier encryptionOID;
private readonly int keySize;
private readonly EnvelopedDataHelper helper = new EnvelopedDataHelper();
static CmsContentEncryptorBuilder()
{
KeySizes = Platform.CreateHashtable();
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;
}
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, null);
}
}

View File

@@ -0,0 +1,35 @@
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.Cms;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Cms;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.X509;
namespace Org.BouncyCastle.Operators;
public class CmsKeyTransRecipientInfoGenerator : KeyTransRecipientInfoGenerator
{
private readonly IKeyWrapper keyWrapper;
protected override AlgorithmIdentifier AlgorithmDetails => (AlgorithmIdentifier)keyWrapper.AlgorithmDetails;
public CmsKeyTransRecipientInfoGenerator(X509Certificate recipCert, IKeyWrapper keyWrapper)
: base(new IssuerAndSerialNumber(recipCert.IssuerDN, new DerInteger(recipCert.SerialNumber)))
{
this.keyWrapper = keyWrapper;
base.RecipientCert = recipCert;
base.RecipientPublicKey = recipCert.GetPublicKey();
}
public CmsKeyTransRecipientInfoGenerator(byte[] subjectKeyID, IKeyWrapper keyWrapper)
: base(subjectKeyID)
{
this.keyWrapper = keyWrapper;
}
protected override byte[] GenerateWrappedKey(KeyParameter contentKey)
{
return keyWrapper.Wrap(contentKey.GetKey()).Collect();
}
}