I'm new to encryption and utilizing this class to get tokens, Can someone help me understand what's going on these two functions with the help of references, video tutorials etc. for a deeper understanding. Purpose is to understand as well as implement in other languages using the same technique.
class Crypt {
public static function encrypt($data, $secret) {
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$key = pack('H*', $secret);
return base64_encode($iv . mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC, $iv));
}
public static function decrypt($data, $secret) {
$data = base64_decode($data);
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$iv = substr($data, 0, $iv_size);
$data = substr($data, $iv_size);
$key = pack('H*', $secret);
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC, $iv), chr(0));
}
}
thanks