CertificateRequest.CreateSelfSigned(DateTimeOffset, DateTimeOffset) Method

Definition

Creates a self-signed certificate using the established subject, key, and optional extensions.

C#
public System.Security.Cryptography.X509Certificates.X509Certificate2 CreateSelfSigned(DateTimeOffset notBefore, DateTimeOffset notAfter);

Parameters

notBefore
DateTimeOffset

The oldest date and time when this certificate is considered valid. Typically UtcNow, plus or minus a few seconds.

notAfter
DateTimeOffset

The date and time when this certificate is no longer considered valid.

Returns

An X509Certificate2 object with the specified values. The returned object will assert HasPrivateKey.

Exceptions

notAfter represents a date and time that happens earlier than notBefore.

The current object was created using a constructor that doesn't accept a signing key.

An error occurs during the certificate creation process.

The HashAlgorithm property value is not supported.

Remarks

This method does not support using MD5 or SHA-1 as the hash algorithm for the certificate signature. If you need an MD5 or SHA-1 based certificate signature, you need to implement a custom X509SignatureGenerator and call Create(X500DistinguishedName, X509SignatureGenerator, DateTimeOffset, DateTimeOffset, Byte[]).

Applies to

Proizvod Verzije
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 4.7.2, 4.8, 4.8.1
.NET Standard 2.1