CreateSelfSignedCertificateEx

Security and Signatures

Description

Creates a self-signed certificate with a selectable key algorithm and exports it - private key included - to a password-protected PFX file

KeyKind 0 keeps the legacy RSA path of CreateSelfSignedCertificate; KeyKind 1 creates an ECDSA key through the CNG Microsoft Software Key Storage Provider, mapping KeyBits 256/384/521 to the P-256/P-384/P-521 curves and signing the certificate with ecdsa-with-SHA256

The ECDSA key lives in a throwaway CNG container that is deleted after the export; only the PFX file keeps the key material

Syntax

Delphi

Function TPDFlib.CreateSelfSignedCertificateEx(Const SubjectName, PFXFileName, PFXPassword: WideString; ValidDays, KeyBits, KeyKind: Integer): Integer;

ActiveX

Function PDFlib::CreateSelfSignedCertificateEx(SubjectName As String, PFXFileName As String, PFXPassword As String, ValidDays As Long, KeyBits As Long, KeyKind As Long) As Long

DLL

int DLCreateSelfSignedCertificateEx(int InstanceID, const wchar_t* SubjectName, const wchar_t* PFXFileName, const wchar_t* PFXPassword, int ValidDays, int KeyBits, int KeyKind);
int DLCreateSelfSignedCertificateExA(int InstanceID, const char* SubjectName, const char* PFXFileName, const char* PFXPassword, int ValidDays, int KeyBits, int KeyKind);

Parameters

SubjectNameThe subject, prefixed with CN= when it contains no = character
PFXFileNameThe PFX file to write
PFXPasswordThe PFX password
ValidDaysDays of validity, minimum 1; values below 1 become 365
KeyBitsRSA bit length for KeyKind 0; curve selector 256/384/521 for KeyKind 1, other values select P-256
KeyKind0 = RSA, 1 = ECDSA

Return values

1The certificate and PFX were written
0The generation or export failed; on non-Windows platforms ECDSA generation is unavailable

See also

CreateSelfSignedCertificate, SetSignProcessPFXFromFile