Helper::md5Verified PHP Method

md5Verified() public static method

Extracts what should be the md5 from the end of a string to verify against the remainder Returns the verified data if the md5 is correct, null otherwise.
public static md5Verified ( $data ) : null | string
$data
return null | string
    public static function md5Verified($data)
    {
        $actual_data = substr($data, 0, -32);
        $checksum = substr($data, -32);
        if (md5($actual_data) === $checksum) {
            return $actual_data;
        }
        return null;
    }

Usage Example

Example #1
0
 /**
  * @param $text
  * @param $key
  * @return string|null
  */
 protected function decryptSignature($text, $key)
 {
     $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
     $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
     $decrypt = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, base64_decode($text), MCRYPT_MODE_ECB, $iv));
     if (Yii::app()->params['no_md5_verify']) {
         return $decrypt;
     }
     return Helper::md5Verified($decrypt);
 }
All Usage Examples Of Helper::md5Verified