Stupid encryption for Kohana. Rijndael-256, PBKDF2, no BS.
PHP
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
classes
config
README.md

README.md

What is this?

Occasionally, I find that I am required by a project to arbitrarily encrypt the contents of some strings in a database. Whatever.

So I did a lot of searchin and reading and then I wrote this little module to use the PHP encryption "best practices" as far as I can understand them, and tie it into Kohana.

Please bear in mind that I am not a cryptographer, and I have been known to be "wrong" in the past, so please tell me if I have goofed somewhere.

Also, please note that I don't necessarily think this is a "good idea" TM.

Database servers are usually further inside the network than web servers, so the odds of data being exposed is (to me) less than the possibility of the PHP source (and encryption key) being exposed. Assuming you are properly using your database to prevent injection.

Whatever.

CIPHER!

Cipher

This module uses mcrypt - so make sure it is installed.

It also uses Hash - so use a modern PHP.

The algoritm used is Rijndael-256 in CBC mode.

Your password is run through PBKDF2 a minimum of 1000 iterations to create the key.

That should be pretty good, afaik, as of 2012-07-16.

Usage

Copy and edit config/encryption.php. Add a good salt ( >= 8 bytes ) and your password.

Then just call the methods.

$ciphertext = Encryption::encrypt('lol');
$plaintext = Encryption::decrypt($ciphertext);

You can also hot-swap that password for another one, if you need to.

$ciphertext = Encryption::encrypt('lol', 'wut');
$plaintext = Encryption::decrypt($ciphertext, 'wut');