• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 519
  • Last Modified:

Base64 Encode and Decode

Ive got a script which uploads a file in sections in VB.net, and before uploading converts it to Base64 so it can be uploaded:-
        input.Read(buffer, 0, count)
        Dim encoding As New System.Text.UTF8Encoding
        Dim postData As String = "valBlob=" & UrlEncode(System.Convert.ToBase64String(buffer))

Open in new window

The data seems to upload fine, however when I try and decode the data in PHP, the file becomes corrupt:-
	$fp = fopen("/home/09S6.dat", "a");
    fputs ($fp, base64_decode($_POST['valBlob']));
    fclose ($fp);

Open in new window

I belive its an issue with encrypting and decrypting, but have no idea of the correct way of donig this.

Any ideas?
1 Solution
Ray PaseurCommented:
PHP has no native support for UTF-8.  See http://us.php.net/manual/en/language.types.string.php

So it might be that there is something about using New System.Text.UTF8Encoding that makes the encoded string incompatible with PHP?
i know nothing about vb but the issue could be UrlEncode()
you might need to urldecode before you base64 decode
Dave BaldwinFixer of ProblemsCommented:
On this page http://msdn.microsoft.com/en-us/library/system.text.encoding.aspx , I found this:

"Note that Encoding is intended to operate on Unicode characters instead of arbitrary binary data, such as byte arrays. If your application must encode arbitrary binary data into text, it should use a protocol such as uuencode, which is implemented by methods such as Convert.ToBase64CharArray."
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now