Python-ASN1 is a simple ASN.1 encoder and decoder for Python 2.6+ and 3.3+.
- Support BER (parser) and DER (parser and generator) encoding
- 100% python, compatible with version 2.6, 2.7, 3.3 and higher
- Can be integrated by just including a file into your project
Python-ASN1 relies on Python-Future for Python 2 and 3 compatibility. To install Python-Future:
pip install future
Install from PyPi with the following:
pip install asn1
or download the repository from GitHub and install with the following:
python setup.py install
You can also simply include asn1.py
into your project.
Note
You can find more detailed documentation on the Usage page.
If you want to encode data and retrieve its DER-encoded representation, use code such as:
import asn1
encoder = asn1.Encoder()
encoder.start()
encoder.write('1.2.3', asn1.ObjectIdentifier)
encoded_bytes = encoder.output()
If you want to decode ASN.1 from DER or BER encoded bytes, use code such as:
import asn1
decoder = asn1.Decoder()
decoder.start(encoded_bytes)
tag, value = decoder.read()
The complete documentation is available on Read The Docs:
Python-ASN1 is free software that is made available under the MIT license. Consult the file LICENSE that is distributed together with this library for the exact licensing terms.
The following people have contributed to Python-ASN1. Collectively they own the copyright of this software.
- Geert Jansen (geert@boskant.nl): original implementation.
- Sebastien Andrivet (sebastien@andrivet.com)