-
Notifications
You must be signed in to change notification settings - Fork 0
/
Safe64.php
34 lines (28 loc) · 839 Bytes
/
Safe64.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
/**
* Safe64
* Simple Class to encrypt Base64 in PHP
*
* @author Nicolás Giacaman <nicolas.egp@gmail.com>
*
*/
class Safe64 {
// Ref. Token
const B64 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; // Don't touch this
const E64 = 'S30EGnsQCxWAh91NLefB6mwUI8KtFagJzkpvd7ORZV2rPYobji4qDXTyHl5cMu'; // Result by Safe64::token()
// URI Safe
const B = '+/=';
const E = '-_,';
public static function token() {
return str_shuffle(self::B64);
}
public static function encode($Str, $Token = null) {
$Salt = empty($Token) ? self::E64 : $Token;
return strtr(base64_encode($Str), self::B64.self::B, $Salt.self::E);
}
public static function decode($Str, $Token = null) {
$Salt = empty($Token) ? self::E64 : $Token;
return base64_decode(strtr($Str, $Salt.self::E, self::B64.self::B));
}
}
?>