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.
To get asn-one, you have two options:
-
Add a dependency to asn-one to your project.
-
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.
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.
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 requires JDK 17 or newer. The library itself targets Java 8, so it can be used on any Java 8+ runtime.
-
Clone the asn-one repository.
-
Run the command
./gradlew clean build.
- 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
-