
Windows 以 PowerShell 建立程式碼簽章用的自簽憑證教學與範例
介紹如何在 Windows 的 PowerShell 中,使用 cmdlet 建立程式碼簽章用的自簽憑證,並對程式進行簽屬。 使用者在使用自我簽屬憑證所簽屬的程式時,需要先安裝與信任憑證,否則程式無法執行,通常自簽憑證僅用於開發與測試階段。 產生自簽憑證 若要產生自簽憑證,可以使用 PowerShell 中的 New-SelfSignedCertificate 這個 cmdlet: # 建立自簽憑證 New-SelfSignedCertificate -Type Custom ` -Subject "CN=My Software, O=My Corporation, C=TW" ` -KeyUsage DigitalSignature ` -FriendlyName "MyCertificate" ` -CertStoreLocation "Cert:\CurrentUser\My" ` -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3", "2.5.29.19={text}") PSParentPath: Microsoft.PowerShell.Security\Certificate::CurrentUser\My Thumbprint Subject ---------- ------- 86B1DE90CCFE6640DD3C952CD965939C1E68F1D5 CN=My Software, O=My Corporation, C=TW 產生出來的憑證會存放在本機的憑證存放區 Cert:\CurrentUser\My 之下,我們可以利用以下指令顯示該憑證的詳細資訊: ...



