Posted On August 14, 2019

PowerShell: Convert Between Various SSL Certificate Formats

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Convert Between Various SSL Certificate Formats
# Install Choco (look for instructions in this blog)

# Install openssl.light
choco install openssl.light -y
# Defining $ENV:ChocotaleyInstall so that it would be called by refreshenv
$ENV:ChocolateyInstall = Convert-Path "$((Get-Command choco).Path)\..\.."
Import-Module "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
Update-SessionEnvironment
# Convert PEM to DER
openssl x509 -outform der -in certificate.pem -out certificate.der

# Convert PEM to P7B
openssl crl2pkcs7 -nocrl -certfile certificate.cer -out certificate.p7b -certfile CACert.cer

# Convert PEM to PFX
openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt

# Convert DER to PEM
openssl x509 -inform der -in certificate.cer -out certificate.pem

# Convert P7B to PEM
openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer

# Convert P7B to PFX
openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer
# OR
openssl pkcs12 -export -in certificate.cer -inkey privateKey.key -out certificate.pfx -certfile CACert.cer

# Convert PFX to PEM
openssl pkcs12 -in certificate.pfx -out certificate.p12 -nodes

# Convert PFX to P12
openssl pkcs12 -in certificate.pfx -out certificate.cer -nodes

# Extract Key
openssl pkcs12 -in C:\Users\rambo\Desktop\kimconnect_com.pfx -nocerts -out C:\Users\rambo\Desktop\key.pem -nodes

# Example:
PS C:\Program Files\OpenSSL\bin> .\openssl pkcs12 -in C:\Users\Test\Desktop\star_kimconnect_com.pfx -out C:\Users\Test\Desktop\star_kimconnect_com.cer -nodes
Enter Import Password:
# Done

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

Use psexec to install application remotely

psexec @ComputerList.txt -u domain\administrator cmd /s /c "xcopy "\\NetworkPath\Forefront Software\Install.exe" "C:\Windows" && Install.exe /u /s…

Hyper-V Servers Report

# hyperVServersReport.ps1 # Version: 0.0.1 # Description: # This script will scan for Hyper-V Hosts…

PowerShell: Measure File Copying Time

The scripty: $sourcesAndDestinations=@("C:\Users\kimconnect\Desktop\test\test1 C:\Users\kimconnect\Desktop\test\test2","C:\Users\kimconnect\Desktop\test\test2 C:\Users\kimconnect\Desktop\test\test3")$testPath="C:\Users\kimconnect\Desktop\test\test1"$switchesMirrorDirectories="/MIR /SEC /W:3 /FFT "$dateStamp = Get-Date -Format "yyyy-MM-dd-hh-mm"$currentPath=(Get-Item -Path ".\").FullName$log="/LOG+:$currentPath\robocopy-log-$dateStamp.txt"function…