9

Is there a free package for reading, manipulating and writing ASN.1 in Java?

It must be:

  1. Free
  2. Lightweight
  3. Self-contained (without external dependencies on, e.g. Apache commons)
  4. Java 5 (not Java 6), and Java 4 is preferred.
Lawrence Dol
  • 63,018
  • 25
  • 139
  • 189

4 Answers4

5

The following project looks promising:

http://www.chaosinmotion.com/wiki/index.php?title=ASN.1_Library

It is provided under a liberal BSD-style licence.

It is small, 41 classes compiling to 55KiB.

It compiled clean with no dependencies to Java 3.

Robert
  • 39,162
  • 17
  • 99
  • 152
Lawrence Dol
  • 63,018
  • 25
  • 139
  • 189
2

You could use jASN1. It is licensed under LGPL and should satisfy all of your needs. It is also very efficient.

Stefan Feuerhahn
  • 1,564
  • 1
  • 14
  • 22
2

The free BouncyCastle library provides low-level ASN.1 parsing. You don't need to install BC as a provider to use the ASN.1 capabilities. It has different versions for 1.4 and up. It has no external dependencies. As the default bundle contains all of the BC provider classes, you may want to repackage it if you want something more compact.

erickson
  • 265,237
  • 58
  • 395
  • 493
  • It's a viable option, but it doesn't really seem to meet the light-weight requirement (I consider light-weight to be under 50K). – Lawrence Dol May 12 '09 at 00:26
  • Yes, I wrote my own decoder class. It's about 200 lines of code, maybe. I've been using it for over 10 years, and I'd like to refactor it to provide a different interface, but it has definitely met the need. – erickson May 12 '09 at 02:42
  • @Erickson: Any chance you want to share it? (Although it is a low priority for me now that I have resolved my immediate problems with a PKCS#12 keystore, so no rush). – Lawrence Dol May 13 '09 at 22:39
  • Looking more closely at BC, it's a looonnnggg way from light-weight (nearly 400 classes - and separating out the non-core classes from core would be a lot of work). – Lawrence Dol May 13 '09 at 22:40
  • The code I wrote already is not mine to share. But I am thinking about writing my own decoder that would be event-oriented, like a SAX parser. If I do that I would be willing to share. – erickson May 14 '09 at 16:58
0

I need to be able to parse any kind of ASN.1 data in krypt. Although krypt is a Ruby project, you may want to have a look at the JRuby extension - the code for handling ASN.1 parsing/encoding is written entirely in Java and modular enough for easy extraction.

I also made a Java-only version, but it is missing some of the higher-level functionality of the former. But since it's concise, maybe it's a good opportunity to get you started.

Both are free of any additional dependencies and use only standard JDK functionality.

emboss
  • 38,880
  • 7
  • 101
  • 108