Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

@peculiar/asn1-x509

Package Overview
Dependencies
6
Maintainers
6
Versions
44
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @peculiar/asn1-x509

ASN.1 schema of `Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile` (RFC5280)


Version published
Weekly downloads
263K
increased by75.54%
Maintainers
6
Created
Weekly downloads
 

Package description

What is @peculiar/asn1-x509?

@peculiar/asn1-x509 is an npm package that provides tools for working with ASN.1 (Abstract Syntax Notation One) and X.509 certificates. It allows developers to parse, encode, and manipulate X.509 certificates and related structures in JavaScript.

What are @peculiar/asn1-x509's main functionalities?

Parsing X.509 Certificates

This feature allows you to parse a raw X.509 certificate from a binary format (BER). The code sample demonstrates how to convert a base64-encoded certificate into a Certificate object.

const { Certificate } = require('@peculiar/asn1-x509');
const rawCert = Buffer.from('MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1J...', 'base64');
const cert = Certificate.fromBER(rawCert);
console.log(cert);

Encoding X.509 Certificates

This feature allows you to encode an X.509 certificate into a binary format (BER). The code sample demonstrates how to create a Certificate object and convert it into a base64-encoded string.

const { Certificate } = require('@peculiar/asn1-x509');
const cert = new Certificate({
  tbsCertificate: {
    version: 2,
    serialNumber: new Uint8Array([1, 2, 3, 4]),
    signature: { algorithm: '1.2.840.113549.1.1.11' },
    issuer: { type: 'rdnSequence', value: [] },
    validity: { notBefore: new Date(), notAfter: new Date() },
    subject: { type: 'rdnSequence', value: [] },
    subjectPublicKeyInfo: { algorithm: { algorithm: '1.2.840.113549.1.1.1' }, subjectPublicKey: new Uint8Array([1, 2, 3, 4]) }
  },
  signatureAlgorithm: { algorithm: '1.2.840.113549.1.1.11' },
  signatureValue: new Uint8Array([1, 2, 3, 4])
});
const rawCert = cert.toSchema().toBER(false);
console.log(Buffer.from(rawCert).toString('base64'));

Manipulating Certificate Extensions

This feature allows you to manipulate extensions within an X.509 certificate. The code sample demonstrates how to add a new extension to a Certificate object.

const { Certificate, Extension } = require('@peculiar/asn1-x509');
const cert = new Certificate();
const ext = new Extension({
  extnID: '2.5.29.14',
  critical: false,
  extnValue: new Uint8Array([1, 2, 3, 4])
});
cert.tbsCertificate.extensions = [ext];
console.log(cert.tbsCertificate.extensions);

Other packages similar to @peculiar/asn1-x509

Readme

Source

@peculiar/asn1-x509

License npm version

NPM

RFC 5280 Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile.

Keywords

FAQs

Last updated on 19 May 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc