The Base64 module provides for the encoding (#encode64) and decoding (#decode64) of binary data using a Base64 representation.
The following particular features are also provided:
- encode into lines of a given length (#b64encode)
- decode the special format specified in RFC2047 for the representation of email headers (decode_b)
Example
A simple encoding and decoding.
require "base64" enc = Base64.encode64('Send reinforcements') # -> "U2VuZCByZWluZm9yY2VtZW50cw==\n" plain = Base64.decode64(enc) # -> "Send reinforcements"
The purpose of using base64 to encode data is that it translates any binary data into purely printable characters. It is specified in RFC 2045 (www.faqs.org/rfcs/rfc2045.html).
| Modules | |
|---|---|
| Deprecated | |
| Public Methods | |
|---|---|
| b64encode | Prints the Base64 encoded version of bin (a String) in lines of len (default 60) characters. |
| decode64 | Returns the Base64-decoded version of str. |
| decode_ |
Decodes text formatted using a subset of RFC2047 (the one used for mime-encoding mail headers). |
| encode64 | Returns the Base64-encoded version of str. |
<code/>and<pre/>for code samples.