1
60

urlencrypt

  1. 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
  1. function urlencodebase64($s) {
  2.     return str_replace(array('+', '/', '='), array('-', '_', ''), base64_encode($s));
  3. }
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
  1. function urldecodebase64($s) {
  2.     $s64 = str_replace(array('-', '_' ),array('+', '/'), $s);
  3.  
  4.     $mod4 = strlen($s64) % 4;
  5.     if ($mod4) {
  6.         $s64 .= substr('====', $mod4);
  7.     }
  8.  
  9.     return base64_decode($s64, true);
  10. }
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
  1. function urlencrypt($s, $key) {
  2.     return urlencodebase64(aesencrypt($s, $key));
  3. }
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
  1. function urldecrypt($s64, $key) {
  2.     return rtrim(aesdecrypt(urldecodebase64($s64), $key));
  3. }
SEE ALSO

aesencrypt

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].