Base64 is used commonly in a number of applications including email via MIME, as well as storing complex data in XML or JSON. This encoding helps to ensure that the data remains intact without modification during transport. Base64 encode your data without hassles or decode it into a human-readable format.īase64 encoding schemes are commonly used when there is a need to encode binary data, especially when that data needs to be stored and transferred over media that are designed to deal with text. Copyright 1991 Bell Communications Research, Inc.Meet Base64 Decode and Encode, a simple online tool that does exactly what it says: decodes from Base64 encoding as well as encodes into it quickly and easily. The XS implementation uses code from metamail. The same approach as a command line: perl -MMIME::Base64 -0777 -ne 'print encode_base64($_)' and Joerg Reichelt and code posted to by Hans Mulder Or if you know you have enough memory use MIME::Base64 qw(encode_base64) 57 bytes of data fills one complete base64 line (76 = 57*4/3): use MIME::Base64 qw(encode_base64) This ensures that the base64 lines line up and that you do not end up with padding in the middle. If you want to encode a large file, you should encode it in chunks that are a multiple of 57 bytes. This will return the same value as length(decode_base64($str)), but should be more efficient. Returns the length that the decoded string would have without actually decoding it. This will return the same value as length(encode_base64($bytes)), but should be more efficient. Returns the length that the encoded string would have without actually encoding it. # encoded_base64_length( $bytes ) # encoded_base64_length( $bytes, $eol ) This is a variant of the base64 encoding which does not use padding, does not break the string into multiple lines and use the characters "-" and "_" instead of "+" and "/" to avoid using reserved URL characters. $decoded = MIME::Base64::decode($encoded) Īdditional functions not exported by default: # encode_base64url( $bytes ) # decode_base64url( $str )Įncode and decode according to the base64 scheme for "URL applications". $encoded = MIME::Base64::encode($decoded) If you prefer not to import these routines into your namespace, you can call them as: use MIME::Base64 () Characters occurring after a '=' padding character are never decoded. This function takes a single argument which is the string to decode and returns the decoded data.Īny character not part of the 65-character base64 subset is silently ignored. # decode_base64( $str )ĭecode a base64 string by calling the decode_base64() function. Use the Encode module to select the byte encoding you want. The base64 encoding is only defined for single-byte characters. The function will croak with "Wide character in subroutine entry" if $bytes contains characters with code above 255. Pass an empty string as second argument if you do not want the encoded string to be broken into lines. The returned encoded string is broken into lines of no more than 76 characters each and it will end with $eol unless it is empty. The second argument is the line-ending sequence to use. The first argument is the byte string to encode. The following primary functions are provided: # encode_base64( $bytes ) # encode_base64( $bytes, $eol ) Įncode data by calling the encode_base64() function. A 65-character subset () of US-ASCII is used, enabling 6 bits to be represented per printable character. The base64 encoding is designed to represent arbitrary sequences of octets in a form that need not be humanly readable. This module provides functions to encode and decode strings into and from the base64 encoding specified in RFC 2045 - MIME (Multipurpose Internet Mail Extensions). $decoded = decode_base64($encoded) #DESCRIPTION $encoded = encode_base64('Aladdin:open sesame') MIME::Base64 - Encoding and decoding of base64 strings #SYNOPSIS use MIME::Base64
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |