- From pem (pem, cer, crt) to pkcs#12 (p12, pfx)
- From pkcs#12 to pem
- How to convert .crt to .pem
- Installing openssl
- Online ssl converters
- Openssl convert der
- Openssl convert p7b
- Openssl convert pem
- Openssl on linux
- Pkcs#7/p7b format
- Конвертирование сертификатов при помощи openssl
- Формат der
- Формат pem
- Формат pkcs#12 или pfx
From pem (pem, cer, crt) to pkcs#12 (p12, pfx)
This is the console command that we can use to convert a PEM certificate file (.pem, .cer or .crt extensions), together with its private key (.key extension), in a single PKCS#12 file (.p12 and .pfx extensions):
If you also have an intermediate certificates file (for example, CAcert.crt) , you can add it to the “bundle” using the -certfile command parameter in the following way:
From pkcs#12 to pem
If you need to “extract” a PEM certificate (.pem, .cer or .crt) and/or its private key (.key)from a single PKCS#12 file (.p12 or .pfx), you need to issue two commands.
The first one is to extract the certificate:
And a second one would be to retrieve the private key:
IMPORTANT: the private key obtained with the above command will be in encrypted format: to convert it in RSA format, you’ll need to input a third command:
Needless to say, since PKCS#12 is a password-protected format, in order to execute all the above commands you’ll be prompted for the password that has been used when creating the .pfx file.
How to convert .crt to .pem
I found the OpenSSL answer given above didn’t work for me, but the following did, working with a CRT file sourced from windows.
openssl x509 -inform DER -in yourdownloaded.crt -out outcert.pem -text
Installing openssl
The first thing to do is to make sure your system has OpenSSL installed: this is a tool that provides an open source implementation of SSL and TLS protocols and that can be used to convert the certificate files into the most popular X.509 v3 based formats.
Online ssl converters
If you can’t (or don’t want to) install OpenSSL, you can convert your SSL Certificates using one of these web-based online tools:
Openssl convert der
Convert DER to PEM
openssl x509 -inform der -in certificate.cer -out certificate.pem
Openssl convert p7b
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.key -out certificate.pfx -certfile CACert.cer
Openssl convert pem
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
Openssl on linux
If you’re using Linux, you can install OpenSSL with the following YUM console command:
If your distribution is based on APT instead of YUM, you can use the following command instead:
Pkcs#7/p7b format
The PKCS#7 or P7B format is usually stored in Base64 ASCII format and has a file extension of .p7b or .p7c. P7B certificates contain “—–BEGIN PKCS7—–” and “—–END PKCS7—–” statements. A P7B file only contains certificates and chain certificates, not the private key. Several platforms support P7B files including Microsoft Windows and Java Tomcat.
Конвертирование сертификатов при помощи openssl
Как только возникает необходимость выполнить конвертирование одного формата сертификата в другой, каждый раз возникает вопрос: “Как это сделать?”. Наиболее удобно для этого использовать OpenSSL (
openssl.org
), этот сайт содержит исходные коды, если нет желания выполнять компилирование исходных кодов, то можно взять скомпилированный вариант OpenSSL, его можно скачать по ссылке:
https://slproweb.com/products/Win32OpenSSL.html
. Необходимость выполнять конвертирование возникает, если имеющийся формат сертификата не подходит для ПО или оборудования.
Итак, если необходимо выполнить конвертирование одного формата сертификата в другой, то надо скачать и установить OpenSSL на локальном компьютере. Далее, рекомендуется скопировать с папку с OpenSSL имеющиеся файлы сертификата, для которого необходимо выполнить конвертирование, открыть командную строку и перейти в папку с установленным OpenSSL.
Рекомендуется запускать командную строку с от имени администратора (Run As Administrator), это позволит избежать возможных ошибок, если на машине включен UAC.
Для выполнения конвертирования необходимо выполнить одну (или две) команду из списка ниже, в зависимости от исходного формата сертификата и целевого.
Конвертирование x509 в PEM
openssl x509 -in certificate.cer -outform PEM -out certificate.pem Конвертирование PEM в DER
openssl x509 -outform der -in certificate.pem -out certificate.der Конвертирование DER в PEM
openssl x509 -inform der -in certificate.der -out certificate.pem Конвертирование PEM в P7B
openssl crl2pkcs7 -nocrl -certfile certificate.pem -out certificate.p7b -certfile CACert.cer Конвертирование PKCS7 в PEM
openssl pkcs7 -print_certs -in certificate.p7b -out certificate.pem Конвертирование pfx в PEM
openssl pkcs12 -in certificate.pfx -out certificate.pem Конвертирование PFX в PKCS#8
Для этого требуется выполнение двух команд
Step 1:Конвертирование PFX в PEM
openssl pkcs12 -in certificate.pfx -nocerts -nodes -out certificate.pem Step 2:Конвертирование PEM в PKCS8
openSSL pkcs8 -in certificate.pem -topk8 -nocrypt -out certificate.pk8 Конвертирование P7B в PFX
Для этого требуется выполнение двух команд
1. Конвертирование P7B в CER
openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer2. Конвертирование CER и закрытого ключа в PFX
openssl pkcs12 -export -in certificate.cer -inkey privateKey.key -out certificate.pfx -certfile cacert.cer cacert.cer – это файл сертификата выдающего центра сертификации (Intermediate CAs)
Формат der
Это бинарная форма PEM. Файлы с этим форматом сертификата могут иметь окончание .der или .cer.
DER в основном используется для установки на серверахJava. Конвертер позволяет изменять сертификат в формат типа .der, для преобразования ключа необходимо использовать команду OpenSSL.
Формат pem
Самый популярный формат используемый Центрами Сертификации для выписки SSL -сертификатов. В этом формате может выдаваться так же промежуточный или главный CA. Этот тип распознаётся после расширений файла: .pem, .crt, .cer или .key (в файлах содержатся линии BEGIN и END сертификата, ключа и т.д.). Он закодирован в формате Base64.
PEM компатибильный с серверами Apache и подобными. Во время инсталяции большинство серверов требуют отдельные файлы – сертификат(ы) не могут быть соединены с приватным ключём и т.д.
Формат pkcs#12 или pfx
Это бинарный формат, в котором находится сертификат, выданый для домена (интернет-страницы), промежуточные сертификаты и приватный ключ. Файлы обычно имеют окончания .pfx или .p12. Наиболее часто используются для импорта и экспорта сертификатов, а так же приватного ключа на серверах Windows.
Во время изменения формата PFX на PEM, в одном файле будет размещён сертфикат и приватный ключ. С целью их разделения, необходимо открыть файл в текстовом редакторе, скопировать его в отдельные файлы вместе с линиями: BEGIN i END, а затем записать как sertifikat.cer, CA.cer и ключ приватный.key.
Нажмите здесь, чтобы использовать для конвертации команды OpenSSL.
