I am trying to create a self-signed trusted certificate. I am using Bouncy Castle from nuget, and the answer on this question. This is the code on that page:
Even with the code of Lourens I couldn't get it to work and the certificate wouldn't be accepted by chrome. I had to add in the CreateSelfSignedCertificateBasedOnCertificateAuthorityPrivateKey the following code to get it working.
// Subject Alternative Name
var alternativeNames = subjectAlternativeNames.Select(n => new GeneralName(GeneralName.DnsName, n)).ToArray();
var subjectAlternativeNamesExtension = new DerSequence(alternativeNames);
certificateGenerator.AddExtension(X509Extensions.SubjectAlternativeName.Id, false, subjectAlternativeNamesExtension);
//Key Usage
certificateGenerator.AddExtension(X509Extensions.KeyUsage, true, new KeyUsage(KeyUsage.DigitalSignature | KeyUsage.KeyEncipherment));
By the way changed also the following line
certificateGenerator.AddExtension(X509Extensions.ExtendedKeyUsage.Id, false, new ExtendedKeyUsage( new [] { KeyPurposeID.IdKPClientAuth, KeyPurposeID.IdKPServerAuth}));