コード例 #1
0
ファイル: PhpRsaVerifier.php プロジェクト: Briareos/Oxygen
 /**
  * @param Oxygen_Math_BigInteger $modulus
  * @param Oxygen_Math_BigInteger $exponent
  * @param string                 $data
  * @param string                 $rawSignature
  *
  * @return bool
  * @throws Oxygen_Exception
  */
 private function rsaMatch(Oxygen_Math_BigInteger $modulus, Oxygen_Math_BigInteger $exponent, $data, $rawSignature)
 {
     $modulusLength = strlen($modulus->toBytes());
     if ($modulusLength !== strlen($rawSignature)) {
         throw new Oxygen_Exception(Oxygen_Exception::RSA_KEY_SIGNATURE_SIZE_INVALID);
     }
     $signature = new Oxygen_Math_BigInteger($rawSignature, 256);
     $m2 = $this->rsavp1($signature, $exponent, $modulus);
     if (strlen($m2->toBytes()) > $modulusLength) {
         throw new Oxygen_Exception(Oxygen_Exception::RSA_KEY_MODULUS_SIZE_INVALID);
     }
     $em = str_pad($m2->toBytes(), $modulusLength, chr(0), STR_PAD_LEFT);
     $em2 = $this->emsaPkcs1v15Encode($data, $modulusLength);
     return Oxygen_Util::hashEquals($em, $em2);
 }