tags:

views:

86

answers:

4

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?

+3  A: 

You may want to look at the mcrypt family of functions. It can encrypt and decrypt using a variety of algorithms.

eykanal
A: 

You'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.

http://ca2.php.net/md5

http://ca3.php.net/sha1

http://ca3.php.net/manual/en/function.crypt.php

jlindenbaum
Note the has functions mentioned here (md5, sha1) are one-way only; once encoded, they can't be decoded.
eykanal
Oh sheesh y'all, **encryption != hashing != encoding**... the functions you listed (MD5, SHA1, and crypt) are hashing/digest functions, not encryption functions. Encryption implies the original input can be deterministically decrypted from the encrypted message using some key. Encoding is simply a transform from one message format to another.
John Rasch
A: 

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.

Mark B.
A: 

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.

phsource