# OpenSSL cert conversion

#### Convert PFX to PEM

```bash
openssl pkcs12 -in certificate.pfx -out certificate.cer -nodes
```

#### Convert PEM to PFX

```
 openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt -certfile CACert.crt 
```

#### Convert P7B to PEM

```bash
openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer
```

#### Convert P7B to PFX

{% hint style="info" %}
Note: This requires 2 commands
{% endhint %}

```bash
# Step 1
openssl pkcs7 -print_certs -in certificate.p7b -out certificate.cer

# Step 2
openssl pkcs12 -export -in certificate.cer -inkey privateKey.key -out certificate.pfx -certfile CACert.cer
openssl pkcs7 -print_certs -in old.p7b -out new.crt
```

#### Convert DER to PEM

```bash
openssl x509 -inform der -in certificate.cer -out certificate.pem
```

#### Convert DER to CRT<br>

Use the following command to convert a DER encoded certificate into a PEM encoded certificate:

```bash
openssl x509 -inform DER -in yourdomain.der -outform PEM -out yourdomain.crt
```

Use the following command to convert a DER encoded private key into a PEM encoded private key:

```bash
openssl rsa -inform DER -in yourdomain_key.der -outform PEM -out yourdomain.key
```

#### Convert CER to PEM

```bash
openssl x509 -in cert.cer -out cert.pem
Convert PEM to DER
```

#### Convert PEM to DER

```bash
openssl x509 -outform der -in certificate.pem -out certificate.der
```

#### Convert CRT to DER<br>

Use the following command to convert a PEM encoded certificate into a DER encoded certificate:

```bash
openssl x509 -inform PEM -in yourdomain.crt -outform DER -out yourdomain.der
```

Use the following command to convert a PEM encoded private key into a DER encoded private key:

```bash
openssl rsa -inform PEM -in yourdomain.key -outform DER -out yourdomain_key.der
```

#### Convert PEM to P7B

```
 openssl crl2pkcs7 -nocrl -certfile certificate.cer -out certificate.p7b -certfile CACert.cer 
```

#### Convert CRT to PEM

```bash
openssl x509 -inform DER -outform PEM -in my_certificate.crt -out my_certificate.pem
```

PEM format:

```bash
openssl rsa -inform PEM -in /tmp/ssl.key
```

Check to see if your Certificate is in PEM format:

```bash
openssl x509 -inform PEM -in /tmp/certificate.crt
```
