function verifySigature($message, $sign, $exponent, $modulus) { $intSign = bin2int(hex2bin($sign)); $intExponent = bin2int(hex2bin($exponent)); $intModulus = bin2int(hex2bin($modulus)); $intResult = powmod($intSign, $intExponent, $intModulus); $hexResult = bin2hex(int2bin($intResult)); $md5Message = md5($message); if ($md5Message == substr($hexResult, -32)) { return "1"; } else { return "0"; } }
function rsa_decrypt($input) { global $private_key; $check = bchexdec($input); $modulus = bin2int($private_key["modulus"]); $exponent = bchexdec("010001"); $result = bcpowmod($check, $exponent, $modulus); $rb = bcdechex($result); return strtoupper(padstr($rb)); }
/** * バイナリデータからGIF画像の情報を取得して返す * * @param string &$data 画像のバイナリデータ * @param array &$image_info 取得した画像情報を格納する配列 * * @return boolean true => 情報の取得に成功 * false => エラー発生 */ function getInfo(&$data, &$image_info) { //画像タイプにJPEGを設定。 $image_info['type'] = IMAGETYPE_GIF; $image_info['extension'] = 'gif'; $bin_w = substr($data, 6, 2); $bin_h = substr($data, 8, 2); $image_info['w'] = bin2int($bin_w, 'v'); $image_info['h'] = bin2int($bin_h, 'v'); return true; }
function bitOr($num1, $num2, $start_pos) { $start_byte = intval($start_pos / 8); $start_bit = $start_pos % 8; $tmp1 = int2bin($num1); $num2 = bcmul($num2, 1 << $start_bit); $tmp2 = int2bin($num2); if ($start_byte < strlen($tmp1)) { $tmp2 |= substr($tmp1, $start_byte); $tmp1 = substr($tmp1, 0, $start_byte) . $tmp2; } else { $tmp1 = str_pad($tmp1, $start_byte, "") . $tmp2; } return bin2int($tmp1); }
function rsa_decrypt($enc_data, $p, $q, $d) { $enc_data = int2bin($enc_data); $exp = $d; $modulus = bcmul($p, $q); $data_len = strlen($enc_data); $chunk_len = bitLen($modulus) - 1; $block_len = (int) ceil($chunk_len / 8); $curr_pos = 0; $bit_pos = 0; $plain_data = 0; while ($curr_pos < $data_len) { $tmp = bin2int(substr($enc_data, $curr_pos, $block_len)); $tmp = bcpowmod($tmp, $exp, $modulus); $plain_data = bitOr($plain_data, $tmp, $bit_pos); $bit_pos += $chunk_len; $curr_pos += $block_len; } return int2bin($plain_data); }