Created
December 17, 2021 19:37
-
-
Save ridomin/e068e4d10d9dfd2cfa9e2675b4aea917 to your computer and use it in GitHub Desktop.
CreateLeafCert.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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