title: How to decode .BER using ASN1 Library in Python
body: <p>I have an encoded file with .BER format that I can't decode. </p>
  
  <p>After searching, I got that I need to use ASN1 library to be able to decode this file and to be readable.</p>
  
  <p>Can someone guide me how to decode .BER file using ASN1 library on python?</p>
  
  <p>I have checked online and found that there are some online ASN1 decoder that correctly decode my file. However, I won't be able to use them as I need to decode it on my own not using an online tool. I don't know how to get this tag and value in the script below.</p>
  
  <p>import asn1
   import re
   import os
   import future
   Input_directory=open("D:\Encoded_Nokia.ber","rb")</p>
  
  <p>for lines in Input_directory:
       decoder = asn1.Decoder()
       output=decoder.start(lines)
       <code>tag,output=decoder.read()</code></p>
  
  <p>Those are the errors i got:</p>
  
  <pre><code>  File "C:\Python34\lib\site-packages\asn1.py", line 421, in read
      value = self._read_value(tag.nr, length)
    File "C:\Python34\lib\site-packages\asn1.py", line 508, in _read_value
      bytes_data = self._read_bytes(length)
    File "C:\Python34\lib\site-packages\asn1.py", line 541, in _read_bytes
      raise Error('Premature end of input.')
  asn1.Error: Premature end of input.
  </code></pre>