CreateSelfSignedCertificate
安全與簽章
描述
建立帶 SHA-256 簽章的自簽 RSA 憑證,並連同私密金鑰匯出到有密碼保護的 PFX 檔案。產生的 PFX 可直接搭配 SignFile、SetSignProcessPFXFromFile 等其他以 PFX 為基礎的簽署進入點,不必先向外部機構取得憑證就能開發與測試簽署流程
憑證產生在暫時的金鑰容器裡,匯出後該容器即被刪除,只有 PFX 檔案保留金鑰材料。自簽憑證適合測試與內部文件:除非使用者明確安裝,PDF 檢視器會把它們標記為不受信任
語法
Delphi
Function TPDFlib.CreateSelfSignedCertificate(Const SubjectName, PFXFileName, PFXPassword: WideString; ValidDays, KeyBits: Integer): Integer;
ActiveX
Function PDFlib::CreateSelfSignedCertificate(SubjectName As String, PFXFileName As String, PFXPassword As String, ValidDays As Long, KeyBits As Long) As Long
DLL
int DLCreateSelfSignedCertificate(int InstanceID, const wchar_t * SubjectName, const wchar_t * PFXFileName, const wchar_t * PFXPassword, int ValidDays, int KeyBits);
參數
| SubjectName | X.500 字串形式的憑證主體,例如 "CN=Alice Signer, O=Example Corp". 不含 "=" 的裸名稱會自動加上 "CN=" 字首。 |
|---|---|
| PFXFileName | 要寫出的 PFX(PKCS#12)檔案路徑。 |
| PFXPassword | 保護匯出 PFX 檔案的密碼。 |
| ValidDays | 自今天起算的有效天數;小於 1 的值預設為 365。 |
| KeyBits | RSA 金鑰長度(位元);超出 1024..16384 的值以 2048 為預設。 |
傳回值
| 0 | 無法建立憑證(主體或檔名為空,或 Windows CryptoAPI 失敗) |
|---|---|
| 1 | Success |