Create Self-Signed Development Certificate
Code Properties
- Language: PowerShell
- Cmdlets:
New-SelfSignedCertificate,Export-Certificate,Set-AuthenticodeSignature- Requires: Administrator privileges
Overview
Sources:
This script creates a new self-signed development certificate, exports it to a local .cer file, and demonstrates how to sign scripts or DLLs.
Code
#Requires -RunAsAdministrator
# declare certificate name
$CertName = "DevCert"
# specify parameters
$Params = @{
Subject = "CN=$CertName"
CertStoreLocation = "Cert:\CurrentUser\My"
KeyExportPolicy = "Exportable"
KeySpec = "Signature"
KeyLength = 2048
KeyAlgorithm = "RSA"
HashAlgorithm = "SHA256"
Type = "CodeSigningCert"
}
# create the certificate
$Cert = New-SelfSignedCertificate @Params
# export certificate to local file
Export-Certificate -Cert $Cert -FilePath ".\$CertName.cer"
# sign a script
Set-AuthenticodeSignature -FilePath "path/to/script.ps1" -Certificate $Cert
# sign a DLL
Set-AuthenticodeSignature -FilePath "path/to/library.dll" -Certificate $CertTo import the certificate to the Trusted Root Certification Authority:
certutil -addstore "Root" ".\$CertName.cer"Usage
- Run PowerShell as Administrator
- Execute the script to create the certificate
- Use
Set-AuthenticodeSignatureto sign your scripts or DLLs - Import the certificate to trusted roots on target machines
Appendix
Note created on 2024-04-13 and last modified on 2024-12-31.
See Also
Backlinks
(c) No Clocks, LLC | 2024