Tim Hastings - NonHostile (because there's no need)

Weblog and collection of geeky articles.

  Home :: Who? :: Contact :: Links :: Subscribe subscribe
The Christmas Lights of Poulton-Le-FyldeThomas Stagles, welcome to EarthWarning: iPods May Cause Drowsiness


It couldn't be easier.

    Public Function ToBase64(ByVal data() As Byte) As String
        If data Is Nothing Then Throw New ArgumentNullException("data")
        Return Convert.ToBase64String(data)
    End Function

    Public Function FromBase64(ByVal base64 As String) As Byte()
        If base64 Is Nothing Then Throw New ArgumentNullException("base64")
        Return Convert.FromBase64String(base64)
    End Function
The code will work in VB.Net 2005 as well as earlier versions.
If you want to do Base 64 encoding/decoding using Visual Basic 6



15 comments, VB.Net, Monday, February 28, 2005 14:47

Timeline Navigation for VB.Net posts
VB.Net: How To Creat an Instance of an Object using its Type Name (made 2 days later)
VB.Net: Base64 Encoding and Decoding in One Line of Code (this post, made Monday, February 28, 2005 14:47)
VB.Net: Creating Functions with a variable Number of Parameters using ParamArray (made 11 weeks earlier)


Comments
Thanks so much! Big rofl! I was already searching for encoding components, cursing at the 30 day limits on them, big up!

Posted by: Alex on Thursday, August 3, 2006 15:18
Hi,
I am looking for VB code \ function for decoding Base64 to use in a VB 2005. Can you help or point me in the right direction.

Thanks a lot

David

Posted by: David Burton on Tuesday, August 15, 2006 10:08
hello, i am in the same boat as David.. and VB2005 code out there?

Posted by: Chris Rowe on Tuesday, February 5, 2008 06:36
Hello, this code will work in VB2005.

Posted by: Tim Hastings on Tuesday, February 5, 2008 10:19
Thank you very much. Have been searching for a solution to my problem for two days now and you have provided a very comfortable solution.

Posted by: Fil Jeffes on Thursday, July 31, 2008 16:37
Thanks

Posted by: Michael on Wednesday, August 13, 2008 10:01
Hi,
I am new to Vb 6.0 and i am looking for VB code which it should take the Hexadecimal bytes and should convert in to UTF-8 characters.

example i'll be getting data like this "C3BC"(hex value) i have to convert this in to Char which should display as "ü" .
I have tried with all cases all the time i am getting char as "?" i don't know why?
I need this solution desperately.please any help would be appriciated.
i have used following functions for conversion
strconv(str,vbunicode)
chrW$(&HC3BC)

Please help...........

Posted by: manu on Tuesday, September 16, 2008 11:06
Thanks a lot for your solution.

Posted by: Balraj on Thursday, February 19, 2009 04:43
But I need to convert from a *STRING*, to a *STRING*.

(Not to/from a byte() array)

Posted by: Kimberly on Tuesday, March 3, 2009 04:10
Kimberly, to convert a String to a Byte array just use

System.Text.Encoding.UTF8.GetBytes("Your string here")

And then to convert it back use

System.Text.Encoding.UTF8.GetString(YourByteArray)

So:

Dim S As String = "Hello world"
Dim EncodedString As String = ToBase64(System.Text.Encoding.UTF8.GetBytes(S))
Dim DecodedString As String = System.Text.Encoding.UTF8.GetString(FromBase64(EncodedString))

Posted by: Chris Haas on Friday, May 29, 2009 22:33
hi sir

i am developing application in vb.net.
how to write mathematical and chemical formule in textbox.
how to save and fetch in same format
plz help me

Posted by: sanjay on Saturday, June 13, 2009 11:15
Thanks for your help

Posted by: Anil Siddi on Tuesday, August 11, 2009 14:33
Thanks ! works great

Posted by: Sanjay on Tuesday, August 18, 2009 08:34
Thank you soooo much. I was looking for an 'easy' solution to encode an image to base64 so it could be sent as part of a HTTP Post segment of a URL. I realise it's not the best way of doing it but the server only accepts URLPost.

Dim gifData() As Byte
Dim gifCode As String
gifData = System.IO.File.ReadAllBytes(ImageLocation)
gifCode = ToBase64(gifData)


Posted by: Cliff on Friday, August 21, 2009 06:48

Post a Comment
Name:  Home page and email address are optional.
  Email addresses will not be displayed or spammed!
Remember these details
Email:
Home Page:
Comment:
Comments cannot contain HTML, URLs will be formatted into hyperlinks.
I reserve the right to remove any comments for any reason.