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);

参数

SubjectNameX.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 失败)
1Success