PdfCertificate Class
Represents an X.509 certificate sent to others so that they can verify your digital signature with a public key contained in the certificate.
public sealed class PdfCertificate : IEquatable<PdfCertificate>
Public NotInheritable Class PdfCertificate
Implements IEquatable(Of PdfCertificate)
- Inheritance:
- System.ObjectPdfCertificate
Implements
Remarks
GemBox.Pdf doesn't use System.Security.Cryptography.X509Certificates.X509Certificate2 class to represent a certificate because System.Security.Cryptography.X509Certificates.X509Certificate2 creates a file that holds the certificate with the public key (in various locations on a hard drive) and on some operating systems and platforms that file is not deleted unless System.Security.Cryptography.X509Certificates.X509Certificate2.Reset method is called.
Another reason why GemBox.Pdf abstracts a certificate with a PdfCertificate class instead of using System.Security.Cryptography.X509Certificates.X509Certificate2 directly is to enable different implementations of a certificate. For example, either System.Security.Cryptography.X509Certificates.X509Certificate2 implementation from .NET or Org.BouncyCastle.X509.X509Certificate implementation from Bouncy Castle could be used.
Constructors
PdfCertificate(Object)
Initializes a new instance of the PdfCertificate class from the specified source.
The certificate source is an instance of a System.Security.Cryptography.X509Certificates.X509Certificate2.
Parameters
source
- System.Object
The certificate source that is an instance of a System.Security.Cryptography.X509Certificates.X509Certificate2.
Exceptions
- System.ArgumentException
The source
parameter is not an instance of a System.Security.Cryptography.X509Certificates.X509Certificate2.
PdfCertificate(String)
Initializes a new instance of the PdfCertificate class from a file with the specified file name.
Parameters
fileName
- System.String
The name of a certificate file.
Exceptions
- System.ArgumentNullException
fileName
is null.
Properties
Subject
Gets the subject distinguished name from the certificate.
Property Value
- System.String
The subject distinguished name from the certificate.
SubjectCommonName
Gets the value of a Common Name attribute from Subject's distinguished name.
public string SubjectCommonName { get; }
Public ReadOnly Property SubjectCommonName As String
Property Value
- System.String
The value of a Common Name attribute from Subject's distinguished name.
Methods
Create(String, Object, PdfDigitalId, DateTimeOffset, DateTimeOffset, Byte[], X509ExtensionCollection, PdfHashAlgorithm, PdfRSASignaturePadding)
Creates a self-signed or chain-signed X.509 Public-Key certificate.
public static PdfCertificate Create(string subjectName, object subjectPublicKey, PdfDigitalId issuer, DateTimeOffset notBefore, DateTimeOffset notAfter, byte[] serialNumber = null, X509ExtensionCollection extensions = null, PdfHashAlgorithm hashAlgorithm = PdfHashAlgorithm.SHA256, PdfRSASignaturePadding rsaSignaturePadding = null)
Public Shared Function Create(subjectName As String, subjectPublicKey As Object, issuer As PdfDigitalId, notBefore As DateTimeOffset, notAfter As DateTimeOffset, serialNumber As Byte() = Nothing, extensions As X509ExtensionCollection = Nothing, hashAlgorithm As PdfHashAlgorithm = PdfHashAlgorithm.SHA256, rsaSignaturePadding As PdfRSASignaturePadding = Nothing) As PdfCertificate
Parameters
subjectName
- System.String
The X.500 Distinguished Name to use as the Subject in a created certificate.
subjectPublicKey
- System.Object
The X.509 SubjectPublicKeyInfo structure to include in the certificate. Supported types are System.Security.Cryptography.X509Certificates.PublicKey, System.Array of System.Bytes that represent DER-encoding of the X.509 SubjectPublicKeyInfo structure, System.String that represent PEM-encoding of the X.509 SubjectPublicKeyInfo structure, System.Security.Cryptography.RSAParameters, System.Security.Cryptography.DSAParameters, System.Security.Cryptography.ECParameters, and Org.BouncyCastle.Crypto.Parameters.ECPublicKeyParameters.
issuer
- PdfDigitalId
A PdfDigitalId instance representing the issuing Certificate Authority (CA). If the issuer
's Certificate is null, then the created certificate is self-signed (the certificate's Issuer is equal to its Subject).
notBefore
- System.DateTimeOffset
The oldest date and time when the certificate is considered valid. Typically System.DateTimeOffset.UtcNow, plus or minus a few seconds.
notAfter
- System.DateTimeOffset
The date and time when the certificate is no longer considered valid.
serialNumber
- System.Byte[]
The optional serial number to use for the new certificate. This value should be unique per issuer. The value is interpreted as an unsigned integer of arbitrary size in big-endian byte ordering. RFC 5280 recommends confining it to 20 bytes or less.
extensions
- System.Security.Cryptography.X509Certificates.X509ExtensionCollection
The optional X.509 Certificate Extensions collection, which is a mutable collection, to include in the certificate.
hashAlgorithm
- PdfHashAlgorithm
The optional hash algorithm to use when signing the certificate.
rsaSignaturePadding
- PdfRSASignaturePadding
The optional RSA signature padding to apply when signing the certificate if issuer
has an 'RSA' private key.
Returns
A PdfCertificate with the specified values.
Exceptions
- System.ArgumentNullException
subjectName
, subjectPublicKey
, or issuer
is null.
Equals(PdfCertificate)
Determines whether the specified PdfCertificate is equal to this PdfCertificate instance.
public bool Equals(PdfCertificate other)
Public Function Equals(other As PdfCertificate) As Boolean
Parameters
other
- PdfCertificate
The PdfCertificate to compare with this PdfCertificate instance.
Returns
- System.Boolean
true if the specified PdfCertificate is equal to this PdfCertificate instance; otherwise, false.
Equals(Object)
Determines whether the specified System.Object is equal to this PdfCertificate instance.
public override bool Equals(object obj)
Public Overrides Function Equals(obj As Object) As Boolean
Parameters
obj
- System.Object
The System.Object to compare with this PdfCertificate instance.
Returns
- System.Boolean
true if the specified System.Object is equal to this PdfCertificate instance; otherwise, false.
Overrides
FromPem(String)
Creates a PdfCertificate from a PEM encoded certificate data.
public static PdfCertificate FromPem(string pem)
Public Shared Function FromPem(pem As String) As PdfCertificate
Parameters
pem
- System.String
The PEM encoded certificate data.
Returns
A PdfCertificate created from the specified PEM encoded certificate data.
GetHashCode()
Returns a hash code for this PdfCertificate instance.
Returns
- System.Int32
A hash code for this PdfCertificate instance, suitable for use in hashing algorithms and data structures like a hash table.
Overrides
GetRawData()
Gets the copy of raw data of a PdfCertificate.
Returns
- System.Byte[]
The copy of raw data of the PdfCertificate as a byte array.
ToString()
Returns a System.String that represents this PdfCertificate instance.
Returns
- System.String
A System.String that represents this PdfCertificate instance.
Overrides
Remarks
This method should be used primarily for debugging purposes and should be considered volatile (format of its return value might change in future versions).