Skip to content

Instantly share code, notes, and snippets.

@ridomin
Created December 17, 2021 19:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ridomin/e068e4d10d9dfd2cfa9e2675b4aea917 to your computer and use it in GitHub Desktop.
Save ridomin/e068e4d10d9dfd2cfa9e2675b4aea917 to your computer and use it in GitHub Desktop.
CreateLeafCert.ps1
$root = gci "cert:\CurrentUser\my\d8c5cd7502cd699783d9b2c031636ca48ae4229f"
$rootSubject = $root.Subject.Substring(3)
Write-Host "Root Certificate" $root.Thumbprint
$certName = "myCustomCert"
$cert = New-SelfSignedCertificate `
-CertStoreLocation cert:\CurrentUser\my `
-Subject $certName `
-Signer $root `
-HashAlgorithm SHA256 `
-NotAfter (Get-Date).AddMonths(24) `
-KeyUsage KeyEncipherment, DataEncipherment
Write-Host $cert.Subject $cert.Thumbprint
Export-Certificate -Cert $cert -FilePath "$certname.cer" -TYPE CERT
certutil -encode "$certname.cer" "$certname.der"
$bashCmd = "openssl x509 -in '$certname.der' -out '$certname.cert.pem'"
Write-Host $bashCmd
bash -c $bashCmd
$mypwd = ConvertTo-SecureString -String "1234" -Force -AsPlainText
Export-PfxCertificate -Cert $cert -FilePath "$certname.pfx" -Password $mypwd
$bashCmd = "openssl pkcs12 -in '$certname.pfx' -out '$certname.key.pem' -nodes"
bash -c $bashCmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment