Very secure php encrypt and decrypt function. Uses gzip to have a little fun with the algorithm as well.
1<?php 2function encrypt_string($input, $key) { 3 $key = substr(md5($key),0,24); 4 $td = mcrypt_module_open ('tripledes', '', 'ecb', ''); 5 $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MCRYPT_RAND); 6 mcrypt_generic_init ($td, $key, $iv); 7 $encrypted_data = mcrypt_generic ($td, gzdeflate($input, 9)); 8 mcrypt_generic_deinit ($td); 9 mcrypt_module_close ($td);10 return trim(str_rot13(base64_encode($encrypted_data)));11}1213function decrypt_string($input, $key) {14 $input = trim(base64_decode(str_rot13($input)));15 $td = mcrypt_module_open ('tripledes', '', 'ecb', '');16 $key = substr(md5($key),0,24);17 $iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($td), MCRYPT_RAND);18 mcrypt_generic_init ($td, $key, $iv);19 $decrypted_data = mdecrypt_generic ($td, $input);20 mcrypt_generic_deinit ($td);21 mcrypt_module_close ($td);22 return stripslashes(trim(@gzinflate($decrypted_data)));23}24?>