@@ -162,7 +162,7 @@ public void EnsureCreateHttpsCertificate_CanExportTheCertInPemFormat()
162
162
{
163
163
// Arrange
164
164
var message = "plaintext" ;
165
- const string CertificateName = nameof ( EnsureCreateHttpsCertificate_DoesNotCreateACertificate_WhenThereIsAnExistingHttpsCertificates ) + ".pfx " ;
165
+ const string CertificateName = nameof ( EnsureCreateHttpsCertificate_DoesNotCreateACertificate_WhenThereIsAnExistingHttpsCertificates ) + ".pem " ;
166
166
var certificatePassword = Guid . NewGuid ( ) . ToString ( ) ;
167
167
168
168
_fixture . CleanupCertificates ( ) ;
@@ -183,10 +183,7 @@ public void EnsureCreateHttpsCertificate_CanExportTheCertInPemFormat()
183
183
Assert . Equal ( EnsureCertificateResult . ValidCertificatePresent , result ) ;
184
184
Assert . True ( File . Exists ( CertificateName ) ) ;
185
185
186
- var key = RSA . Create ( ) ;
187
- key . ImportFromEncryptedPem ( File . ReadAllText ( Path . ChangeExtension ( CertificateName , "key" ) ) , certificatePassword ) ;
188
- var exportedCertificate = new X509Certificate2 ( File . ReadAllBytes ( CertificateName ) ) ;
189
- exportedCertificate = exportedCertificate . CopyWithPrivateKey ( key ) ;
186
+ var exportedCertificate = X509Certificate2 . CreateFromEncryptedPemFile ( CertificateName , certificatePassword , Path . ChangeExtension ( CertificateName , "key" ) ) ;
190
187
Assert . NotNull ( exportedCertificate ) ;
191
188
Assert . True ( exportedCertificate . HasPrivateKey ) ;
192
189
@@ -260,7 +257,7 @@ public void EnsureCreateHttpsCertificate_CanExportTheCertInPemFormat_WithoutPass
260
257
{
261
258
// Arrange
262
259
var message = "plaintext" ;
263
- const string CertificateName = nameof ( EnsureCreateHttpsCertificate_DoesNotCreateACertificate_WhenThereIsAnExistingHttpsCertificates ) + ".pfx " ;
260
+ const string CertificateName = nameof ( EnsureCreateHttpsCertificate_DoesNotCreateACertificate_WhenThereIsAnExistingHttpsCertificates ) + ".pem " ;
264
261
_fixture . CleanupCertificates ( ) ;
265
262
266
263
var now = DateTimeOffset . UtcNow ;
@@ -277,10 +274,7 @@ public void EnsureCreateHttpsCertificate_CanExportTheCertInPemFormat_WithoutPass
277
274
Assert . Equal ( EnsureCertificateResult . ValidCertificatePresent , result ) ;
278
275
Assert . True ( File . Exists ( CertificateName ) ) ;
279
276
280
- var key = RSA . Create ( ) ;
281
- key . ImportFromPem ( File . ReadAllText ( Path . ChangeExtension ( CertificateName , "key" ) ) ) ;
282
- var exportedCertificate = new X509Certificate2 ( File . ReadAllBytes ( CertificateName ) ) ;
283
- exportedCertificate = exportedCertificate . CopyWithPrivateKey ( key ) ;
277
+ var exportedCertificate = X509Certificate2 . CreateFromPemFile ( CertificateName , Path . ChangeExtension ( CertificateName , "key" ) ) ;
284
278
Assert . NotNull ( exportedCertificate ) ;
285
279
Assert . True ( exportedCertificate . HasPrivateKey ) ;
286
280
0 commit comments