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
Exemplo n.º 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);
 }
Exemplo n.º 2
0
 public function test_md5Verified()
 {
     $random_string = '';
     for ($i = 0; $i < 5; $i++) {
         $random_string .= substr(md5(mt_rand()), 0, mt_rand(1, 32));
     }
     $checksum = md5($random_string);
     $pass_test = $random_string . $checksum;
     $this->assertEquals($random_string, Helper::md5Verified($pass_test));
     $fail_test = $random_string . 'a' . $checksum;
     $this->assertNull(Helper::md5Verified($fail_test));
 }