<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: binascii code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 07 Sep 2008 09:16:32 GMT</pubDate>
    <description>DZone Snippets: binascii code</description>
    <item>
      <title>Using base64 to encode/decode data</title>
      <link>http://snippets.dzone.com/posts/show/1618</link>
      <description>If you have binary data, you can encode it with&lt;br /&gt;ascii character to store it more safely.&lt;br /&gt;base64 module is an efficient choice to do so.&lt;br /&gt;It uses characters from this set&lt;br /&gt;('=' is used for padding at the end.)&lt;br /&gt;&lt;code&gt;&lt;br /&gt;ABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;br /&gt;abcdefghijklmnopqrstuvwxyz&lt;br /&gt;0123456789+/&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;Here's how to use it.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt;&gt;&gt; import base64&lt;br /&gt;&gt;&gt;&gt; base64.encodestring('hello world')&lt;br /&gt;'aGVsbG8gd29ybGQ=\n'&lt;br /&gt;&gt;&gt;&gt; base64.decodestring(_)&lt;br /&gt;'hello world'&lt;br /&gt;&gt;&gt;&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;If the text is long, the base64 module will split&lt;br /&gt;the encoded data into multiple lines.&lt;br /&gt;If you don't wan't it to be split. You can use&lt;br /&gt;binascii.b2a_base64 instead of base64.encodestring and&lt;br /&gt;binascii.a2b_base64 instead of base64.decodestring&lt;br /&gt;</description>
      <pubDate>Thu, 02 Mar 2006 19:28:38 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1618</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
  </channel>
</rss>
