decode base64 string

G

Guoqi Zheng

Dear sir,

I need to decode base64 encoded email.

I used below function but it does not work correctly, especially when I need
to decode some Characters like Chinese,

Can some one point out what I did wrong here? Thanks.



Public Function DecodeBase64(ByVal strInput As String) As String

Dim ReturnByte As Byte()

ReturnByte = System.Convert.FromBase64String(strInput)

Dim ReturnString As String

ReturnString = System.Text.Encoding.UTF8.GetString(ReturnByte)

Return ReturnString

End Function


--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.com
 
R

Rob Teixeira [MVP]

It's possible that the string was originally encoded using another codepage
or as Unicode, instead of UTF8.
Try some of the other System.Text.Encoding values.

-Rob Teixeira [MVP]
 
G

Guoqi Zheng

This a base64 string inside an email message. How can I determine what
encoding they used originally??
I need a function which able to decode any base64 encoded string, otherwise,
I have problem.

--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.com
 
R

Rob Teixeira [MVP]

One of the headers in the email tells you the content type, and if it's
text, will most likely also tell you what charset or codepage was used to
encode it. You must use this charset or codepage to decode the body (or part
of the body for multi-part emails).

I'm not an expert on email protocols, so you should look up the various RFC
documents to get a clear picture of what headers you need to look for, and
what format the messages will be in.

-Rob Teixeira [MVP]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top