Example #1
0
/**
 * 根据证书ID 加载 证书
 *
 * @param unknown_type $certId        	
 * @return string NULL
 */
function getPulbicKeyByCertId($certId)
{
    //global $log;
    $log = new PhpLog(SDK_LOG_FILE_PATH, "PRC", SDK_LOG_LEVEL);
    $log->LogInfo('报文返回的证书ID>' . $certId);
    // 证书目录
    $cert_dir = SDK_VERIFY_CERT_DIR;
    $log->LogInfo('验证签名证书目录 :>' . $cert_dir);
    $handle = opendir($cert_dir);
    if ($handle) {
        while ($file = readdir($handle)) {
            clearstatcache();
            $filePath = $cert_dir . '/' . $file;
            if (is_file($filePath)) {
                if (pathinfo($file, PATHINFO_EXTENSION) == 'cer') {
                    if (getCertIdByCerPath($filePath) == $certId) {
                        closedir($handle);
                        $log->LogInfo('加载验签证书成功');
                        return getPublicKey($filePath);
                    }
                }
            }
        }
        $log->LogInfo('没有找到证书ID为[' . $certId . ']的证书');
    } else {
        $log->LogInfo('证书目录 ' . $cert_dir . '不正确');
    }
    closedir($handle);
    return null;
}
 protected function _ConstructPostData($postData)
 {
     $currency = GetDefaultCurrency();
     $currencycode = strtolower($currency['currencycode']);
     switch ($postData['cctype']) {
         case 'VISA':
             $cctype = '001';
             break;
         case 'MC':
             $cctype = '002';
             break;
         case 'AMEX':
             $cctype = '003';
             break;
         case 'DISCOVER':
             $cctype = '004';
             break;
         case 'DINERS':
             $cctype = '005';
             break;
         default:
             $cctype = '000';
             break;
     }
     $amount = $this->GetGatewayAmount();
     $billingDetails = $this->GetBillingDetails();
     $timestamp = getmicrotime();
     $transactionid = $this->GetCombinedOrderId();
     $signatureData = getMerchantID() . $amount . $currencycode . $timestamp . 'sale';
     $cybersourcePost['merchantID'] = getMerchantID();
     $cybersourcePost['billTo_firstName'] = htmlentities($billingDetails['ordbillfirstname']);
     $cybersourcePost['billTo_lastName'] = $billingDetails['ordbilllastname'];
     $cybersourcePost['billTo_street1'] = $billingDetails['ordbillstreet1'];
     $cybersourcePost['billTo_city'] = $billingDetails['ordbillsuburb'];
     $cybersourcePost['billTo_state'] = $billingDetails['ordbillstate'];
     $cybersourcePost['billTo_postalCode'] = $billingDetails['ordbillzip'];
     $cybersourcePost['billTo_country'] = $billingDetails['ordbillcountry'];
     $cybersourcePost['billTo_email'] = $billingDetails['ordbillemail'];
     $cybersourcePost['card_cardType'] = $cctype;
     $cybersourcePost['card_accountNumber'] = $postData['ccno'];
     $cybersourcePost['card_expirationMonth'] = $postData['ccexpm'];
     $cybersourcePost['card_expirationYear'] = '20' . $postData['ccexpy'];
     $cybersourcePost['orderPage_timestamp'] = $timestamp;
     $cybersourcePost['orderPage_signaturePublic'] = hopHash($signatureData, getPublicKey());
     $cybersourcePost['orderPage_serialNumber'] = getSerialNumber();
     $cybersourcePost['orderPage_version'] = '4';
     $cybersourcePost['orderPage_transactionType'] = 'sale';
     $cybersourcePost['amount'] = $amount;
     $cybersourcePost['currency'] = $currencycode;
     $cybersourcePost['hash'] = md5($this->GetValue("accessid") . $transactionid . $_COOKIE['SHOP_ORDER_TOKEN'] . $amount);
     $cybersourcePost['orderid'] = $transactionid;
     $cybersourcePost['iscsessionid'] = $_COOKIE['SHOP_ORDER_TOKEN'];
     return $cybersourcePost;
 }
Example #3
0
function VerifySignature($data, $signature)
{
    $pub = getPublicKey();
    $pub_digest = hopHash($data, $pub);
    return strcmp($pub_digest, $signature) == 0;
}
Example #4
0
function encryptDateType($certDataType)
{
    $cert_path = SDK_ENCRYPT_CERT_PATH;
    $public_key = getPublicKey($cert_path);
    openssl_public_encrypt($certDataType, $crypted, $public_key);
    return base64_encode($crypted);
}
Example #5
0
function hellman($a)
{
    echo shell_exec('clear');
    echo "\n                Bonjour, mon nom est Bernard, je suis la pour crypter votre message.\n\n                Vous etes Alice, et votre but est de m'envoyer une clé publique pour que je puisse chiffrer mon message ...\n\n                D'abord, vous devez créer une clé privée, celle ci doit etre une suite super-croissante :\n\n                Alice : ";
    while (true) {
        // bernard : votre private key
        $pKey = readline($a);
        $private_key = stringToArray($pKey);
        if (!super_croissance_check($private_key)) {
            echo "\n                Veuillez entrer une suite super croissante\n";
            $pKey = readline($a);
            $private_key = stringToArray($pKey);
            if (!super_croissance_check($private_key)) {
                echo "\n                Vas t'acheter des doigts !\n";
                exit;
            }
        }
        // sleep(1);
        echo "\n                Hum... c'est bien une suite supercroissante.\n";
        //  bernard :      votre mod
        echo "\n                Maintenant, un modulo :\n\n                Alice : ";
        $mod = readline($a);
        if (!is_numeric($mod)) {
            echo "\n\n                Je n'ai pas compris, 'ai besoin d'un entier pour pouvoir continuer.\n\n                Alice : \n";
            $mod = readline($a);
            if (!is_numeric($mod)) {
                echo "\n                Je n'ai toujours pas compris, pour eviter l'explosion de la terre je m'arette la.\n";
                exit;
            }
        }
        // bernard : votre $e
        echo "\n                Bien ! Maintenant un entier e.\n\n                Alice : ";
        $e = readline($a);
        if (!is_numeric($e)) {
            echo "\n\n                Je n'ai pas compris, 'ai besoin d'un entier pour pouvoir continuer\n\n                Alice : ";
            $e = readline($a);
            if (!is_numeric($e)) {
                echo "\n                Je n'ai toujours pas compris, je ... je dois vous laisser, j'ai oublié, une fourchette dans le micro-ondes\n";
                exit;
            }
        }
        //        /echo "E :: $e ::";
        //        limit > 4
        echo "\n                Et pour finir un entier bloc pour limiter les bloc messages dont la longueur doit etre supérieur à 4 et que la longueur de cl2 privée ne depasse pas celle ci\n\n                Alice : ";
        $limit = readline($a);
        if ($limit <= 4 || $limit > count($private_key)) {
            echo "\n\n                Hum pouvez vous recommencer ? la limite ne correspond pas au regles decrites tout à l'heure\n\n                Alice : ";
            $limit = readline($a);
            if (!$limit <= 4 || $limit > count($private_key)) {
                echo "\n                Hum, pouvez vous vous acheter des doigts ?\n";
                exit;
            }
        }
        echo "\n";
        sleep(2);
        $public_key = getPublicKey($private_key, $mod, $e, $limit);
        //        bernard votre message
        echo "\n\n                Tout est bon ! il ne reste plus que le message a crypter.\n\n                Bernard : ";
        $mess = readline($a);
        echo "\n";
        sleep(2);
        $message_crypted = cryptMessage($public_key[0], $mess, $limit);
        // $message_crypted = cryptMessage($public_key[0], $mess, $limit);
        $passwd = $public_key[1];
        // decrypt($private_key, $e, $mod, $message_crypted, $passwd, $limit);
        decrypt($private_key, $e, $mod, $message_crypted, $passwd, $limit);
        exit;
    }
    echo "\n";
}
Example #6
0
 /**
  * 加密数据
  * @param string $data数据
  * @param string $cert_path 证书配置路径
  * @return unknown
  */
 static function encryptData($data, $cert_path = SDK_ENCRYPT_CERT_PATH)
 {
     $public_key = getPublicKey($cert_path);
     openssl_public_encrypt($data, $crypted, $public_key);
     return base64_encode($crypted);
 }