I have some form inputs that need to be encrypted for database storage. I am not sure if I am using the best encryption. This is my encrypt and decrypt with strings kept in environment files.
class encrypt
{
public static function encrypt_text($value)
{
if(!$value) return false;
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, env('ENCRYPT_STRING_1'), $value, MCRYPT_MODE_ECB, env('ENCRYPT_STRING_2'));
return trim(base64_encode($crypttext));
}
public static function decrypt_text($value)
{
if(!$value) return false;
$crypttext = base64_decode($value);
$decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, env('ENCRYPT_STRING_1'), $crypttext, MCRYPT_MODE_ECB, env('ENCRYPT_STRING_2'));
return trim($decrypttext);
}
}