Skip to content
Advertisement

How do I read(open) an ASN.1 file in python

I want to get a certificates serial number using python:

JavaScript

Unfortunately it fails in the first line:

JavaScript

How do I read an ASN.1 file format (DER) in Python?

Advertisement

Answer

You are opening the file as a text file, which means read tries to decode the data using UTF-8 in order to return a str object.

Instead, open it as a binary file, so that read simply returns a bytes object without trying to decode the data at all.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement