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

Quick 1-liner Generate List of Active Directory users

# Discover domain controller:echo %LOGONSERVER%# Display Users:dsquery user -limit 0 | dsget user -display -dept…

Regular Expression (RegEx) Overview

A good online tool to test your regex skills: https://regexr.com/ Syntax: 1. /pattern/flags2. New RegExp(pattern,…

Basic CSS: Add Different Margins to Each Side of an Element

<style>.injected-text {margin-bottom: -25px;text-align: center;}.box {border-style: solid;border-color: black;border-width: 5px;text-align: center;}.yellow-box {background-color: yellow;padding: 10px;}.red-box {background-color: crimson;color: #fff;margin-top:…