473,408 Members | 2,477 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

base64 enc/dec problem

PCH
I'm having a problem encoding a file (image) into base64, and then
converting it back from base64 and saving it.

I've tried several ways, but whenever i open the new image.. it is always
corrupt.

Here is the base coding I'm trying to get working

Imports System.IO

Dim fs As FileStream

Dim fswrite As FileStream

Dim oByte() As Byte

fs = New System.IO.FileStream("C:\18.jpg", _

System.IO.FileMode.Open, _

System.IO.FileAccess.Read)

ReDim oByte(fs.Length)

Dim b64String As String

b64String = System.Convert.ToBase64String(oByte, 0, fs.Length)

fswrite = File.Create("C:\test1.jpg", 1024)

Dim info As Byte() = New UTF8Encoding(True).GetBytes(b64String)

fswrite.Write(info, 0, info.Length)

fswrite.Close()

fs.Close()
Nov 17 '05 #1
2 3423

"PCH" <pc***@hotmail.com> wrote in message
news:Om*************@tk2msftngp13.phx.gbl...
I'm having a problem encoding a file (image) into base64, and then
converting it back from base64 and saving it.

I've tried several ways, but whenever i open the new image.. it is always
corrupt.

First you were never reading the input file. Second you were saving the
base64 encoded string to the output file. Here:

Dim fs As FileStream
Dim fswrite As FileStream
Dim oByte() As Byte
fs = New System.IO.FileStream("C:\18.jpg", _
System.IO.FileMode.Open, _
System.IO.FileAccess.Read)
ReDim oByte(fs.Length)
fs.Read(oByte, 0, fs.Length)
Dim b64String As String
b64String = System.Convert.ToBase64String(oByte, 0, fs.Length)
fswrite = File.Create("C:\test1.jpg", 1024)
Dim info As Byte() = System.Convert.FromBase64String(b64String)
fswrite.Write(info, 0, info.Length)
fswrite.Close()
fs.Close()

David
Nov 17 '05 #2
PCH
ah that Read call!
fs.Read(oByte, 0, fs.Length)

Thanks for the info!

"David Browne" <davidbaxterbrowne no potted me**@hotmail.com> wrote in
message news:%2****************@tk2msftngp13.phx.gbl...

"PCH" <pc***@hotmail.com> wrote in message
news:Om*************@tk2msftngp13.phx.gbl...
I'm having a problem encoding a file (image) into base64, and then
converting it back from base64 and saving it.

I've tried several ways, but whenever i open the new image.. it is always corrupt.

First you were never reading the input file. Second you were saving the
base64 encoded string to the output file. Here:

Dim fs As FileStream
Dim fswrite As FileStream
Dim oByte() As Byte
fs = New System.IO.FileStream("C:\18.jpg", _
System.IO.FileMode.Open, _
System.IO.FileAccess.Read)
ReDim oByte(fs.Length)
fs.Read(oByte, 0, fs.Length)
Dim b64String As String
b64String = System.Convert.ToBase64String(oByte, 0, fs.Length)
fswrite = File.Create("C:\test1.jpg", 1024)
Dim info As Byte() = System.Convert.FromBase64String(b64String)
fswrite.Write(info, 0, info.Length)
fswrite.Close()
fs.Close()

David

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Karl Pech | last post by:
Hi all, I'm trying to write a program which can read in files in the following format: sos_encoded.txt: --- begin-base64 644 sos.txt UGxlYXNlLCBoZWxwIG1lIQ== ---
3
by: Patrick | last post by:
Hi... I have a problem with Mime/base64 decoding. Maybe someone can help. I have an original Text, that I send using outlook. The text is: "This is a testmail ä ü ö é à è" (without the ") So...
27
by: gRizwan | last post by:
Hello all, We have a problem on a webpage. That page is sent some email data in base64 format. what we need to do is, decode the base64 data back to original shape and extract attached image...
4
by: John | last post by:
Hi all, I've been going through google and yahoo looking for a certain base64 decoder in C without success. What I'm after is something that you can pass a base64 encoded string into and get back...
1
by: scott | last post by:
Hi all, trying to use base64. Ill get right to the problem. I am converting a string into base 64. No problem there. That base64 string can then be converted back to the orignal string. No...
0
by: Phil C. | last post by:
(Cross post from framework.aspnet.security) Hi. I testing some asp.net code that generates a 256 bit Aes Symmetric Key and a 256 bit entropy value. I encrypt the Aes key(without storing it as...
7
by: Neo Geshel | last post by:
Greetings. I have managed to stitch together an awesome method of posting text along with an image to a database, in a way that allows an unlimited number of previews to ensure that text and...
5
by: Jay | last post by:
I have bean trying to get my head around reading .GIF files from base64 strings, Basically I need to specify a filename and convert it to base64 then I can copy/past the string to wear I want it....
8
by: Jeremy Kitchen | last post by:
I have encoded a string into Base64 for the purpose of encryption. I then later decrypted it and converted it back from Base64 the final string returns with four nothing characters. "pass" what...
13
by: aruna.eies.eng | last post by:
i am currently trying to convert data into binary data.for that i need to know how to achieve it in c language and what are the libraries that we can use. so if any one can send me a sample code or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.