What's the problem with this code?
the purpose is to convert binary file into a Base64 string
I seem to have problem in the following line
BYTE const* pbBinary = &bytes[0];
int size = sizeof(pbBinary);
=================
typedef unsigned char BYTE;
std::ifstream file1("c:/test2.png");
// read from test2.png into BYTE array
std::vector<BYTEbytes(
(std::istreambuf_iterator<char>(file1))
, (std::istreambuf_iterator<char>())
);
if(bytes.empty())
; // no bytes have been read
BYTE const* pbBinary = &bytes[0];
int size = sizeof(pbBinary);
unsigned long ulEncLen = 0;
char *pEncOut = NULL;
BOOL fRet = ::CryptBinaryToString( pbBinary, size,
CRYPT_STRING_BASE64, pEncOut, &ulEncLen );
====================
BOOL WINAPI CryptBinaryToString(
__in const BYTE *pbBinary,
__in DWORD cbBinary,
__in DWORD dwFlags,
__out_opt LPTSTR pszString,
__inout DWORD *pcchString
); 5 5569
Chunekit Pong wrote:
What's the problem with this code?
It doesn't compile
the purpose is to convert binary file into a Base64 string
What's Base64 string?
I seem to have problem in the following line
BYTE const* pbBinary = &bytes[0];
int size = sizeof(pbBinary);
Most likely you will get 4 (depends on the platform you use)
=================
typedef unsigned char BYTE;
std::ifstream file1("c:/test2.png");
// read from test2.png into BYTE array
std::vector<BYTEbytes(
(std::istreambuf_iterator<char>(file1))
, (std::istreambuf_iterator<char>())
);
Is this working?
if(bytes.empty())
; // no bytes have been read
BYTE const* pbBinary = &bytes[0];
int size = sizeof(pbBinary);
I would do this:
const int size = bytes.size();
On Thu, 20 Nov 2008 10:13:34 +0100, anon <an**@no.invalidwrote:
>Chunekit Pong wrote:
>What's the problem with this code? It doesn't compile
>the purpose is to convert binary file into a Base64 string What's Base64 string?
>I seem to have problem in the following line BYTE const* pbBinary = &bytes[0]; int size = sizeof(pbBinary); Most likely you will get 4 (depends on the platform you use)
>================= typedef unsigned char BYTE; std::ifstream file1("c:/test2.png");
// read from test2.png into BYTE array std::vector<BYTEbytes( (std::istreambuf_iterator<char>(file1)) , (std::istreambuf_iterator<char>()) );
Is this working?
> if(bytes.empty()) ; // no bytes have been read
BYTE const* pbBinary = &bytes[0]; int size = sizeof(pbBinary); I would do this: const int size = bytes.size();
the full C++ file is like this - should compile http://www.oniva.com/upload/1356/c3.cpp
On Thu, 20 Nov 2008 10:13:34 +0100, anon <an**@no.invalidwrote:
>Chunekit Pong wrote:
>What's the problem with this code? It doesn't compile
>the purpose is to convert binary file into a Base64 string What's Base64 string?
>I seem to have problem in the following line BYTE const* pbBinary = &bytes[0]; int size = sizeof(pbBinary); Most likely you will get 4 (depends on the platform you use)
>================= typedef unsigned char BYTE; std::ifstream file1("c:/test2.png");
// read from test2.png into BYTE array std::vector<BYTEbytes( (std::istreambuf_iterator<char>(file1)) , (std::istreambuf_iterator<char>()) );
Is this working?
> if(bytes.empty()) ; // no bytes have been read
BYTE const* pbBinary = &bytes[0]; int size = sizeof(pbBinary); I would do this: const int size = bytes.size();
I used the bytes.size();
but i found that - pEncOut - is not holding any string after calling
CryptBinaryToString function, when I debug it says bad Prt something.
After calling the function CryptBinaryToString - pEncOut shoul have
the Base64 string generated.
===================
char *pEncOut = NULL;
BOOL fRet = ::CryptBinaryToString( pbBinary, size,
CRYPT_STRING_BASE64, pEncOut, &ulEncLen );
Chunekit Pong wrote:
On Thu, 20 Nov 2008 10:13:34 +0100, anon <an**@no.invalidwrote:
>Chunekit Pong wrote:
>>What's the problem with this code?
It doesn't compile
>>the purpose is to convert binary file into a Base64 string
What's Base64 string?
>>I seem to have problem in the following line BYTE const* pbBinary = &bytes[0]; int size = sizeof(pbBinary);
Most likely you will get 4 (depends on the platform you use)
>>================= typedef unsigned char BYTE; std::ifstream file1("c:/test2.png");
// read from test2.png into BYTE array std::vector<BYTEbytes( (std::istreambuf_iterator<char>(file1)) , (std::istreambuf_iterator<char>()) );
Is this working?
>> if(bytes.empty()) ; // no bytes have been read
BYTE const* pbBinary = &bytes[0]; int size = sizeof(pbBinary);
I would do this: const int size = bytes.size();
the full C++ file is like this - should compile http://www.oniva.com/upload/1356/c3.cpp
To open a file for binary read, you need to create ifstream object like
this:
std::ifstream file1( "c:/test2.png",
std::ios_base::binary |
std::ios_base::in );
Are you sure CryptBinaryToString works fine?
Chunekit Pong schrieb:
>>================= typedef unsigned char BYTE; std::ifstream file1("c:/test2.png");
// read from test2.png into BYTE array std::vector<BYTEbytes( (std::istreambuf_iterator<char>(file1)) , (std::istreambuf_iterator<char>()) );
Is this working?
>> if(bytes.empty()) ; // no bytes have been read
BYTE const* pbBinary = &bytes[0]; int size = sizeof(pbBinary);
I would do this: const int size = bytes.size();
I used the bytes.size();
but i found that - pEncOut - is not holding any string after calling
CryptBinaryToString function, when I debug it says bad Prt something.
After calling the function CryptBinaryToString - pEncOut shoul have
the Base64 string generated.
===================
char *pEncOut = NULL;
BOOL fRet = ::CryptBinaryToString( pbBinary, size,
CRYPT_STRING_BASE64, pEncOut, &ulEncLen );
Of course it doesn't work. pEncOut is set to NULL. It won't magically
change to something else.
You would have to set pEncOut to some buffer and maybe ulEncLen to the
size of this buffer. Check out the documentation of this
CryptBinaryToString function.
--
Thomas This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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==
---
|
by: plank |
last post by:
Hey Peeps,
Ok here is my situation.. I have a Java applet which allows the user to select files and upload them to the server. The
applet converts the file to Base64 and then POSTS the data to an...
|
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...
|
by: Steve Montague |
last post by:
I need to decode a base64 image and display it in a PictureBox control.
Currently I get an "Invaild character in a Base-64 string." error, so not
sure if a bad file or bad code, I have:
byte...
|
by: AC [MVP MCMS] |
last post by:
Any pointers on how to (1) read a Base64 encoded string from a text file
and (2) write it to a binary file?
I have a ton of files that are being generated from a legacy system. Each
file...
|
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...
|
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....
|
by: Roland Rickborn |
last post by:
Hallo zusammen,
in meine Anwendung ist ein Bild eingebettet und oben in der Leiste soll
ein Icon erscheinen.
Ausserdem will ich nur _eine_ Datei ausgeben, also ohne zusärtliche
Bild-Dateien...
|
by: pycraze |
last post by:
Hi ,
I am currently trying to implement base64 encoding and decoding
scheme in C . Python has a module , base64 , that will do the
encoding and decoding with ease . I am aware of OpenSSL having...
|
by: Chunekit Pong |
last post by:
How to save a Base64 encoded string to a binary file
For instance, the following XML tag stores the binary data in a Base64
encoded string
<data>TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx<data>
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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...
|
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,...
|
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...
| |