Bonjour,
je suis sur un bout de code PHP ou j'ai besoin de préparer une structure xml,la compresser puis crypter et l'envoyer via la méthode curl_ avec la méthode POST,
sur le coté traitement du poste je reçois une chaine de caractère plus courte, quand j'envois 512 caractère , la variable du post contienne une chaine de taille aléatoire a chaque refreesh.

merci pour vos réponse.

j'ajoute le code pour mieux expliquer

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 
 
<?php
 
require_once 'MessagesUtils.php';
 
$sender_account = '100103';
$recipient_account = '100104';
$recipient_name = 'boutique.com';
$order = 'A012/2012';
$product = '05561';
$url_return = 'http://thy85k.php'; /* utiliser des fichier de return generer dynamiquement a partir d'un template */
$url_cancel = 'http://ply5o92.php'; /* utiliser des fichier de return generer dynamiquement a partir d'un template */;
$amount = '500';
$api_key = '955g477t555d3011zgpkko'; /* c'est un identifiant utilisé pour récuperer la clé publique du marchand dans la base de icosnet */
$token = '8gfpjkjsmmfyerav'; /* c'est un token generer dynamiquement au niveau du marchand pour identifier chaque transaction */
 
 
$xmlString = MessagesUtils::buildMerchantRequest($sender_account, $recipient_account, $recipient_name, $order, $product, $url_return, $url_cancel, $amount, $api_key, $token);
/* ---------end build request ------------------ */
 
//crypt with public key
$fp = fopen("PublicKey.pem", "r");
$pub_key = fread($fp, 8192);
fclose($fp);
$PK = "";
$PK = openssl_get_publickey($pub_key);
$xmlString = urlencode($xmlString);
 
 
$xmlString = gzcompress($xmlString);
 
 
$xmlencrypted = "";
 
try {
    openssl_public_encrypt($xmlString, $xmlencrypted, $PK);
} catch (Exception $exp) {
    var_dump($exp);
}
 
/* fin de cryptage */
 
 
// Infobip's POST URL
$postUrl = "http://localhost/security/cryptography/traitement.php";
 
 
// previously formatted XML data becomes value of "XML" POST variable
$fields = "XML=" . $xmlencrypted;
// in this example, POST request was made using PHP's CURL
 
echo '--------- xmlencrypted  marchent--------------------</br>';
var_dump($xmlencrypted);
 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $postUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
 
// response of the POST request
$result = curl_exec($ch);
 
$response = '';
if ($result == true) {
    $response = ob_get_contents();
}
 
$xmlResponse = simplexml_load_string($response);
 
var_dump($xmlResponse);
 
curl_close($ch);
?>
d'un autre coté sur le fichier traitement.php j'ai:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
 
<?php
 
require_once 'MessagesUtils.php';
echo"<?xml version=\"1.0\"?>\r\n";
 
 
if (isset($_POST['XML'])) {
 
    $xmlencrypted = $_POST['XML'];    
 
    echo '---------recieved xmlencrypted --------------------</br>';
    var_dump($xmlencrypted);
 
    /* decryptage message du marchand */
    //decrypt with private key
    $fp = fopen("Key.pem", "r");
    $private_key = fread($fp, 8192);
    fclose($fp);
    $PrK = "";
    $PrK = openssl_get_privatekey($private_key, '');
 
    $xmlCompressed="";
    /
    openssl_private_decrypt($xmlencrypted, $xmlCompressed, $PrK);
 
    echo '--------- xmlCompressed --------------------</br>';
    var_dump($xmlCompressed);
 
 
 
    $xmlCodded= gzuncompress($xmlCompressed);
    echo '--------- uncompressed --------------------</br>';
    var_dump($xmlCodded);
 
 
 
 
 
    $xmlDecodded = urldecode($xmlCodded);
 
    $xmlResponse = simplexml_load_string($xmlDecodded);
 
    echo '--------- xmlResponse --------------------</br>';
    var_dump($xmlResponse);
 
 
    $check_result = "OK";
    $err_code = "0";
    $last_balance = "700";
    $new_balance = "800";
    $order = "A012/2012";
    $token = "955g477t555d3011zgpkko";
 
    $response = MessagesUtils::buildIcosnetResponse($check_result, $err_code, $last_balance, $new_balance, $order, $token);
 
    echo $response;
} else {
    echo "erreur";
}
?>