Skip to content

Instantly share code, notes, and snippets.

@itorgov
Forked from nathggns/base64url.php
Last active March 6, 2020 10:30
Show Gist options
  • Save itorgov/25882f7ff4001413078a7c2fb2cf2bcd to your computer and use it in GitHub Desktop.
Save itorgov/25882f7ff4001413078a7c2fb2cf2bcd to your computer and use it in GitHub Desktop.
These two functions implement base64url functionality for PHP.
<?php
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
function base64url_decode($data) {
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment