Base64 Encode and Decode

Posted on 2011-10-30
Medium Priority
Last Modified: 2012-05-12
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?
Question by:tonelm54
LVL 111

Expert Comment

by:Ray Paseur
ID: 37054200
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?

Expert Comment

ID: 37054207
i know nothing about vb but the issue could be UrlEncode()
you might need to urldecode before you base64 decode
LVL 84

Accepted Solution

Dave Baldwin earned 2000 total points
ID: 37054492
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."

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question