• PHP版本解密openrtb中的价格


    Decrypt Price Confirmations

    原文地址 https://developers.google.com/ad-exchange/rtb/response-guide/decrypt-price?hl=zh-cn%23decryption_scheme

    <?php
    
    function urlsafe_b64decode($string) {
        $data = str_replace(array('-','_'),array('+','/'),$string);
        $mod4 = strlen($data) % 4;
        if ($mod4) {
            $data .= substr('====', $mod4);
        }
        return base64_decode($data);
    }
    
    
    function decode($final_message, $e_key, $i_key) {
        $enc_price = urlsafe_b64decode($final_message);
        $iv = substr($enc_price, 0, 16);
        $p = substr($enc_price, 16, 8);
        $sig = substr($enc_price, 24, 4);
        $price_pad = hash_hmac("sha1", $iv, $e_key, true);
        $price = $p ^ $price_pad;
        $conf_sig = hash_hmac("sha1", $price . $iv, $i_key, true);
        if ($conf_sig != $sig) {
            return false;
        }
        return $price;
    }
    $e_key = "encrypriceencodingwhenintegratin";
    $i_key = "integpriceencodingwhenintegratin";
    foreach(["cHJpY2VlbmNvZGluZ3doZTzUyMb2dirzYcjALQ", "cHJpY2VlbmNvZGluZ3doZTjUy8b2dirzYXcL0Q", "cHJpY2VlbmNvZGluZ3doZTzKyOjDQx_zjiVOmw", "cHJpY2VlbmNvZGluZ3doZTrN1vbBdirz1G52-Q"] as $msg) {
        echo decode($msg, $e_key, $i_key) . PHP_EOL;
    }
  • 相关阅读:
    跨源资源共享(CORS)
    7.9 restful api
    7.8 http redirected
    7.7 设置http首部
    7.6 request form post
    7.5 URL 解析
    7.4 http request post get
    7.3 ip host反解析
    7.2 tcpclient 基本web
    7.1 获取所有网卡ip地址
  • 原文地址:https://www.cnblogs.com/23lalala/p/6164891.html
Copyright © 2020-2023  润新知