@@ -30,14 +30,14 @@ public void SaveRootCertificate(string pathOrName, string password, X509Certific
30
30
/// <inheritdoc />
31
31
public X509Certificate2 ? LoadCertificate ( string subjectName , X509KeyStorageFlags storageFlags )
32
32
{
33
- string path = Path . Combine ( getCertificatePath ( ) , subjectName + defaultCertificateFileExtension ) ;
34
- return loadCertificate ( path , string . Empty , storageFlags ) ;
33
+ string filePath = Path . Combine ( getCertificatePath ( false ) , subjectName + defaultCertificateFileExtension ) ;
34
+ return loadCertificate ( filePath , string . Empty , storageFlags ) ;
35
35
}
36
36
37
37
/// <inheritdoc />
38
38
public void SaveCertificate ( string subjectName , X509Certificate2 certificate )
39
39
{
40
- string filePath = Path . Combine ( getCertificatePath ( ) , subjectName + defaultCertificateFileExtension ) ;
40
+ string filePath = Path . Combine ( getCertificatePath ( true ) , subjectName + defaultCertificateFileExtension ) ;
41
41
byte [ ] exported = certificate . Export ( X509ContentType . Pkcs12 ) ;
42
42
File . WriteAllBytes ( filePath , exported ) ;
43
43
}
@@ -46,9 +46,13 @@ public void Clear()
46
46
{
47
47
try
48
48
{
49
- Directory . Delete ( getCertificatePath ( ) , true ) ;
49
+ string path = getCertificatePath ( false ) ;
50
+ if ( Directory . Exists ( path ) )
51
+ {
52
+ Directory . Delete ( path , true ) ;
53
+ }
50
54
}
51
- catch ( DirectoryNotFoundException )
55
+ catch ( Exception )
52
56
{
53
57
// do nothing
54
58
}
@@ -89,14 +93,14 @@ private string getRootCertificatePath(string pathOrName)
89
93
string . IsNullOrEmpty ( pathOrName ) ? defaultRootCertificateFileName : pathOrName ) ;
90
94
}
91
95
92
- private string getCertificatePath ( )
96
+ private string getCertificatePath ( bool create )
93
97
{
94
98
if ( certificatePath == null )
95
99
{
96
100
string path = getRootCertificateDirectory ( ) ;
97
101
98
102
string certPath = Path . Combine ( path , defaultCertificateDirectoryName ) ;
99
- if ( ! Directory . Exists ( certPath ) )
103
+ if ( create && ! Directory . Exists ( certPath ) )
100
104
{
101
105
Directory . CreateDirectory ( certPath ) ;
102
106
}
0 commit comments