cert2json v1.0.13
About The Project
This project converts x509 certificates into JSON format. It provides both a command line interface and an API.
Getting Started
To get a local copy up and running follow these simple steps.
Install CLI
Run the following command to install the CLI
npm install -g cert2json
Install API
In your npm package install the dependency
npm install cert2json
Usage
CLI Example
The CLI will print the JSON. You can use jq to process the output. Below is an example printing the certificate issuer.
➜ cert2json -h
usage: cert2json file
➜ cert2json google.com.cer | jq '.tbs.issuer.full'
"C=US, O=Google Trust Services, CN=GTS CA 1O1"
➜
API Examples
Import cert2json and call parseFromFile. The certificate can be DER or PEM format.
// Import the library
const cert2json = require('cert2json')
// Parse the certificate, resulting in a JSON object
const cert = cert2json.parseFromFile('./certificates/google.com.cer')
// Print the issuer
console.log(cert.tbs.issuer.full)
Results in:
C=US, O=Google Trust Services, CN=GTS CA 1O1
Alternatively you can parse the certificate from memory. The parse function expects a Buffer containing the certificate data.
// Import the library
const cert2json = require('cert2json')
const fs = require('fs')
// Read the certificate into a buffer
const certificatePath = './certificates/example.com.cer'
const certificateBuffer = fs.readFileSync(certificatePath)
// Parse the buffer contents
const cert = cert2json.parse(certificateBuffer)
// Print the certificate
console.log(JSON.stringify(cert, null, 2))
Contributing
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
License
Distributed under the MIT License. See LICENSE
for more information.