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

PowerShell: ADFS Backup and Restore

# AD FS Backup and Restore # Reference documentation: https://learn.microsoft.com/en-us/windows-server/identity/ad-fs/operations/ad-fs-rapid-restore-tool # Set Variables $filePassword="password" $adfsToolDownload="https://download.microsoft.com/download/6/8/A/68AF3CD3-1337-4389-967C-A6751182F286/ADFSRapidRecreationTool.msi"…

PowerShell: Grant Domain Admins Access to Directories

Snippet: # Messing around$shareDrives=@("E","F","G","I","J","N",'O','Q','R','S','T','U','V','W','Z','Y');$subdomain=(net config workstation) -match 'Workstation domain\s+\S+$' -replace '.+?(\S+)$','$1';$domainadmins="$subdomain`\Domain Admins"; $shareDrives | %{"Add-NTFSAccess…

CSS: How To Set Color Gradient and Animation to Text and Background

// Static color gradient .colorGradientClass { background-color: #ffffff !important; background-image: linear-gradient(315deg, #ffffff 0%, #d9d9d9 74%)…