CONVERT STRING TO READABLE FORMAT WHEN CONTAIN BASE64 STRING

peter liles 556 Reputation points
2021-08-26T11:23:41.72+00:00

I receive the following error message when attempting to run this code:

Dim Buffer As Byte() = Convert.FromBase64String(strBody)

The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.

I am trying to output a readable string of text (variable) to a Textbox from my email using POP :

It also contains HTML code which i removed because i was unable to save the post on here.

String text

--_004_46221637E59720418908A2B0A37AE83701464C393EBAHSIAEXB201b_
Content-Type: multipart/alternative;
boundary="_000_46221637E59720418908A2B0A37AE83701464C393EBAHSIAEXB201b_"

--_000_46221637E59720418908A2B0A37AE83701464C393EBAHSIAEXB201b_
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Peter,

I look forward to hearing from you soon.

Thanks Emma

Tel:328148 Mob: 0777 8205

[recycling%20logo]"Please consider your environmental responsibility before=
printing this e-mail"

This e-mail and any attached files are confidential and may also be legally=
privileged. They are intended solely for the intended addressee.

--_000_46221637E59720418908A2B0A37AE83701464C393EBAHSIAEXB201b_
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

--_000_46221637E59720418908A2B0A37AE83701464C393EBAHSIAEXB201b_--

--_004_46221637E59720418908A2B0A37AE83701464C393EBAHSIAEXB201b_
Content-Type: image/jpeg; name="image001.jpg"
Content-Description: image001.jpg
Content-Disposition: inline; filename="image001.jpg"; size=1090;
creation-date="Tue, 14 Jul 2019 09:52:57 GMT";
modification-date="Tue, 14 Jul 2019 09:52:57 GMT"
Content-ID: <image001.jpg@01D0BE23.3E7A9C60>
Content-Transfer-Encoding: base64

/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAoHBwgHBgoICAgLCgoLDhgQDg0NDh0VFhEYIx8lJCIf
IiEmKzcvJik0KSEiMEExNDk7Pj4+JS5ESUM8SDc9Pjv/2wBDAQoLCw4NDhwQEBw7KCIoOzs7Ozs7
Ozs7Ozs7Ozs7Ozs7Ozs7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ysXhKk6yrU9Wb7eJ7I+HhrSBhC52osgwSc4/wDr1wXi/wDsabWEv7C9hdJ/9ei5G1v734/z
ro9c8JtB4RhsrSeSY2UhkG4Y3Anngemf51R0n4c3UeqwXWpXFu0ELB/KjyxcjoDkDis60a1Vqm12
1MsTHEVmqTjpZa9n1Ot8NRzxaDbJOpUhfkVuoX+HP4UVq0V6MI8kVHsevTh7OCgumgUUUVRYUUUU
AFFFFAH/2Q==
--_004_46221637E59720418908A2B0A37AE83701464C393EBAHSIAEXB201b_--

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,317 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yijing Sun-MSFT 7,071 Reputation points
    2021-08-27T06:52:07.167+00:00

    Hi @peter liles

    The Convert.FromBase64String(String) method converts the specified string (it encodes binary data into Base64 numbers) into an equivalent 8-bit unsigned integer array.
    The strBody should not be a valid 64-bit, you can check it with DEBUG.
    I created a test of 32bits with using FromBase64String,just like this:

    Dim x As String = "iVBORw0KGgoAAAANSUhEUgAAAMgAAABk"  
    Dim b As Byte() = Convert.FromBase64String(x)  
    

    If your string have a symbol,you must replace it.

    Best regards,
    Yijing Sun


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.