#if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
#pragma warning disable
using System;
using System.IO;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Cms;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Crmf;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.Pkcs;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Asn1.X509;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Cms;
using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto;
namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Crmf
{
public class PkiArchiveControlBuilder
{
private CmsEnvelopedDataGenerator envGen;
private CmsProcessableByteArray keyContent;
///
///Basic constructor - specify the contents of the PKIArchiveControl structure.
///
/// the private key to be archived.
/// the general name to be associated with the private key.
///
public PkiArchiveControlBuilder(PrivateKeyInfo privateKeyInfo, GeneralName generalName)
{
EncKeyWithID encKeyWithID = new EncKeyWithID(privateKeyInfo, generalName);
try
{
this.keyContent = new CmsProcessableByteArray(CrmfObjectIdentifiers.id_ct_encKeyWithID, encKeyWithID.GetEncoded());
}
catch (IOException e)
{
throw new InvalidOperationException("unable to encode key and general name info", e);
}
this.envGen = new CmsEnvelopedDataGenerator();
}
///Add a recipient generator to this control.
/// recipient generator created for a specific recipient.
///this builder object.
public PkiArchiveControlBuilder AddRecipientGenerator(RecipientInfoGenerator recipientGen)
{
envGen.AddRecipientInfoGenerator(recipientGen);
return this;
}
/// Build the PKIArchiveControl using the passed in encryptor to encrypt its contents.
/// a suitable content encryptor.
/// a PKIArchiveControl object.
public PkiArchiveControl Build(ICipherBuilderWithKey contentEncryptor)
{
CmsEnvelopedData envContent = envGen.Generate(keyContent, contentEncryptor);
EnvelopedData envD = EnvelopedData.GetInstance(envContent.ContentInfo.Content);
return new PkiArchiveControl(new PkiArchiveOptions(new EncryptedKey(envD)));
}
}
}
#pragma warning restore
#endif