Book HomeJava and XSLTSearch this book

8.148. MIME::Base64

Provides functions to encode and decode strings into the Base64 encoding scheme as specified in RFC 2045 (dealing with MIME, or Multipurpose Internet Mail Extensions). Base64 encoding was designed to represent data in octets in an encoded form; all data is encoded using a 65-character subset, which is comprised of A-Z, a-z, 0-9+, /, and =. MIME::Base64 ships with the Perl source kit as of 5.8.

For example:

#!/usr/local/bin/perl -w
use MIME::Base64;
my $stone = 'purplebarneystone';
my $b64 = encode_base64($stone);
print "$b64\n";

MIME::Base64 implements the following functions, both of which are exported.

decode_base64

decode_base64(string)

Unpacks the base64-encoded string and returns the decoded data. In addition, decode_base64 ignores any character that's not part of the recognized 65-character base64 subset.

encode_base64

encode_base64(string, [end_of_line])

Base64-encodes string with the optional end_of_line argument. To base64-encode a JPEG image that lives in a file, you should specify end_of_line, since encode_base64 returns base64-encoded content that's broken down into 76 characters per line. If you do not want the 76-character breaks to be imposed on you, set end_of_line to an empty string ("").



Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.