Home All Groups Group Topic Archive Search About

String to byte[] & back using Base64

Author
8 Aug 2005 5:21 AM
Samba
Hi,

Can I please have a very small code snippet to convert byte[] to string and
back using Base64? Advance thanks.

--
Samba!

Author
8 Aug 2005 8:19 AM
Dominick Baier [DevelopMentor]
Hello Samba,

string b = Convert.ToBase64String(bytes);
byte[] bytesagain = Convert.FromBase64String(b);

---------------------------------------
Dominick Baier - DevelopMentor
http://www.leastprivilege.com

Show quoteHide quote
> Hi,
>
> Can I please have a very small code snippet to convert byte[] to
> string and back using Base64? Advance thanks.
>
Author
8 Aug 2005 8:39 AM
Samba
Ok, so thats how you do it ... thanks, Dominick.
--
Samba!
Author
25 Oct 2005 3:45 PM
Steve Smith
Show quote Hide quote
"Dominick Baier [DevelopMentor]" wrote:

> Hello Samba,
>
> string b = Convert.ToBase64String(bytes);
> byte[] bytesagain = Convert.FromBase64String(b);
>
> ---------------------------------------
> Dominick Baier - DevelopMentor
> http://www.leastprivilege.com
>
> > Hi,
> >
> > Can I please have a very small code snippet to convert byte[] to
> > string and back using Base64? Advance thanks.
> >
>
>
>
>
I'm using this functionality to try to load an image that's returned to me
in an XML file. The converstion to the byte array works fine.

Than I move the byte array into a memory Stream using ...

Dim stmBLOBData As New MemoryStream(binaryData)

which also seems to work fine, but the following line which should actually
create the image failes with a "Invalid Parameter used".

     img =  Image.FromStream(stmBLOBData)

Is this really a problem with my conversion? Any ideas how to debug?
Author
25 Oct 2005 4:25 PM
Dominick Baier [DevelopMentor]
Hello Steve,

From/To base64 conversion is lossless...

not sure what your problem is.


---------------------------------------
Dominick Baier - DevelopMentor
http://www.leastprivilege.com

Show quoteHide quote
> "Dominick Baier [DevelopMentor]" wrote:
>
>> Hello Samba,
>>
>> string b = Convert.ToBase64String(bytes);
>> byte[] bytesagain = Convert.FromBase64String(b);
>> ---------------------------------------
>> Dominick Baier - DevelopMentor
>> http://www.leastprivilege.com
>>> Hi,
>>>
>>> Can I please have a very small code snippet to convert byte[] to
>>> string and back using Base64? Advance thanks.
>>>
> I'm using this functionality to try to load an image that's returned
> to me in an XML file. The converstion to the byte array works fine.
>
> Than I move the byte array into a memory Stream using ...
>
> Dim stmBLOBData As New MemoryStream(binaryData)
>
> which also seems to work fine, but the following line which should
> actually create the image failes with a "Invalid Parameter used".
>
> img =  Image.FromStream(stmBLOBData)
>
> Is this really a problem with my conversion? Any ideas how to debug?
>
Author
25 Oct 2005 10:47 PM
Marcello Cantelmo
Show quote Hide quote
> I'm using this functionality to try to load an image that's returned to me
> in an XML file. The converstion to the byte array works fine.
>
> Than I move the byte array into a memory Stream using ...
>
> Dim stmBLOBData As New MemoryStream(binaryData)
>
> which also seems to work fine, but the following line which should
> actually
> create the image failes with a "Invalid Parameter used".
>
>     img =  Image.FromStream(stmBLOBData)
>
> Is this really a problem with my conversion? Any ideas how to debug?

arrImg...is your bytearray ;-)

Dim _stream As New MemoryStream(_arrImg, True)
stream.Write(_arrImg, 0, _arrImg.Length)
PictureBox1.Image = New Bitmap(New Bitmap(_stream))
_stream.Close()


best regards,
Marcello Cantelmo
www.cantelmosoftware.com

try for free Goliath.NET Obfuscator - the last secure obfuscator for .NET
platform