60
urlencrypt
- require_once 'aesencrypt.php';
urlencodebase64
SYNOPSIS
urlencodebase64($s)
DESCRIPTION
urlencodebase64 returns the URL and filename safe Base64 encoding of the string $s.
EXAMPLE
To encode a string:
php > require 'library/urlencrypt.php';
php > $s=urlencodebase64('https://www.izend.org');
php > echo $s;
aHR0cHM6Ly93d3cuaXplbmQub3Jn
CODE
- function urlencodebase64($s) {
- return str_replace(array('+', '/', '='), array('-', '_', ''), base64_encode($s));
- }
urldecodebase64
SYNOPSIS
urldecodebase64($s)
DESCRIPTION
urldecodebase64 returns the string decoded from the URL and filename safe Base64 encoded string $s.
If $s cannot be decoded, urldecodebase64 returns false.
EXAMPLE
To decode a string:
php > require 'library/urlencrypt.php';
php > $s=urlencodebase64('https://www.izend.org');
php > echo urldecodebase64($s);
https://www.izend.org
CODE
- function urldecodebase64($s) {
- $s64 = str_replace(array('-', '_' ),array('+', '/'), $s);
- $mod4 = strlen($s64) % 4;
- if ($mod4) {
- $s64 .= substr('====', $mod4);
- }
- return base64_decode($s64, true);
- }
urlencrypt
SYNOPSIS
urlencrypt($s, $key)
DESCRIPTION
urlencrypt returns the URL and filename safe Base64 encoding of the AES-256-CBC encryption of the URL $s with the key $key.
EXAMPLE
To encrypt a URL:
php > require 'library/urlencrypt.php';
php > $secretkey=openssl_random_pseudo_bytes(32);
php > $url='https://www.izend.org';
php > $s=urlencrypt($url, $secretkey);
php > echo strlen($s);
80
CODE
- function urlencrypt($s, $key) {
- return urlencodebase64(aesencrypt($s, $key));
- }
urldecrypt
SYNOPSIS
urldecrypt($s, $key)
DESCRIPTION
urldecrypt returns the URL decrypted from the URL and filename safe Base64 encoded AES-256-CBC encrypted string $s64 with the key $key.
EXAMPLE
To decrypt an encrypted URL:
php > require 'library/urlencrypt.php';
php > $secretkey=openssl_random_pseudo_bytes(32);
php > $url='https://www.izend.org';
php > $s=urlencrypt($url, $secretkey);
php > echo urlencrypt($s, $secretkey);
https://www.izend.org
CODE
- function urldecrypt($s64, $key) {
- return rtrim(aesdecrypt(urldecodebase64($s64), $key));
- }
Comments