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 LongDLL
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
| 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 |