Skip to content
This repository has been archived by the owner on Jun 20, 2018. It is now read-only.

Commit

Permalink
make paranoia encrypted string url friendly
Browse files Browse the repository at this point in the history
  • Loading branch information
highstrike committed Sep 30, 2016
1 parent 725d6ed commit 31b0e19
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/Lib/Paranoia.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
* // controller
* use Unimatrix\Utility\Lib\Paranoia;
*
* $encrypted = Paranoia::encrypt('string_to_encrypt'));
* $encrypted = Paranoia::encrypt('string_to_encrypt');
* $decrypted = Paranoia::decrypt('string_to_decrypt');
*
* @author Flavius
* @version 0.2
* @version 0.3
*/
class Paranoia {
/**
Expand All @@ -41,7 +42,7 @@ private static function secret($s = null) {
* @return null|string
*/
public static function encrypt($a = null, $s = null) { $s = self::secret($s);
return is_null($a) ? null : strtr(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($s), serialize($a), MCRYPT_MODE_CBC, md5($s))), '+/=', '-_@');
return is_null($a) ? null : strtr(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($s), serialize($a), MCRYPT_MODE_CBC, md5($s))), '+/=', '-_.');
}

/**
Expand All @@ -52,6 +53,6 @@ public static function encrypt($a = null, $s = null) { $s = self::secret($s);
* @return null|string
*/
public static function decrypt($a = null, $s = null) { $s = self::secret($s);
return is_null($a) ? null : unserialize(rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($s), base64_decode(strtr($a, '-_@', '+/=')), MCRYPT_MODE_CBC, md5($s)), "\0"));
return is_null($a) ? null : unserialize(rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($s), base64_decode(strtr($a, '-_.', '+/=')), MCRYPT_MODE_CBC, md5($s)), "\0"));
}
}

0 comments on commit 31b0e19

Please sign in to comment.