CreateSelfSignedCertificateEx
安全與簽章
描述
建立可選金鑰演算法的自簽憑證,連同私鑰一併匯出到受密碼保護的 PFX 檔案
KeyKind 0 維持 CreateSelfSignedCertificate 的既有 RSA 路徑;KeyKind 1 透過 CNG Microsoft Software Key Storage Provider 建立 ECDSA 金鑰,把 KeyBits 256/384/521 映射到 P-256/P-384/P-521 曲線,並以 ecdsa-with-SHA256 簽署憑證
ECDSA 金鑰存放在一次性 CNG 容器裡,匯出後即刪除;金鑰材料只留在 PFX 檔案中
語法
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);參數
| SubjectName | 主體;不含 = 字元時自動加 CN= 前置 |
|---|---|
| PFXFileName | 要寫出的 PFX 檔案 |
| PFXPassword | PFX 密碼 |
| ValidDays | 有效天數,最小 1;低於 1 的值按 365 處理 |
| KeyBits | KeyKind 0 的 RSA 位元長度;KeyKind 1 的曲線選擇 256/384/521,其他值選 P-256 |
| KeyKind | 0 = RSA,1 = ECDSA |
傳回值
| 1 | 憑證與 PFX 已寫出 |
|---|---|
| 0 | 產生或匯出失敗;非 Windows 平台不支援產生 ECDSA 金鑰 |