encode_base64url#

Encode bytes using the URL- and filename-safe base64 alphabet, with no padding and no line breaks.

תקציר#

use MIME::Base64 qw(encode_base64url);
my $token = encode_base64url($bytes);

מה מוחזר#

A single unbroken ASCII string using the alphabet [A-Za-z0-9-_]. Trailing = padding is stripped. The result is safe to drop into URLs, path segments, cookie values, and JWT components without percent-escaping. The output is always one line - never wrapped.

דוגמאות#

encode_base64url("Aladdin:open sesame");

## "QWxhZGRpbjpvcGVuIHNlc2FtZQ"

encode_base64url("\xFB\xFF");

## "-_8"                (note the '-' and '_' where '+' and '/' would appear)

encode_base64url("");

## ""

מקרי קצה#

  • Empty input returns the empty string.

  • Bytes that would encode to + under standard base64 become -; bytes that would encode to / become _.

  • No = appears in the output under any input length.

הבדלים מן ה-upstream#

Fully compatible with upstream MIME::Base64 3.16.

ראו גם#

  • decode_base64url - the inverse operation.

  • encode_base64 - standard variant with wrapping and padding.