Categories: Linux SSL Windows

Convert x509/PEM SSL Certificate to PFX/P12 from Linux to Windows

often when you’re working in heterogeneous environments you will be needing to convert the standard linux format x509/pem ssl certificate files to the windows native pfx/p12  format, or vise-versa.  the following openssl commands are able to do just about every type of certificate conversion imaginable.

tip
.pem, .cer, crt. are all the same type of x509/pem certificate only with different extensions.
full certificate chain = public cert + intermediate cert + root cert contained in a single file

openssl convert x509/pem

convert pem & private key to pfx/p12:

openssl pkcs12 -export -out certificate.pfx -inkey privatekey.pem -in certificate.pem -certfile cacert.pem

convert fullchain pem & private key (let’s encrypt) to pfx/p12

openssl pkcs12 -export -out sysinfo.io.pfx -inkey privkey.pem -in fullchain.pem

openssl convert pfx/p12

convert pfx to pem and private key

openssl pkcs12 -in certificate.pfx -out certificate.pem -nodes

remove private key password

openssl rsa -in file.key -out file2.key

enter the passphrase and [file2.key] is now the unprotected private key.

the output file: [file2.key] should be unencrypted. to verify this open the file using a text editor (vi/nano) and view the headers.

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 der to pem:

openssl x509 -inform der -in certificate.der -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
openssl pkcs12 -export -in certificate.cer -inkey privatekey.pem -out certificate.pfx -certfile cacert.cer

 

if you need to convert a java keystore .jks let’s say taking an ssl cert from a tomcat system and moving it to apache or windows and vice-versa, it is usually easier to simply generate a new csr key-pair from those systems and perform a re-issue of the cert, however there’s a way using a conversion application such as portecle.

man page

name

openssl – openssl command line tool

synopsis

openssl command [ command_opts ] [ command_args ]

openssl list [ standard-commands | digest-commands | cipher-commands | cipher-algorithms | digest-algorithms | public-key-algorithms]

the openssl project is a collaborative effort to develop a robust, commercial-grade, fully featured, and open source toolkit implementing the transport layer security (tls) protocols (including sslv3) as well as a full-strength general purpose cryptographic library.

related content: to convert certificates from windows to linux click here.

the openssl toolkit includes:

libssl (with platform specific naming):
provides the client and server-side implementations for sslv3 and tls.

libcrypto (with platform specific naming):
provides general cryptographic and x.509 support needed by ssl/tls but
not logically part of it.

openssl:

  • creation of key parameters
  • creation of x.509 certificates, csrs and crls
  • calculation of message digests
  • encryption and decryption
  • ssl/tls client and server tests
  • handling of s/mime signed or encrypted mail
  • and more…

 

get openssl:

  1. download and install openssl to perform a certificate conversion.

 

 ivan ristić, the creator of ssllabs.com, has a free download of his openssl cookbook that covers the most frequently used openssl features and commands. it is updated often, and is available at https://www.feistyduck.com/books/openssl-cookbook/. it is highly recommended.

openssl no-xxx [ arbitrary options ]

description

openssl is a cryptography toolkit implementing the secure sockets layer (ssl v2/v3) and transport layer security (tls v1) network protocols and related cryptography standards required by them.

the openssl program is a command line tool for using the various cryptography functions of openssl’s crypto library from the shell. it can be used for

  • creation and management of private keys, public keys and parameters
  • public key cryptographic operations
  • creation of x.509 certificates, csrs and crls
  • calculation of message digests
  • encryption and decryption with ciphers
  • ssl/tls client and server tests
  • handling of s/mime signed or encrypted mail
  • time stamp requests, generation and verification

command summary

the openssl program provides a rich variety of commands (command in the synopsis above), each of which often has a wealth of options and arguments (command_opts and command_args in the synopsis).

detailed documentation and use cases for most standard subcommands are available (e.g., x509(1) or openssl-x509(1)).

many commands use an external configuration file for some or all of their arguments and have a -config option to specify that file. the environment variable openssl_conf can be used to specify the location of the file. if the environment variable is not specified, then the file is named openssl.cnf in the default certificate storage area, whose value depends on the configuration flags specified when the openssl was built.

the list parameters standard-commandsdigest-commands, and cipher-commands output a list (one entry per line) of the names of all standard commands, message digest commands, or cipher commands, respectively, that are available in the present openssl utility.

the list parameters cipher-algorithms and digest-algorithms list all cipher and message digest names, one entry per line. aliases are listed as:

from => to

the list parameter public-key-algorithms lists all supported public key algorithms.

the command no-xxx tests whether a command of the specified name is available. if no command named xxx exists, it returns 0 (success) and prints no-xxx; otherwise it returns 1 and prints xxx. in both cases, the output goes to stdout and nothing is printed to stderr. additional command line arguments are always ignored. since for each cipher there is a command of the same name, this provides an easy way for shell scripts to test for the availability of ciphers in the openssl program. (no-xxx is not able to detect pseudo-commands such as quitlist, or no-xxx itself.)

standard commands

