MIME::Base64#
Native implementation of MIME::Base64
Provides base64 encoding and decoding functions compatible with Perl’s MIME::Base64 module. Since PetaPerl does not support XS, this module is implemented directly in Rust.
Synopsis#
use MIME::Base64;
my $encoded = encode_base64("Hello, World!");
my $decoded = decode_base64($encoded);
# Suppress line breaks
my $oneline = encode_base64($data, "");
# URL-safe variant
use MIME::Base64 'encode_base64url';
my $token = encode_base64url($data);
Functions#
encode_base64#
Encode binary data to base64. An optional second argument specifies the end-of-line sequence inserted every 76 characters (default: “\n”). Pass “” to suppress line breaks.
use MIME::Base64;
my $encoded = encode_base64("Hello, World!");
my $oneline = encode_base64($data, "");
decode_base64#
Decode a base64-encoded string back to the original binary data. Whitespace in the input is silently ignored.
use MIME::Base64;
my $decoded = decode_base64("SGVsbG8sIFdvcmxkIQ==");
encode_base64url#
Encode binary data using the URL-safe base64 alphabet (- and _ instead
of + and /), without padding or line breaks.
use MIME::Base64 'encode_base64url';
my $token = encode_base64url($data);
decode_base64url#
Decode a URL-safe base64-encoded string back to binary data.
use MIME::Base64 'decode_base64url';
my $data = decode_base64url($token);
encoded_base64_length#
Return the length of the string that encode_base64 would produce for the given data, without actually encoding it.
decoded_base64_length#
Return the length of the data that decode_base64 would produce for the given encoded string, without actually decoding it.
Standard Base64 Alphabet#
Standard: A-Z, a-z, 0-9, +, / with = padding
URL-safe: A-Z, a-z, 0-9, -, _ without padding