# De-compiling .pfx file

In the previous note we have taken insights how can we make a .pfx format file for our SSL work , Many vendors & certificate issuers provide the pfx format as their ssl for the purchased domain. So now we will take insights how to de-compile the pfx file & the the following files from it :&#x20;

* CA Certificate (Root CA)
* Private Key (.key)
* CA-Chain (.bundle)

***

{% hint style="info" %}
Reference Website :&#x20;

<https://www.ibm.com/docs/en/arl/9.7?topic=certification-extracting-certificate-keys-from-pfx-file>
{% endhint %}

Here we have obtained the pfx file from the domain provider and now we will extract the necessary files above mentioned using openssl

<figure><img src="https://2332860236-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq6mjlFfyDOi3mV0lemKE%2Fuploads%2FyZ23a2xX74lwy9lYxW8Y%2Fimage.png?alt=media&#x26;token=debf5993-8e21-4db8-8fc3-a6c81192ba4b" alt=""><figcaption><p>pfx file obtained from the SSL Provider</p></figcaption></figure>

Now we will extract the files one by one ,  Extracting the private key first from the pfx file

```
~ Extracting the private key from the pfx file : 
# openssl pkcs12 -in wildcard_ghoulsec.pfx -nocerts -out private.key -nodes
```

We have extracted the private key now we will extract the ca certificate also known as the root ca certificate

```
~ Extracting the ca certificate from the pfx file :
# openssl pkcs12 -in wildcard_ghoulsec.pfx -clcerts -nokeys -out ca.crt
```

We have extracted the certificate of the domain and now we will extract the CA-chain file in which we can get the root ca file bundled which can later be used to sign the certificates.

```
~ Extracting the ca-chain certificate bundle from the pfx file :
# openssl pkcs12 -in wildcard_ghoulsec.pfx -cacerts -nokeys -out ca-chain.bundle
```

Now we have generated all the necessary files now we will verify that all the files extracted are integral to the main pfx package file.

<figure><img src="https://2332860236-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq6mjlFfyDOi3mV0lemKE%2Fuploads%2FgDWbz0sQH9CB2pjFHghH%2Fimage.png?alt=media&#x26;token=23884992-f137-4f4d-a249-8cf90a7f912d" alt=""><figcaption></figcaption></figure>

Check the modulus of the private key:

```
~ Compare the output of the following commands : 
# openssl rsa -in private.key -noout -modulus
# openssl x509 -in ca.crt -noout -modulus
```

Check the output of the following command :&#x20;

```
# openssl verify -CAfile ca-chain.bundle ca.crt
The output of the following command look like :
```

<figure><img src="https://2332860236-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq6mjlFfyDOi3mV0lemKE%2Fuploads%2FLFiDJvwwp4OvAXVitCbk%2Fimage.png?alt=media&#x26;token=c36568c5-b3c7-4540-825f-e0d8c45f771d" alt=""><figcaption></figcaption></figure>

***
