MIME::...URLSafe(3pm)

πŸ“¦
version 0.01 Β· 2 versions
  • 0.01 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.01 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– MIME::Base64::URLSafe πŸ’–

okay bestie, so this page is from the User Contributed Perl Documentation collection, and it's about MIME::Base64::URLSafe β€” the module that does the URL-safe base64 thing. Pull up a chair, we're decoding this together πŸŽ€


✨ NAME ✨

MIME::Base64::URLSafe β€” it's the Perl version of Python's URL-safe base64 codec. literally a whole port, and it ate πŸ’…


🌸 SYNOPSIS 🌸

here's the vibe, short and sweet:

use MIME::Base64::URLSafe;

$encoded = urlsafe_b64encode('Alladdin: open sesame');
$decoded = urlsafe_b64decode($encoded);

that's it. that's the whole flex ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

so, real talk: this module is a perl version of python's URL-safe base64 encoder / decoder. no cap, that's the whole job.

when you're embedding binary data in a URL, it is preferable to use base64 encoding. sounds great, right? except β€” the two characters '+' and '/' used in the standard base64 encoding have special meanings in URLs, and that often leads to re-encoding with URL-encoding, or worse, interoperability problems 😭 it's giving chaos.

to overcome the problem, the module provides a variation of base64 codec compatible with python's urlsafe_b64encode / urlsafe_b64decode. iconic behaviour, honestly 🫢

here's what gets modified from base64:

use '-' and '_' instead of '+' and '/'
no line feeds
no trailing equals (=)
bestie look closely at that list β€” '-' and '_' come in, '+' and '/'' go out, the line feeds are gone, and the trailing = is gone too. periodt.

the following functions are provided:

urlsafe_b64encode($str)
urlsafe_b64decode($str)

and if you prefer not to import these routines to your namespace β€” totally valid, no pressure β€” you can call them as:

use MIME::Base64::URLSafe ();
$encoded = MIME::Base64::URLSafe::encode($decoded);
$decoded = MIME::Base64::URLSafe::decode($encoded);

iykyk πŸ‘‘


🌈 SEE ALSO 🌈

  • MIME::Base64

fore more discussion on using base64 encoding in URL applications, see: http://en.wikipedia.org/wiki/Base64#URL_Applications


πŸ‘‘ AUTHOR πŸ‘‘

Kazuho Oku <kazuho ___at___ labs.cybozu.co.jp>

Copyright (C) 2006 Cybozu Labs, Inc.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available.


and that's the whole page, bestie β€” this one's from perl v5.36.0, dated 2022-11-27, and yeah the title up top really does say MIME::...URLSafe(3pm) because manpage headers love a little abbreviation moment πŸ™ˆ go forth and encode urlsafely, you've got this πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…

πŸ“¦ where this page comes from