Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@peculiar/asn1-x509

Package Overview
Dependencies
Maintainers
6
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

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)

  • 2.3.6
  • npm
  • Socket score

Version published
Maintainers
6
Created

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

Keywords

FAQs

Package last updated on 13 Mar 2023

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc