66
77namespace ActiveLogin . Authentication . BankId . AzureKeyVault ;
88
9- internal class AzureKeyVaultCertificateClient
9+ internal class AzureKeyVaultCertificateClient ( SecretClient secretClient )
1010{
1111 public static AzureKeyVaultCertificateClient Create ( ClientCertificateFromAzureKeyVaultOptions options )
1212 {
@@ -46,16 +46,10 @@ private static TokenCredential GetTokenCredential(ClientCertificateFromAzureKeyV
4646 }
4747
4848 private const string CertificateContentType = "application/x-pkcs12" ;
49- private readonly SecretClient _secretClient ;
50-
51- private AzureKeyVaultCertificateClient ( SecretClient secretClient )
52- {
53- _secretClient = secretClient ;
54- }
5549
5650 public X509Certificate2 GetX509Certificate2 ( string keyVaultSecretKey )
5751 {
58- var secret = _secretClient . GetSecret ( keyVaultSecretKey ) . Value ;
52+ var secret = secretClient . GetSecret ( keyVaultSecretKey ) . Value ;
5953 if ( secret . Properties . ContentType != CertificateContentType )
6054 {
6155 throw new ArgumentException ( $ "This certificate must be of type { CertificateContentType } ") ;
@@ -66,11 +60,9 @@ public X509Certificate2 GetX509Certificate2(string keyVaultSecretKey)
6660 return GetX509Certificate2 ( certificateBytes ) ;
6761 }
6862
69- private X509Certificate2 GetX509Certificate2 ( byte [ ] certificate )
63+ private static X509Certificate2 GetX509Certificate2 ( byte [ ] certificate )
7064 {
71- var exportedCertCollection = new X509Certificate2Collection ( ) ;
72- exportedCertCollection . Import ( certificate , null , X509KeyStorageFlags . MachineKeySet ) ;
73-
74- return exportedCertCollection . Cast < X509Certificate2 > ( ) . First ( x => x . HasPrivateKey ) ;
65+ return X509CertificateLoader . LoadPkcs12Collection ( certificate , null , X509KeyStorageFlags . MachineKeySet )
66+ . First ( x => x . HasPrivateKey ) ;
7567 }
7668}
0 commit comments