CreateSelfSignedCertificateExA

Security and Signatures

Description

The trailing A denotes the ANSI (char) DLL entry point; the ActiveX/COM surface exposes only the Unicode form. Behaviour is identical to CreateSelfSignedCertificateEx and string arguments are interpreted using the current SetAnsiMode code page

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 DLCreateSelfSignedCertificateExA(InstanceID: Integer; SubjectName, PFXFileName, PFXPassword: PAnsiChar; ValidDays, KeyBits, KeyKind: Integer): Integer;

DLL

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