<?php class secure { function encryption_decryption($action, $str) { $key = 'naveen'; $string = $str; if ($action == "encrypt") { $output = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key)))); } else { if ($action == "decrypt") { $output = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($string), MCRYPT_MODE_CBC, md5(md5($key))), ""); } } return $output; } } $obj = new secure(); $result = $obj->encryption_decryption("encrypt", "hello"); echo $result;