Skip to main content

asn1js — ASN.1 BER/DER encoder and decoder for JavaScript

Encode, decode, and validate ASN.1 data in browsers and Node.js. asn1js ships TypeScript types and is the foundation of PKIjs, so it handles the structures behind X.509 certificates, PKCS, CMS, and LDAP.

Features

  • BER and DER encoding and decoding

    Decode bytes into a tree of ASN.1 objects with fromBER() and encode them back with toBER(). Every tag, length, and value block stays accessible, byte by byte.

  • All ASN.1 types, as JavaScript values

    Supports the universal types of ASN.1:2008. Integers convert to bigint, object identifiers to dotted strings, string types to string, and time types to Date.

  • Schema validation

    Describe the structure you expect, then validate and extract fields by name in one step. Optional fields, Any, Choice, and Repeated cover real-world modules.

  • Every tag class

    Universal, application, context-specific, and private tags, with explicit and implicit tagging, and constructed or primitive encoding.

  • Safe parsing of untrusted input

    Limits on nesting depth, node count, and content length stop malicious input before it exhausts memory or the call stack.

  • Tested against the ASN.1:2008 test suite

    Checked against the freely available ASN.1:2008 test suite, and used in production through PKIjs.