]> git.immae.eu Git - github/shaarli/Shaarli.git/blame - application/http/Base64Url.php
Merge pull request #1345 from ArthurHoaro/changelog-v0.11.1
[github/shaarli/Shaarli.git] / application / http / Base64Url.php
CommitLineData
7a9daac5
V
1<?php
2
00af48d9 3namespace Shaarli\Http;
7a9daac5 4
7a9daac5
V
5/**
6 * URL-safe Base64 operations
7 *
8 * @see https://en.wikipedia.org/wiki/Base64#URL_applications
9 */
10class Base64Url
11{
12 /**
13 * Base64Url-encodes data
14 *
15 * @param string $data Data to encode
16 *
17 * @return string Base64Url-encoded data
18 */
f211e417
V
19 public static function encode($data)
20 {
7a9daac5
V
21 return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
22 }
23
24 /**
25 * Decodes Base64Url-encoded data
26 *
27 * @param string $data Data to decode
28 *
29 * @return string Decoded data
30 */
f211e417
V
31 public static function decode($data)
32 {
7a9daac5
V
33 return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
34 }
35}