Table of Contents

Class CertificateSigner

Namespace
MiPdf.Signatures
Assembly
MiPdf.dll

An IExternalSigner backed by a local certificate with private key.

public sealed class CertificateSigner : IExternalSigner
Inheritance
CertificateSigner
Implements
Inherited Members

Constructors

CertificateSigner(X509Certificate2, IEnumerable<X509Certificate2>?)

Creates a signer for a certificate with an RSA or ECDSA private key.

public CertificateSigner(X509Certificate2 certificate, IEnumerable<X509Certificate2>? chain = null)

Parameters

certificate X509Certificate2

The signer certificate including its private key.

chain IEnumerable<X509Certificate2>

Intermediate certificates to embed in the signature (optional).

Exceptions

ArgumentException

The certificate has no private key.

Properties

Certificate

The signer certificate (public part).

public X509Certificate2 Certificate { get; }

Property Value

X509Certificate2

CertificateChain

Intermediate certificates to embed (may be empty).

public IReadOnlyList<X509Certificate2> CertificateChain { get; }

Property Value

IReadOnlyList<X509Certificate2>

Methods

FromPfx(string, string?)

Loads a PKCS#12 (.pfx/.p12) file and uses the first certificate with a private key; the other certificates form the chain.

public static CertificateSigner FromPfx(string path, string? password)

Parameters

path string
password string

Returns

CertificateSigner

SignHash(byte[], HashAlgorithmName)

Signs a hash with the private key: PKCS#1 v1.5 for RSA keys, IEEE P1363 (r || s) for EC keys.

public byte[] SignHash(byte[] hash, HashAlgorithmName hashAlgorithm)

Parameters

hash byte[]
hashAlgorithm HashAlgorithmName

Returns

byte[]

Exceptions

PdfException

The key is neither RSA nor ECDSA.

SignHash(byte[], HashAlgorithmName, RSASignaturePadding)

Signs a hash with the given RSA padding (PKCS#1 v1.5 or PSS). EC keys have no padding: for them the argument is ignored and the signature is IEEE P1363 (r || s), as by SignHash(byte[], HashAlgorithmName).

public byte[] SignHash(byte[] hash, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)

Parameters

hash byte[]
hashAlgorithm HashAlgorithmName
padding RSASignaturePadding

Returns

byte[]