question

peterliles-4155 avatar image
0 Votes"
peterliles-4155 asked YijingSun-MSFT commented

CONVERT STRING TO READABLE FORMAT WHEN CONTAIN BASE64 STRING

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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DysXhKk6yrU9Wb7eJ7I+HhrSBhC52osgwSc4/wDr1wXi/wDsabWEv7C9hdJ/9ei5G1v734/z
ro9c8JtB4RhsrSeSY2UhkG4Y3Anngemf51R0n4c3UeqwXWpXFu0ELB/KjyxcjoDkDis60a1Vqm12
1MsTHEVmqTjpZa9n1Ot8NRzxaDbJOpUhfkVuoX+HP4UVq0V6MI8kVHsevTh7OCgumgUUUVRYUUUU
AFFFFAH/2Q==
--004_46221637E59720418908A2B0A37AE83701464C393EBAHSIAEXB201b--

dotnet-aspnet-webforms
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

YijingSun-MSFT avatar image
0 Votes"
YijingSun-MSFT answered YijingSun-MSFT commented

Hi @peterliles-4155

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.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

How do i translate
=?utf-8?b?SXTigJlz?=

into it's for display in webpage when run on server. I tried saving as byte data in a file but just appears as shown.


This is the code that is sent from POP3 SERVER embedded into Subject header. The full code is:
"Subject: Online Banking | =?utf-8?b?SXTigJlz?= been a while, Mr Jones"

0 Votes 0 ·

Hi @peterliles-4155 ,
The base64 includs about 'A-Z','a-z','0-9','+' and '/'. In your string,you must replace '?' to '/' and replace '-' to '+'. And then the first '=' is unnecessary you need to remove it, Also, it must to be 8 multiples. So in the last of your string ,you must add "=".
Summary, your string must to be like this:
/utf+8/b/SXTigJlz/==
You could use remove() and replace() method.

Best regards,
Yijing Sun

0 Votes 0 ·