Different output after decode and encode data (base64)
<p>If i run:</p>

<pre><code>import base64
data = open('1.dat', 'rb').read()
decoded = base64.b64decode(data)
encoded = base64.b64encode(decoded)
data == encoded
</code></pre>

<p>I get "False" as result?
How to decode/encode to get the original result?</p>

<p>You have to <code>b64encode()</code> the data before you <code>b64decode()</code> it:</p>

<pre><code>&gt;&gt;&gt; import base64
&gt;&gt;&gt; data = b"qwertzuiop"
&gt;&gt;&gt; encoded = base64.b64encode(data)
&gt;&gt;&gt; decoded = base64.b64decode(encoded)
&gt;&gt;&gt; data == decoded
True
</code></pre>

<p>If your input file is already base64, you need to <code>b64decode()</code> it first, not encode. So your code should be this: </p>

<pre><code>import base64
data = open('1.dat', 'rb').read()  # base64 encoded string
decoded = base64.b64decode(data)
encoded = base64.b64encode(decoded)
data == encoded
</code></pre>

<p>If you are getting False as a result, your <code>data</code> is Base64 encoded differently than what the <code>base64</code> module does.</p>

python base64