Class CertificateUtil
Provides the making and reading of TLS certificates for a VPN server.
public static class CertificateUtil
- Inheritance
-
CertificateUtil
- Inherited Members
Methods
CreateChained(RSA, string?, DateTimeOffset?)
Makes a certificate with a given RSA key under a made-up chain of two authorities that bear DigiCert's names, valid from now.
public static X509Certificate2 CreateChained(RSA rsa, string? subjectName = null, DateTimeOffset? notAfter = null)
Parameters
rsaRSAThe key.
subjectNamestringThe subject, or null for
CN=and a made-up host name (CreateRandomDns()).notAfterDateTimeOffset?The end of its validity, or null for 5 years from now.
Returns
- X509Certificate2
The certificate, with its private key, which can be exported.
Exceptions
- ArgumentException
The end is past the made-up authority's, 8 March 2027, as the default's is now.
CreateExportable(X509Certificate2, string)
Makes a copy of a certificate whose private key is kept and can be exported.
public static X509Certificate2 CreateExportable(X509Certificate2 certificate, string password = "")
Parameters
certificateX509Certificate2The certificate, with its private key.
passwordstringThe password the copy goes through PKCS#12 with. The default is empty.
Returns
- X509Certificate2
The copy.
CreateRandomDns()
Makes up a host name: a host of the kind many sites keep for an API or their files, a pronounceable name of three
or four syllables, and .com, .net or .org, meant to have no fixed shape a network could match.
public static string CreateRandomDns()
Returns
- string
The host name.
CreateSelfSigned(RSA, string?, DateTimeOffset?)
Makes a self-signed certificate, SHA-256 with a given RSA key, valid from now.
public static X509Certificate2 CreateSelfSigned(RSA rsa, string? subjectName = null, DateTimeOffset? notAfter = null)
Parameters
rsaRSAThe key.
subjectNamestringThe subject, or null for
CN=and a made-up host name (CreateRandomDns()).notAfterDateTimeOffset?The end of its validity, or null for 20 years from now.
Returns
- X509Certificate2
The certificate, with its private key, which can be exported.
CreateSelfSigned(X509Certificate2, DateTime?, DateTime?)
Makes a self-signed copy of a certificate's subject and extensions, SHA-256 with a new RSA key.
public static X509Certificate2 CreateSelfSigned(X509Certificate2 originalCert, DateTime? noBefore = null, DateTime? notAfter = null)
Parameters
originalCertX509Certificate2The certificate to copy.
noBeforeDateTime?The start of its validity, or null for the original's.
notAfterDateTime?The end of its validity, or null for the original's.
Returns
- X509Certificate2
The certificate, with its private key, which can be exported.
Remarks
On Windows, it takes the original's friendly name too.
CreateSelfSigned(string?, DateTimeOffset?)
Makes a self-signed certificate, SHA-256 with a new RSA key, valid from now.
public static X509Certificate2 CreateSelfSigned(string? subjectName = null, DateTimeOffset? notAfter = null)
Parameters
subjectNamestringThe subject, or null for
CN=and a made-up host name (CreateRandomDns()).notAfterDateTimeOffset?The end of its validity, or null for 20 years from now.
Returns
- X509Certificate2
The certificate, with its private key, which can be exported.
GetCertificateFromUrl(Uri, CancellationToken)
Gets the certificate an HTTPS address presents, without checking it; the request's own errors are ignored.
public static Task<X509Certificate2> GetCertificateFromUrl(Uri url, CancellationToken cancellationToken)
Parameters
urlUriThe address.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
- Task<X509Certificate2>
A task whose result is the certificate.
Exceptions
- Exception
The address presented no certificate.