Decript Base64 Binary encrypted filles in Soap Response

Recently i got a new project to work on a SOAP service and to Get and Post messages to a ASP .NET service based on xml.
The issue is that i managed to make the soap request and get the message.
The message looks like this : UEsDBBQAAAAIAAdUe06+NXE0kR4AADLSAQALAAAAUHJvZHVzZS54bWzUXW1z48YN5k/h5EMnmbMsvomSpmkzFCXbjERJoSTb52/p9dq5mbxN2svczy/…
The message is Base64 Binary on RFC 4648 with multiple xml documents on it.
How i can construct this documents from the code in php?
The documents encrypted in this request are 3 xml files.
I mannaged to get them from an online decriptor called freeformatter with download function.
If i try to decode the result i get something like : PKT{N�5q4�2�Produse.xml�]ms�� �O��C’��,����i3%یDI�$��o��ڹ��M����/�,��|vL�O�$�/�xv,,�u�s>9?;?..
There is a sollution for this?
Im new to SOAP so i dont understand too much of it.
Thank you very much.

What do you use to make the SOAP Request?
If you use the SOAP Extension’s SOAPClient Class, that should take care of the Base64 decoding automatically.

Hello and thank you for response.
I’m using a new SoapClient() class for this function but the server returm me this base64 binary data response.
The code is very lightweight.

$wsdl = 'https://*******';
$options = array('trace' => true);
$client = new SoapClient($wsdl, $options);
$params = array('encoding' => 'utf-8', 'Domain' => '******','User' => '*******', 'Password' => '*******', 'Unit' => '*******', 'Tip' => '******', 'Div' => '****', 'XmlExtraParams' => '<root><header><code>****</code></header></root>');
$response = $client->GetData($params);
$raspuns = ($client->__getLastResponse());
echo $raspuns;

The code is working, getting the response but im stucked at decription.
There is a way to descript that base64 binary on php that automaticaly construct that filles encrypted?
Thank you very much,.

Looking at the decoded result in your first message, I think the xml might be archived using something called pkt

What do you get if you pass your response through base64_decode() ?

When i pass the response with base64_decode() function i get only the binary data, where i can see the name of filles

But i want to know how i can construct them…
The values are in binary data, and the target filles are also there.

The ‘PK’ characters you have at the start and after each filename makes me think the xml file data might be compressed. ‘PK’ is the File Signature for zip, jar and other compressed files, see

So you could try breaking up the data for each file and passing each segment through the gzuncompress() function.

Actually, scrap that, they are probably compressed using the zip, not gzip format, so you’ll have to use ZipArchive not gzuncompress.

See this discussion: extract-a-file-from-a-zip-string for suggestions on how to do this. The OP there seems to have the same problem as you except that you multiple files instead of just one.

I was making a zip file from the bytes that i get on response, but no succes.
The issue is that i created manualy the filles in the archive,but im not getting content to them.
Thank you very much for helping me, i will try more to get the content, but if you have some models which i can count on would be great. Cheers.

Thank you.
I mannaged to solve it, the sollution was really short.
I write 2 new filles and i catch the response in one, and in another i make a compiler using the value of the first file and creating a new file with zip extension without ZipArchive() function.

Could you post the code for future reference please? Just so that people coming here with the same problem can also see the solution.


The first thing you need to do when you have an .zip file in a base64 binary string is to catch the response to a txt file.
Let’s say the response from soap it’s called ’ $response ’ and we need to catch this to an file. We do like this :

$response = $client -> _getLastResponse();
$file = "response.xml";

Now we got the response to an xml file.
The next thing to do is to get the response from xml values.
Lets say our value is .

$b64 = "b64.txt";
$dom = new DomDocument();
$dom = load("response.xml");
$data = $dom->getElementByTagName("ResponseFromServer");
$catchb64 = $data;

Now we got the clean Base64 Binary string in one fille.
The next thing we need is to create the document ( in this case is a .zip fille)

$input_fille = "response.txt"; // the fille with clean base64 binary data on it
$output_fille = ""; //the fille we need to create on system with the documents decrypted
$content = fille_get_contents($input_fille); // Reading the content of input fille
$binary = base64_decode($content); // Decoding to binary
fille_put_contents($output_fille,$binary); // Writing to fille the vallues

We dont need the ZipArchive() function, because is allready a zip archive, all we need to do is to create a empty document and after to send the binary data to it.
Cheer’s and goodluck!


Awesome, thanks!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.