Bouncy Castle's X509V3CertificateGenerator.SetSignatureAlgorithm marked obsolete. What do I do?

前端 未结 3 754
小蘑菇
小蘑菇 2020-12-30 05:37

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:



        
3条回答
  •  攒了一身酷
    2020-12-30 06:06

    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}));
    

提交回复
热议问题