Create Self-Signed Development Certificate PowerShell Code

title: Contents 
style: nestedList # TOC style (nestedList|inlineFirstLevel)
minLevel: 1 # Include headings from the specified level
maxLevel: 4 # Include headings up to the specified level
includeLinks: true # Make headings clickable
debugInConsole: false # Print debug info in Obsidian console

Overview

Sources:

Code Snippet

The script below creates a new self-signed, development certificate, exports it to a local .cer file, and demonstrates how to sign a script or Dynamic Link Library (DLL):

#Requires -RunAsAdministrator
 
# Declare Certificate Name
$CertName = "DevtCert"
 
# Specify Splat Params
$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 Path
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 $cert

To import the certificate to the Trusted Root Certification Authority:

certutil -addstore "Root" ".\$CertName.cer"

Details

About

This note is about …

See Also


Appendix

Note created on 2024-04-13 and last modified on 2024-04-13.

LIST FROM [[PowerShell - Create Self-Signed Development Certificate]] AND -"CHANGELOG" AND -"04-RESOURCES/Code/PowerShell/PowerShell - Create Self-Signed Development Certificate"

(c) No Clocks, LLC | 2024