Skip to content
hierynomusPublic

About

A Standalone ASN.1 Encoding/Decoding Library in Java

Resources

Stars

42 stars

Watchers

2 watching

Forks

Repository files navigation

asn-one - ASN.1 library for Java

Build Status Code coverage Javadoc Maven Central

What is asn-one

asn-one is a pure Java implementation of an ASN.1 encoder and decoder. It supports the BER and DER encoding rules of the bytestream. It is designed to be as lightweight as possible by having minimized the external dependencies. It only depends on the SLF4J logging API.

Getting asn-one

To get asn-one, you have two options:

  1. Add a dependency to asn-one to your project.

  2. Build asn-one yourself.

Binary releases of asn-one are not provided here, but you can download it straight from the Maven Central repository if you want to.

Depending on asn-one

If you’re building your project using Maven, you can add the following dependency to the pom.xml:

<dependency>
  <groupId>com.hierynomus</groupId>
  <artifactId>asn-one</artifactId>
  <version>0.7.0</version>
</dependency>

If your project is built using another build tool that uses the Maven Central repository, translate this dependency into the format used by your build tool.

Reading ASN.1

Input must be BER or DER encoded. PEM files (-----BEGIN …​-----) need to be Base64 decoded first.

ASN1InputStream is = new ASN1InputStream(new BERDecoder(), bytes);
ASN1Sequence certificate = is.readObject();

By default, decoding is strict: an object with a UNIVERSAL tag that asn-one has no specific type for causes an ASN1ParseException, so a successful parse means every object was understood. To read any well-formed structure instead, use a lenient decoder, which keeps such objects as an ASN1UnknownObject with their raw contents:

ASN1InputStream is = new ASN1InputStream(BERDecoder.lenient(), bytes);

The setting also applies to tagged objects whose contents are decoded later on, through ASN1TaggedObject.getObject().

Building asn-one

Building requires JDK 17 or newer. The library itself targets Java 8, so it can be used on any Java 8+ runtime.

  1. Clone the asn-one repository.

  2. Run the command ./gradlew clean build.

Release History

v0.7.0 (2023-03-06)
  • Add support for Java Modules

v0.6.0 (2021-09-27)
  • Fix Java module name

  • Fix bug in parsing Tag numbers

v0.4.0 (2018-10-11)
  • Moved groupID to 'com.hierynomus' to be in line with other libraries

v0.3.0 (2018-10-10)
  • Implemented serialization and deserialization in streams

v0.2.0 (unreleased)
v0.1.0 (2016-11-25)
  • Initial release, containing most standard types

About

A Standalone ASN.1 Encoding/Decoding Library in Java

Resources

Stars

42 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages