PDA

View Full Version : خطا در اتصال به درگاه امن پاسار گاد



sims_r_z
سه شنبه 05 اردیبهشت 1391, 13:14 عصر
من یک سایت دارم که با php کار شده ودر گاه امن بانک پاسارگاد و بهش وصل کردم ولی این خطا رو میده می خواستم بدونم مشکل از کجاست

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "certificate.xml" in /home/xxxxx/public_html/xxxxx/RSAProcessor.class.php on line 17
================================================== ==============
Warning: str_repeat() [function.str-repeat]: Second argument has to be greater than or equal to 0 in /home/xxxxx/public_html/xxxxx/rsa.class.php on line 79

sims_r_z
سه شنبه 05 اردیبهشت 1391, 14:18 عصر
کسی نیست جواب بده؟!!!!!!!!!!!!!!!!!!!!

Unique
سه شنبه 05 اردیبهشت 1391, 14:30 عصر
اینجوری به جواب نمیرسین باید کد کامل یا قطعه ای از کد که این خطا را ایجاد میکنه بگذارین

sims_r_z
سه شنبه 05 اردیبهشت 1391, 14:41 عصر
; کلاس
RSAProcessor.class.php
کین کدش

<?php
require_once("rsa.class.php");
class RSAProcessor
{
private $public_key = null;
private $private_key = null;
private $modulus = null;
private $key_length = "1024";
public function __construct($xmlRsakey=null,$type=null)
{
$xmlObj = null;
if($xmlRsakey==null) {
$xmlObj = simplexml_load_file("xmlfile/RSAKey.xml");
}
elseif($type==RSAKeyType::XMLFile)
{
$xmlObj = simplexml_load_file($xmlRsakey);
}
else {
$xmlObj = simplexml_load_string($xmlRsakey);
}
$this->modulus = RSA::binary_to_number(base64_decode($xmlObj->Modulus));
$this->public_key = RSA::binary_to_number(base64_decode($xmlObj->Exponent));
$this->private_key = RSA::binary_to_number(base64_decode($xmlObj->D));
$this->key_length = strlen(base64_decode($xmlObj->Modulus))*8;
}
public function getPublicKey() {
return $this->public_key;
}
public function getPrivateKey() {
return $this->private_key;
}
public function getKeyLength() {
return $this->key_length;
}
public function getModulus() {
return $this->modulus;
}
public function encrypt($data) {
return base64_encode(RSA::rsa_encrypt($data,$this->public_key,$this->modulus,$this->key_length));
}
public function dencrypt($data) {
return RSA::rsa_decrypt($data,$this->private_key,$this->modulus,$this->key_length);
}
public function sign($data) {
return RSA::rsa_sign($data,$this->private_key,$this->modulus,$this->key_length);
}
public function verify($data) {
return RSA::rsa_verify($data,$this->public_key,$this->modulus,$this->key_length);
}
}
class RSAKeyType{
const XMLFile = 0;
const XMLString = 1;
}

sims_r_z
سه شنبه 05 اردیبهشت 1391, 14:42 عصر
rsa.class.php


<?php
define("BCCOMP_LARGER", 1);
class RSA {
function rsa_encrypt($message, $public_key, $modulus, $keylength) {
$padded = RSA::add_PKCS1_padding($message, true, $keylength / 8);
$number = RSA::binary_to_number($padded);
$encrypted = RSA::pow_mod($number, $public_key, $modulus);
$result = RSA::number_to_binary($encrypted, $keylength / 8);
return $result;
}
function rsa_decrypt($message, $private_key, $modulus, $keylength) {
$number = RSA::binary_to_number($message);
$decrypted = RSA::pow_mod($number, $private_key, $modulus);
$result = RSA::number_to_binary($decrypted, $keylength / 8);
return RSA::remove_PKCS1_padding($result, $keylength / 8);
}
function rsa_sign($message, $private_key, $modulus, $keylength) {
$padded = RSA::add_PKCS1_padding($message, false, $keylength / 8);
$number = RSA::binary_to_number($padded);
$signed = RSA::pow_mod($number, $private_key, $modulus);
$result = RSA::number_to_binary($signed, $keylength / 8);
return $result;
}
function rsa_verify($message, $public_key, $modulus, $keylength) {
return RSA::rsa_decrypt($message, $public_key, $modulus, $keylength);
}
function rsa_kyp_verify($message, $public_key, $modulus, $keylength) {
$number = RSA::binary_to_number($message);
$decrypted = RSA::pow_mod($number, $public_key, $modulus);
$result = RSA::number_to_binary($decrypted, $keylength / 8);
return RSA::remove_KYP_padding($result, $keylength / 8);
}
function pow_mod($p, $q, $r) {
$factors = array();
$div = $q;
$power_of_two = 0;
while(bccomp($div, "0") == BCCOMP_LARGER) {
$rem = bcmod($div, 2);
$div = bcdiv($div, 2);
if($rem) array_push($factors, $power_of_two);
$power_of_two++;
}
$partial_results = array();
$part_res = $p;
$idx = 0;
foreach($factors as $factor) {
while($idx < $factor)
{
$part_res = bcpow($part_res, "2");
$part_res = bcmod($part_res, $r);
$idx++;
}
array_push($partial_results, $part_res);
}
$result = "1";
foreach($partial_results as $part_res)
{
$result = bcmul($result, $part_res);
$result = bcmod($result, $r);
}
return $result;
}
function add_PKCS1_padding($data, $isPublicKey, $blocksize)
{
$pad_length = $blocksize - 3 - strlen($data);
if($isPublicKey)
{
$block_type = "\x02";
$padding = "";
for($i = 0; $i < $pad_length; $i++)
{
$rnd = mt_rand(1, 255);
$padding .= chr($rnd);
}
}
else
{
$block_type = "\x01";
$padding = str_repeat("\xFF", $pad_length);
}
return "\x00" . $block_type . $padding . "\x00" . $data;
}
function remove_PKCS1_padding($data, $blocksize)
{
assert(strlen($data) == $blocksize);
$data = substr($data, 1);
if($data{0} == '\0')
die("Block type 0 not implemented.");
assert(($data{0} == "\x01") || ($data{0} == "\x02"));
$offset = strpos($data, "\0", 1);
return substr($data, $offset + 1);
}
function remove_KYP_padding($data, $blocksize)
{
assert(strlen($data) == $blocksize);
$offset = strpos($data, "\0");
return substr($data, 0, $offset);
}
function binary_to_number($data)
{
$base = "256";
$radix = "1";
$result = "0";
for($i = strlen($data) - 1; $i >= 0; $i--)
{
$digit = ord($data{$i});
$part_res = bcmul($digit, $radix);
$result = bcadd($result, $part_res);
$radix = bcmul($radix, $base);
}
return $result;
}
function number_to_binary($number, $blocksize)
{
$base = "256";
$result = "";
$div = $number;
while($div > 0)
{
$mod = bcmod($div, $base);
$div = bcdiv($div, $base);
$result = chr($mod) . $result;
}
return str_pad($result, $blocksize, "\x00", STR_PAD_LEFT);
}
}

sims_r_z
سه شنبه 05 اردیبهشت 1391, 14:43 عصر
حاله یه نگاه به کدهای بالا کنید بگید مشکل از کجاست

sims_r_z
سه شنبه 05 اردیبهشت 1391, 17:03 عصر
کسی بلد نیست جواب بده

plague
سه شنبه 05 اردیبهشت 1391, 18:25 عصر
$xmlObj = simplexml_load_file($xmlRsakey);
مشکل اینجاست خط 17

$xmlRsakey
یه متغیره که باید حاوی نام یه فایل باشه که اینجا قراره لود بشه
ظاهرا اینه الان certificate.xml
ولی به هرجهت خالی میرسه به اینجا یا با نام غلط میرسه به اینجا یا همچین فایلی وجود نداره و اررور میده که آدرس فایلی که دادین لود کنم غلطه

sims_r_z
سه شنبه 05 اردیبهشت 1391, 19:59 عصر
دوست عزیز هر کاری کردم همین پیغام میاد این آیدی یاهو sims_r_z@yahoo.com منه اگه می تونی برام برنامه نویسیش کنی پیام بده تا کد بیشتری برات بفرستم

plague
سه شنبه 05 اردیبهشت 1391, 22:17 عصر
با کد فرستادن چیزی درست نمیشه باید
برنامه نویس بیاد روی هاستت رفع اشکال و تست بکنه
کدی که باهاش وصل میشی به دیتابیس رو بزار اینجا اگه میتونی

.fatemeh
یک شنبه 17 آذر 1392, 20:03 عصر
سلام
من هم به همین مشکل برخوردم توی certificate.xml باید کلید عمومی قرار بگیره که کپی کردم ولی بازم همین خطا رو میده.
کسی از دوستان می تونه راهنمایی کنه؟
ممنون