1

I want to send data via POST to a php page, I need to store the bytes exactly as they are but I wasn't able to do it. When I send 138 bytes, fputs and fwrite returns 133.

$fh = fopen($myFile, 'ab') or die("can't open file");
echo fputs($fh, $_POST['data'] ,strlen($_POST['data']));
fclosw

VB.NET:

Dim ar As System.Text.UTF8Encoding = New System.Text.UTF8Encoding
Request.ContentLength = ar.GetByteCount(PostData)
ContentType = "application/x-www-form-urlencoded"
SW = New StreamWriter(Request.GetRequestStream(), ar)
SW.Write(PostData)

-edit this is the encrypted data function

Public Function Encrypt(ByVal stringToEncrypt As String, ByVal key As String) As String
    Rijndael.Key = SHA256.ComputeHash(ASCIIEncoding.ASCII.GetBytes(key))
    Rijndael.Mode = CipherMode.ECB
    Dim Buffer As Byte() = ASCIIEncoding.UTF8.GetBytes(stringToEncrypt)
    Return Convert.ToBase64String(Rijndael.CreateEncryptor().TransformFinalBlock(Buffer, 0,  Buffer.Length))
    End Function

EDITED example, original encrypted string:

j/aokbSUDP1nAD7KafnDoLSmI93sOLiroTwcQIUS/Xw8eUlUZA58OULXCtsnkKqOe+UXlFP6vKuTIWxVMRBZLiBiIOZomNsvoIfM4dv2UzAk2q5mpjo4/0E9lPvu4I7X

after sending

j/aokbSUDP1nAD7KafnDoLSmI93sOLiroTwcQIUS/Xw8eUlUZA58OULXCtsnkKqOe UXlFP6vKuTIWxVMRBZLiBiIOZomNsvoIfM4dv2UzAk2q5mpjo4/0E9lPvu4I7X
Tareq Ibrahim
  • 365
  • 5
  • 18

1 Answers1

1

I don't see a reason why this wouldn't work:

$connection = fopen($file, 'ab');
fwrite($connection, urldecode($_POST['data']));
fclose($connection);
Klaus S.
  • 1,239
  • 10
  • 18