Skip to content

Commit 9cd8421

Browse files
authored
Refactor certificate loading to use helper methods
https://learn.microsoft.com/en-us/dotnet/fundamentals/syslib-diagnostics/syslib0057 SYSLIB0057: X509Certificate2 and X509Certificate constructors for binary and file content are obsolete Reason for obsoletion The affected APIs supported loading certificates in multiple formats. For example, new X509Certificate2(data) loaded a certificate from a byte[] called data. data could be one of any supported format, including X.509, PKCS7, or PKCS12/PFX. While this method was easy to use, it created issues where user-supplied data was passed with a different format than intended. This might allow loading PKCS12 where only X.509 content was intended to be loaded. Or it might create interoperability issues from handling the data in different ways.
1 parent e87175e commit 9cd8421

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

content/develop/clients/dotnet/connect.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ ConfigurationOptions options = new ConfigurationOptions
9595

9696
options.CertificateSelection += delegate
9797
{
98-
return new X509Certificate2("redis.pfx", "secret"); // use the password you specified for pfx file
98+
return X509CertificateLoader.LoadPkcs12FromFile("redis.pfx", "secret"); // use the password you specified for pfx file
9999
};
100100
options.CertificateValidation += ValidateServerCertificate;
101101

@@ -109,7 +109,7 @@ bool ValidateServerCertificate(
109109
return false;
110110
}
111111

112-
var ca = new X509Certificate2("redis_ca.pem");
112+
var ca = X509CertificateLoader.LoadCertificateFromFile("redis_ca.pem");
113113
bool verdict = (certificate.Issuer == ca.Subject);
114114
if (verdict) {
115115
return true;

0 commit comments

Comments
 (0)