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
| SubjectName | The subject, prefixed with CN= when it contains no = character |
|---|---|
| PFXFileName | The PFX file to write |
| PFXPassword | The PFX password |
| ValidDays | Days of validity, minimum 1; values below 1 become 365 |
| KeyBits | RSA bit length for KeyKind 0; curve selector 256/384/521 for KeyKind 1, other values select P-256 |
| KeyKind | 0 = RSA, 1 = ECDSA |
Return values
| 1 | The certificate and PFX were written |
|---|---|
| 0 | The generation or export failed; on non-Windows platforms ECDSA generation is unavailable |