Base64 Encode and Decode

Posted on 2011-10-30
Last Modified: 2012-05-12
Ive got a script which uploads a file in sections in, 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 107

    Expert Comment

    by:Ray Paseur
    PHP has no native support for UTF-8.  See

    So it might be that there is something about using New System.Text.UTF8Encoding that makes the encoded string incompatible with PHP?
    LVL 7

    Expert Comment

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

    Accepted Solution

    On this page , 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

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now