


打开powershell


$subject = "CN=Psc_Driver_Cert"

$cert = New-SelfSignedCertificate `
  -Type Custom `
  -Subject $subject `
  -CertStoreLocation "Cert:\CurrentUser\My" `
  -KeyAlgorithm RSA `
  -KeyLength 2048 `
  -HashAlgorithm SHA256 `
  -KeyUsage DigitalSignature `
  -KeyExportPolicy Exportable `
  -TextExtension @(
    "2.5.29.37={text}1.3.6.1.5.5.7.3.3",
    "2.5.29.19={text}"
  ) `
  -NotAfter (Get-Date).AddYears(10)



注意
  2.5.29.37={text}1.3.6.1.5.5.7.3.3：表示 Code Signing EKU
  KeyUsage DigitalSignature：用于签名
  KeyExportPolicy Exportable：后面才能导出成 .pfx 给 signtool 用



设置密码导出证书
$pwd = ConvertTo-SecureString "a1234567" -AsPlainText -Force

Export-Certificate `
  -Cert $cert `
  -FilePath ".\Psc_Driver_Cert.cer"

Export-PfxCertificate `
  -Cert $cert `
  -FilePath ".\Psc_Driver_Cert.pfx" `
  -Password $pwd


系统信任证书
1. cmd 写法
certutil -addstore Root Psc_Driver_Cert.cer
certutil -addstore TrustedPublisher Psc_Driver_Cert.cer

2. PowerShell 写法
Import-Certificate -FilePath "./Psc_Driver_Cert.cer" -CertStoreLocation "Cert:\LocalMachine\Root"
Import-Certificate -FilePath "./Psc_Driver_Cert.cer" -CertStoreLocation "Cert:\LocalMachine\TrustedPublisher"



日志如下:
PS D:\proj\plant_sun_cat\0_cmake_library\edk> $subject = "CN=Psc_Driver_Cert"
PS D:\proj\plant_sun_cat\0_cmake_library\edk> $cert = New-SelfSignedCertificate `
>>   -Type Custom `
>>   -Subject $subject `
>>   -KeyAlgorithm RSA `
>>   -KeyLength 2048 `
>>   -HashAlgorithm SHA256 `
>>   -KeyUsage DigitalSignature `
>>   -KeyExportPolicy Exportable `
>>   -TextExtension @(
>>     "2.5.29.37={text}1.3.6.1.5.5.7.3.3",
>>     "2.5.29.19={text}"
>>   ) `
>>   -NotAfter (Get-Date).AddYears(10)
PS D:\proj\plant_sun_cat\0_cmake_library\edk>
PS D:\proj\plant_sun_cat\0_cmake_library\edk> Export-Certificate `
>>   -Cert $cert `
>>   -FilePath ".\Psc_Driver_Cert.cer"


    目录: D:\proj\plant_sun_cat\0_cmake_library\edk


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----


PS D:\proj\plant_sun_cat\0_cmake_library\edk> Export-PfxCertificate `
>>   -Cert $cert `
>>   -FilePath ".\Psc_Driver_Cert.pfx" `
>>   -Password $pwd


    目录: D:\proj\plant_sun_cat\0_cmake_library\edk


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         2026/4/16     11:20           2630 Psc_Driver_Cert.pfx


PS D:\proj\plant_sun_cat\0_cmake_library\edk> Import-Certificate -FilePath "./Psc_Driver_Cert.cer" -CertStoreLocation "Cert:\LocalMachine\Root"


   PSParentPath:Microsoft.PowerShell.Security\Certificate::LocalMachine\Root

Thumbprint                                Subject
----------                                -------
62772DAA8714A813D275C3F9264082A9AFF5F16D  CN=Psc_Driver_Cert


PS D:\proj\plant_sun_cat\0_cmake_library\edk> Import-Certificate -FilePath "./Psc_Driver_Cert.cer" -CertStoreLocation "Cert:\LocalMachine\TrustedPublisher"


   PSParentPath:Microsoft.PowerShell.Security\Certificate::LocalMachine\TrustedPublisher

Thumbprint                                Subject
----------                                -------
62772DAA8714A813D275C3F9264082A9AFF5F16D  CN=Psc_Driver_Cert