Looking for built in encryption functions, not to hide the string from the clever programmer, but instead just to obfuscate it a bit. Looking for functions such as str_rot13
and base64_encode
, but I can't seem to locate any. Surely there are more?
views:
86answers:
4You're looking for obfuscation algorithms, not encryption algorithms?
Base 64 and mcrypt are the easiest to encode decode quickly. If you're looking for obfuscation, use those.
Base 64 and Rot 13 are not encryption as they can easily be encoded and decoded.
Encrytpion functions are more like md5, sha1 and crypt. MD5 is considered "broken" so, you should use sha1 for encryption, or at the very least salt your MD5 when hashing.
If you only need to obfuscate a little bit, try the strtr()
function. It exists to swap out characters in a string - perfect for making some text translatable...but not readable.
Quick example:
<?php
$mytext="obfuscate me";
$obfuscated = strtr($mytext,"aeiourstlne","rstlneaeiou");
echo $obfuscated; /* Output is lbfnacreu mu */
?>
Some further reading here.
For real encryption, mcrypt is the solution. For obfuscation, a third function is uuencode; here's some code for decoding; encoding involves reversing the order.
$text = str_rot13($text);
$text = base64_decode($text);
$text = convert_uudecode($text);
Note that both base64_encode and convert_uudecode increase the size of the data.