ASN1C icon ASN1C ASN.1 Compiler

The ASN1C ASN.1 compiler translates ASN.1 and/or XML schema (XSD) source specifications into C, C++, C#, Java, or Python source code. Developers can use this code to translate structures/objects to and from finished ASN.1 messages using ITU-T/ISO encoding rules BER, CER, DER, OER, PER, UPER, JER(JSON), or XER(XML). ASN1C also includes tools for converting XSD specifications to ASN.1 specifications and vice versa.

ASN.1 compiler

ASN1C generated code consists of type definitions and encode/decode functions (or methods) that provide a complete Application Programming Interface (API) for working with the message definitions contained within an ASN.1 specification.

In addition to the ASN.1 compiler, a run-time library of common encode/decode functions is also part of the package. This library contains routines to encode and decode ASN.1 primitives (BOOLEAN, INTEGER, etc.). The ASN1C ASN.1 compiler assembles a series of calls to these functions to accomplish the encoding or decoding of more complex message types.

All that a programmer needs to do to get an encoder/decoder up and running is to:

  1. Run ASN1C to generate code for a given ASN.1 or XSD specification,
  2. Develop an application to call functions/methods within the generated code,
  3. Compile/link the application, generated code, and run-time libraries.

To assist with items 2 and 3, the compiler also has the capability to generate sample reader and writer programs as well as a makefile to build all of the generated code.

ASN.1 to C/C++

Both the C and C++ version use a common base run-time library consisting of a set of low-level primitive C functions for encoding and decoding the base types. The code generation is done predominantly in C and provides a complete set of C API functions for all defined ASN.1 types.

The C++ code generation capability adds a set of class "wrappers" that hide most of the details in invoking the encode/decode functions. These wrappers provide additional services specific to C++. These include automatic initialization of variables of generated types through constructors, easier assignment and testing of data through operator overloading, and virtual callback interfaces through the event handling mechanism.

ASN.1 to Java or C#

The generated Java code consists of a series of Java source files - one for each production (type) defined within an ASN.1 specification. Each of these Java files contains (at a minimum) the following items:

  • A public member data variable (or variables) to hold data of the generated type.
  • A constructor (or constructors) to initialize the variable.
  • An encode method.
  • A decode method.
  • A print method to print the contents of the object to a given output stream.

There is also a run-time library for Java. This consists of a series of classes for encoding and decoding the primitive ASN.1 types. For example, the Asn1Integer class will encode or decode a variable of the ASN.1 INTEGER type. The compiler will extend these base classes to form higher level types derived directly from the base types, or assemble a series of these lower level objects to form constructed types (SEQUENCE, for example).

Generation of C# code is very similar to the Java generation described above. A separate C# class is generated for each production defined in an ASN.1 specification. This contains constructors and methods for encoding and decoding an instance of the class using any of the ASN.1 encoding rules.

Java or C# embedded development kits are available which support the Java MicroEdition (J2ME) or C# compact edition libraries.

Read More - ASN1C Compiler FAQ...


The ASN1C Eclipse plugin allows editing, syntax checking and code generation of Java, C#, or C/C++ code within the Eclipse IDE environment using ASN1C. It is integrated with the Java perspective in such a way as to allow Java projects to be created directly from ASN.1 source code.

Note that the plugin is functional with Eclipse 4.6 (Neon) and later versions. Earlier versions of Eclipse are not supported.

Download and Installation

The recommended method for plugin installation is via our plug-in update site, Follow these steps:

  1. Select Help -> Install New Software
  2. Enter our update site for the "Work with" location: ''
  3. The available plug-ins should appear in the list
  4. Enable the checkbox next to "ASN.1 and XML Solutions" and click Next
  5. Click Next in the next page
  6. Select acceptance of the license terms and click Finish in the next page
  7. Click Yes to restart Eclipse

Alternatively, the plug-in can be downloaded as a .zip file and then installed. Click on the following link to download the file:

ASN1C Eclipse Plug-in .zip file

Follow these steps to install the plugin after downloading it:

  1. Select Help -> Install New Software
  2. Click the Add button
  3. Click the Archive button in the pop-up page
  4. Locate the downloaded zip file and select OK
  5. Enable the checkbox next to "ASN.1 and XML Solutions" and click Next
  6. Click Next in the next page
  7. Select acceptance of the license terms and click Finish in the next page
  8. Click Yes to restart Eclipse

Getting Started with the Plugin

Once installed, the path to the ASN1C compiler command-line executable must be set. This is done as follows:

  1. Select Windows -> Preferences -> ASN1C Compiler
  2. In the compiler path box, use Browse or enter the full path to the ASN1C compiler command-line executable file (i.e. asn1c/asn1c.exe, not acgui/acgui.exe)
  3. Click OK to exit the screen

A new project can now be created. We will use the ASN1C Java Employee program as a sample.

  1. Select Windows -> Preferences -> ASN1C Compiler
  2. Click the "Language" drop-down list and select 'Java' as the application language
  3. Click the "Select encoding rules" drop-down list and select the 'BER' option
  4. Click the "Select Function Types to be generated" drop-down list and check the 'Encode' and 'Decode' options
  5. Click the "Basic options" drop-down list and select the 'Generate sample reader program' and 'Generate sample writer program' options
  6. Click the "Java options" drop-down list and select the 'Output code to module name dirs (-dirs)' option
  7. Click OK to exit the preferences screen
  8. Select File -> New -> Project...
  9. Under 'ASN1 Compiler Tools', select 'ASN1C compiler Project' and click 'Next'
  10. Set project name to 'Employee' and click 'Next'
  11. ASN.1 files may now be added to the project using the 'Add file' button. Click this button and navigate to the ASN1C java/sample_ber/Employee directory and select employee.asn. Then click 'Next'.
  12. Click Next in the next page (Java Settings)
  13. On the final page (ASN1C compiler command), check the 'Launch ASN.1 Compiler on finish' option and click 'Finish'. The ASN1C compiler should now attempt to generate the Java files.


Download button