@_az,
Sorry for late response. Yes you are right,the above code does not export the private key with the .pfx file.
Now I have solved it in another way. I am putting it here if somebody is required.
I have changed the following code in ACMECLI:
case Constants.RsaKeyType:
certKeys = CryptoHelper.Rsa.GenerateKeys(KeySize ?? Constants.DefaultAlgorKeySizeMap[KeyAlgor]);
key = CertHelper.GenerateRsaPrivateKey(2048); // #chan333 add
using (var rsa = CryptoHelper.Rsa.GenerateAlgorithm(certKeys))
{
certCsr = CryptoHelper.Rsa.GenerateCsr(Dns, rsa);
}
break;
TO
case Constants.RsaKeyType:
key = CertHelper.GenerateRsaPrivateKey(2048);
certCsr = CertHelper.GenerateRsaCsr(Dns, key);
break;
then creating a Private key .PEM file
using (var keyPem = new MemoryStream())
{
CertHelper.ExportPrivateKey(key, EncodingFormat.PEM, keyPem);
keyPem.Position = 0L;
Save(AcmeOrderCertKeyFmt, keyPem);
}
and in the final code block of exporting .pfx file:
if (ExportPfx != null)
{
Console.WriteLine(“Exporting Certificate as PKCS12…”);
var certByte = Load<byte>(Constants.AcmeOrderCertFmt).value;
key = CertHelper.ImportPrivateKey(EncodingFormat.PEM,
Load(AcmeOrderCertKeyFmt).value);
using (var crtStream = new MemoryStream(certByte))
using (var pfxStream = new MemoryStream())
{
Console.WriteLine(“Reading in Certificate chain (PEM)”);
var cert = ACMEKestrel.Crypto.CertHelper.ImportCertificate(EncodingFormat.PEM, crtStream);
Console.WriteLine(“Writing out Certificate archive (PKCS12)”);
CertHelper.ExportArchive(key, new[] { cert }, ArchiveFormat.PKCS12, pfxStream, "chanchal");
pfxStream.Position = 0L;
Save(_statePath + "\\" + t.Host + ".pfx", pfxStream);
}
}
and then i import to IIS and it is imported and the wild card certificate working fine
Hope this helps someone.
@JuergenAuer
The content is:
-----BEGIN CERTIFICATE-----
MIIFYjCCBEqgAwIBAgISBKPiklDHdHyuQzCEfOcyY6MbMA0GCSqGSIb3DQEBCwUA
MEoxCzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB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