asn1parse
parse an asn.1 sequence.
ca
certificate authority (ca) management.
ciphers
cipher suite description determination.
cms
cms (cryptographic message syntax) utility.
crl
certificate revocation list (crl) management.
crl2pkcs7
crl to pkcs#7 conversion.
dgst
message digest calculation.
dh
diffie-hellman parameter management. obsoleted by dhparam.
dhparam
generation and management of diffie-hellman parameters. superseded by genpkey and pkeyparam.
dsa
dsa data management.
dsaparam
dsa parameter generation and management. superseded by genpkey and pkeyparam.
ec
ec (elliptic curve) key processing.
ecparam
ec parameter manipulation and generation.
enc
encoding with ciphers.
engine
engine (loadable module) information and manipulation.
errstr
error number to error string conversion.
gendh
generation of diffie-hellman parameters. obsoleted by dhparam.
gendsa
generation of dsa private key from parameters. superseded by genpkey and pkey.
genpkey
generation of private key or parameters.
genrsa
generation of rsa private key. superseded by genpkey.
nseq
create or examine a netscape certificate sequence.
ocsp
online certificate status protocol utility.
passwd
generation of hashed passwords.
pkcs12
pkcs#12 data management.
pkcs7
pkcs#7 data management.
pkey
public and private key management.
pkeyparam
public key algorithm parameter management.
pkeyutl
public key algorithm cryptographic operation utility.
rand
generate pseudo-random bytes.
req
pkcs#10 x.509 certificate signing request (csr) management.
rsa
rsa key management.
rsautl
rsa utility for signing, verification, encryption, and decryption. superseded by pkeyutl.
s_client
this implements a generic ssl/tls client which can establish a transparent connection to a remote server speaking ssl/tls. it’s intended for testing purposes only and provides only rudimentary interface functionality but internally uses mostly all functionality of the openssl ssl library.
s_server
this implements a generic ssl/tls server which accepts connections from remote clients speaking ssl/tls. it’s intended for testing purposes only and provides only rudimentary interface functionality but internally uses mostly all functionality of the openssl ssl library. it provides both an own command line oriented protocol for testing ssl functions and a simple http response facility to emulate an ssl/tls-aware webserver.
s_time
ssl connection timer.
sess_id
ssl session data management.
smime
s/mime mail processing.
speed
algorithm speed measurement.
spkac
spkac printing and generating utility.
ts
time stamping authority tool (client/server).
verify
x.509 certificate verification.
version
openssl version information.
x509
x.509 certificate data management.

message digest commands

md2
md2 digest
md5
md5 digest
mdc2
mdc2 digest
rmd160
rmd-160 digest
sha
sha digest
sha1
sha-1 digest
sha224
sha-224 digest
sha256
sha-256 digest
sha384
sha-384 digest
sha512
sha-512 digest

encoding and cipher commands

base64
base64 encoding
bf bf-cbc bf-cfb bf-ecb bf-ofb
blowfish cipher
cast cast-cbc
cast cipher
cast5-cbc cast5-cfb cast5-ecb cast5-ofb
cast5 cipher
des des-cbc des-cfb des-ecb des-ede des-ede-cbc des-ede-cfb des-ede-ofb des-ofb
des cipher
des3 desx des-ede3 des-ede3-cbc des-ede3-cfb des-ede3-ofb
triple-des cipher
idea idea-cbc idea-cfb idea-ecb idea-ofb
idea cipher
rc2 rc2-cbc rc2-cfb rc2-ecb rc2-ofb
rc2 cipher
rc4
rc4 cipher
rc5 rc5-cbc rc5-cfb rc5-ecb rc5-ofb
rc5 cipher

options

details of which options are available depend on the specific command. this section describes some common options with common behavior.

common options

-help
provides a terse summary of all options.

pass phrase options

several commands accept password arguments, typically using -passin and -passout for input and output passwords respectively. these allow the password to be obtained from a variety of sources. both of these options take a single argument whose format is described below. if no password argument is given and a password is required then the user is prompted to enter one: this will typically be read from the current terminal with echoing turned off.

pass:password
the actual password is password. since the password is visible to utilities (like ‘ps’ under unix) this form should only be used where security is not important.
env:var
obtain the password from the environment variable var. since the environment of other processes is visible on certain platforms (e.g. ps under certain unix oses) this option should be used with caution.
file:pathname
the first line of pathname is the password. if the same pathname argument is supplied to -passin and -passout arguments then the first line will be used for the input password and the next line for the output password. pathname need not refer to a regular file: it could for example refer to a device or named pipe.
fd:number
read the password from the file descriptor number. this can be used to send the data via a pipe for example.
stdin
read the password from standard input.

history

the list-xxx-algorithms pseudo-commands were added in openssl 1.0.0; for notes on the availability of other commands, see their individual manual pages.

copyright 2000-2018 the openssl project authors. all rights reserved.

licensed under the openssl license (the “license”). you may not use this file except in compliance with the license. you can obtain a copy in the file license in the source distribution or at https://www.openssl.org/source/license.html.

Share
Disqus Comments Loading...

Recent Posts

FreeNAS Error Creating Pool

command '('gpart', 'create', '-s', 'gpt', '/dev/da8')' returned non-zero exit status 1. If you get this error while trying to create… Read More

May 14, 2019 8:22 am 08:22

Change Grub Default Boot Entry on Linux Mint

i'm dual booting windows and linux mint on my laptop. the grub default is to boot into linux mint, however… Read More

April 23, 2019 7:45 pm 19:45

How to Reset Secure Channel On Active Directory Domain Controller

when you're a little too careless about virtualizing your domain controllers, cloning, migrating, backing up and restoring, returning from vacation… Read More

April 21, 2019 8:14 am 08:14

Run SystemD Script Before System Shutdown

for the sheer hell of it, a few weeks ago i wanted to see if i could properly and successfully… Read More

April 20, 2019 10:14 am 10:14

Learn Systemctl Usage to Manage Systemd Service in Linux

systemd is new service manager for linux. it's a replacement for all previous init systems (sysv/sysvinit & ubuntu's upstart) and… Read More

April 20, 2019 7:55 am 07:55

Force Delete Windows Server DHCP Failover Relationship

if you've found yourself here then chances are you messed up one of your domain controllers or at least one… Read More

April 20, 2019 5:54 am 05:54