RE: Base64 Help

2005-10-17 Thread Adam Jones
int main (void)
{
 BIO *bmem, *b64;
 BUF_MEM *bptr;
 char message[] = Hello World \n;
 int written = 0;
 
 b64 = BIO_new(BIO_f_base64());
 bmem = BIO_new(BIO_s_mem());
 b64 = BIO_push(b64, bmem);
 written = BIO_write(b64, message, strlen(message));
 cout  written  endl;
 BIO_get_mem_ptr(b64, bptr);
 BIO_flush(b64);
 BIO_free_all(b64);
}
 
This should be straight forward, but it is not. It appears that base64
encoding to something other than stdout or a file does not work. I am using
vc++ 6.0, on windows platform. I can't get it to work with stdout either. I
get no compile or runtime errors. The bptr gets a valid address, but the
address has nothing in it. Also the system tells me that 13 characters were
written, which is the correct number.Does anyone see why this is not working
correctly? I have even change the line BIO_get_mem_ptr(b64, bptr); to
BIO_get_mem_ptr(bmem, bptr); which does nothing.

Thanks in Advance... 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Joseph Oreste Bruni
Sent: Thursday, October 13, 2005 4:36 PM
To: openssl-users@openssl.org
Subject: Re: Base64 Help

Using VC++ is your first problem... :)

The call to BIO_push is your problem. You overwrite your reference to the
b64 BIO with another reference to the mem BIO. So now, b64 points to mem.

Do this:

int main()
{
 BIO *bmem, *b64;
 char message[] = Hello World \n;
 int written = 0;

 b64 = BIO_new(BIO_f_base64());
 bmem = BIO_new_fp(stdout,0);
 b64 = BIO_push(b64, bmem);
 written = BIO_write(b64, message, strlen(message));
 cout  written  endl;
 BIO_flush(b64);
 BIO_free_all(b64);
}

This will output your Base64 to stdout. Then if you need to use a mem BIO
just change out the call to what you had, but you'll need to get pointers to
the data to display it (or whatever).




On Oct 13, 2005, at 1:55 PM, Adam Jones wrote:

 Visual C++ did not complain nor did it error out when it ran, but you 
 are correct it does take a BUF_MEM structure. I also added another BIO 
 method to the code. I also read that section in the book you 
 suggested. I also made the code simple, but it appears that it still 
 does not give me the
 base64
 encoding. Any suggestions...

 int main()
 {
 BIO *bmem, *b64;
 char message[] = Hello World \n;
 int written = 0;

 b64 = BIO_new(BIO_f_base64());
 bmem = BIO_new(BIO_s_mem());
 bmem = BIO_push(b64, bmem);
 written = BIO_write(b64, message, strlen(message));
 cout  written  endl;
 BIO_flush(b64);
 BIO_free_all(b64);
 }



 -Original Message-
 From: [EMAIL PROTECTED]
 [mailto:[EMAIL PROTECTED] On Behalf Of Joseph Oreste 
 Bruni
 Sent: Thursday, October 13, 2005 2:46 PM
 To: openssl-users@openssl.org
 Subject: Re: Base64 Help

 b64 is a filter BIO, it won't hold on to your data. You need to 
 append a memory BIO to the back end of the filter bio so that your 
 output can be accumulated.

 There are samples on how to do this in the OpenSSL book as well as a 
 rather lengthy discussion on BIO's in general.

 Also BIO_get_mem_ptr() gives you a pointer to BUF_MEM structure, not 
 a char*. Your compiler should have yelled at you for that.


 On Oct 13, 2005, at 12:41 PM, Adam Jones wrote:


 Below is the code I am using to try and test the base64 encode in 
 openssl. I am using rand to generate a binary and then encoding that 
 to base64. Instead of using a file, I want to use memory to output 
 the
 base64 encoded buffer. This code compiles and runs, but my output 
 buffer is all 0. Any help would be appreciated. What have I missed?

 The variable written does show 16 like it should..help!

 #include iostream
 #include memory.h
 #include evp.h
 #include rand.h
 #include bio.h

 using namespace std;

 int main()
 {
  BIO *b64;
  unsigned char *pbuffer = new unsigned char [16];  unsigned char 
 *pOutput = new unsigned char [100];  int written;

  memset(pOutput, '0', 100);
  RAND_bytes(pbuffer, 16);
  b64 = BIO_new(BIO_f_base64());
  written = BIO_write(b64, pbuffer, 16);

  cout  written  endl;

  BIO_get_mem_ptr(b64, pOutput);

  for ( int nLoop = 0; nLoop 16; nLoop++)  {  cout  pOutput[nLoop]; 
 }  cout  \n  endl;

  BIO_free_all(b64);




 Confidentiality Notice:

 This e-mail and any files transmitted with it are confidential and 
 intended solely for the use of the individual or entity to whom they 
 are addressed.  If you are not the named addressee you should not 
 disseminate, distribute or copy this e-mail. Please notify the sender 
 immediately by e-mail if you have received this e-mail by mistake and 
 delete this e-mail from your system.  If you are not the intended 
 recipient you are notified that disclosing, copying, distributing or 
 taking any action in reliance on the contents of this information is 
 strictly prohibited.
 __
 OpenSSL Project http://www.openssl.org

Re: Base64 Help

2005-10-17 Thread Dr. Stephen Henson
On Mon, Oct 17, 2005, Adam Jones wrote:

 int main (void)
 {
  BIO *bmem, *b64;
  BUF_MEM *bptr;
  char message[] = Hello World \n;
  int written = 0;
  
  b64 = BIO_new(BIO_f_base64());
  bmem = BIO_new(BIO_s_mem());
  b64 = BIO_push(b64, bmem);
  written = BIO_write(b64, message, strlen(message));
  cout  written  endl;
  BIO_get_mem_ptr(b64, bptr);
  BIO_flush(b64);
  BIO_free_all(b64);
 }
  
 This should be straight forward, but it is not. It appears that base64
 encoding to something other than stdout or a file does not work. I am using
 vc++ 6.0, on windows platform. I can't get it to work with stdout either. I
 get no compile or runtime errors. The bptr gets a valid address, but the
 address has nothing in it. Also the system tells me that 13 characters were
 written, which is the correct number.Does anyone see why this is not working
 correctly? I have even change the line BIO_get_mem_ptr(b64, bptr); to
 BIO_get_mem_ptr(bmem, bptr); which does nothing.
 
 Thanks in Advance... 
 

Have you tried looking at the contents of bptr before you free the BIOs? The
BIO_free_all() calls will free up the memory buffer.

Steve.
--
Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage
OpenSSL project core developer and freelance consultant.
Funding needed! Details on homepage.
Homepage: http://www.drh-consultancy.demon.co.uk
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   [EMAIL PROTECTED]


Re: Base64 Help

2005-10-17 Thread Rich Salz

//  Set up a base64 encoding BIO that writes to a memory BIO.
BIO* b64 = BIO_new(BIO_f_base64());
BIO* out = BIO_new(BIO_s_mem());
BIO_set_flags(out, BIO_CLOSE);  // probably redundant
b64 = BIO_push(b64, out);

//  Send the data.
// e.g., i2d_X509_bio(b64, mX509);
BIO_write(b64, message, strlen(message));

//  Collect the encoded data.
BIO_flush(b64);
char* temp;
int count = BIO_get_mem_data(out, temp);

// ... use the data, and then:
BIO_free_all(b64);
//  temp is now invalid!

--
Rich Salz, Chief Security Architect
DataPower Technology   http://www.datapower.com
XS40 XML Security Gateway   http://www.datapower.com/products/xs40.html
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   [EMAIL PROTECTED]


RE: Base64 Help

2005-10-17 Thread Adam Jones
Thank you! It finally works...It appears you have to flush the BIO
before you get a pointer to it (as shown in your code below. Thanks! 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Rich Salz
Sent: Monday, October 17, 2005 12:41 PM
To: Adam Jones
Cc: openssl-users@openssl.org
Subject: Re: Base64 Help

 //  Set up a base64 encoding BIO that writes to a memory BIO.
 BIO* b64 = BIO_new(BIO_f_base64());
 BIO* out = BIO_new(BIO_s_mem());
 BIO_set_flags(out, BIO_CLOSE);  // probably redundant
 b64 = BIO_push(b64, out);

 //  Send the data.
 // e.g., i2d_X509_bio(b64, mX509);
BIO_write(b64, message, strlen(message));

 //  Collect the encoded data.
 BIO_flush(b64);
 char* temp;
 int count = BIO_get_mem_data(out, temp);

// ... use the data, and then:
 BIO_free_all(b64);
//  temp is now invalid!

--
Rich Salz, Chief Security Architect
DataPower Technology   http://www.datapower.com
XS40 XML Security Gateway   http://www.datapower.com/products/xs40.html
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   [EMAIL PROTECTED]




Confidentiality Notice:

This e-mail and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed.  If 
you are not the named addressee you should not disseminate, distribute or copy 
this e-mail. Please notify the sender immediately by e-mail if you have 
received this e-mail by mistake and delete this e-mail from your system.  If 
you are not the intended recipient you are notified that disclosing, copying, 
distributing or taking any action in reliance on the contents of this 
information is strictly prohibited.
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   [EMAIL PROTECTED]


Re: Base64 Help

2005-10-13 Thread Joseph Oreste Bruni
b64 is a filter BIO, it won't hold on to your data. You need to  
append a memory BIO to the back end of the filter bio so that your  
output can be accumulated.


There are samples on how to do this in the OpenSSL book as well as a  
rather lengthy discussion on BIO's in general.


Also BIO_get_mem_ptr() gives you a pointer to BUF_MEM structure,  
not a char*. Your compiler should have yelled at you for that.



On Oct 13, 2005, at 12:41 PM, Adam Jones wrote:

Below is the code I am using to try and test the base64 encode in  
openssl. I am using rand to generate a binary and then encoding  
that to base64. Instead of using a file, I want to use memory to  
output the base64 encoded buffer. This code compiles and runs, but  
my output buffer is all 0. Any help would be appreciated. What have  
I missed?


The variable written does show 16 like it should..help!

#include iostream
#include memory.h
#include evp.h
#include rand.h
#include bio.h

using namespace std;

int main()
{
 BIO *b64;
 unsigned char *pbuffer = new unsigned char [16];
 unsigned char *pOutput = new unsigned char [100];
 int written;

 memset(pOutput, '0', 100);
 RAND_bytes(pbuffer, 16);
 b64 = BIO_new(BIO_f_base64());
 written = BIO_write(b64, pbuffer, 16);

 cout  written  endl;

 BIO_get_mem_ptr(b64, pOutput);

 for ( int nLoop = 0; nLoop 16; nLoop++)
 {
 cout  pOutput[nLoop];
 }
 cout  \n  endl;

 BIO_free_all(b64);




smime.p7s
Description: S/MIME cryptographic signature


RE: Base64 Help

2005-10-13 Thread Adam Jones
Visual C++ did not complain nor did it error out when it ran, but you are
correct it does take a BUF_MEM structure. I also added another BIO method to
the code. I also read that section in the book you suggested. I also made
the code simple, but it appears that it still does not give me the base64
encoding. Any suggestions...

int main()
{
BIO *bmem, *b64;
char message[] = Hello World \n;
int written = 0;

b64 = BIO_new(BIO_f_base64());
bmem = BIO_new(BIO_s_mem());
bmem = BIO_push(b64, bmem);
written = BIO_write(b64, message, strlen(message));
cout  written  endl;
BIO_flush(b64);
BIO_free_all(b64);
}

 

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Joseph Oreste Bruni
Sent: Thursday, October 13, 2005 2:46 PM
To: openssl-users@openssl.org
Subject: Re: Base64 Help

b64 is a filter BIO, it won't hold on to your data. You need to append a
memory BIO to the back end of the filter bio so that your output can be
accumulated.

There are samples on how to do this in the OpenSSL book as well as a rather
lengthy discussion on BIO's in general.

Also BIO_get_mem_ptr() gives you a pointer to BUF_MEM structure, not a
char*. Your compiler should have yelled at you for that.


On Oct 13, 2005, at 12:41 PM, Adam Jones wrote:

 Below is the code I am using to try and test the base64 encode in 
 openssl. I am using rand to generate a binary and then encoding that 
 to base64. Instead of using a file, I want to use memory to output the 
 base64 encoded buffer. This code compiles and runs, but my output 
 buffer is all 0. Any help would be appreciated. What have I missed?

 The variable written does show 16 like it should..help!

 #include iostream
 #include memory.h
 #include evp.h
 #include rand.h
 #include bio.h

 using namespace std;

 int main()
 {
  BIO *b64;
  unsigned char *pbuffer = new unsigned char [16];  unsigned char 
 *pOutput = new unsigned char [100];  int written;

  memset(pOutput, '0', 100);
  RAND_bytes(pbuffer, 16);
  b64 = BIO_new(BIO_f_base64());
  written = BIO_write(b64, pbuffer, 16);

  cout  written  endl;

  BIO_get_mem_ptr(b64, pOutput);

  for ( int nLoop = 0; nLoop 16; nLoop++)  {  cout  pOutput[nLoop];  
 }  cout  \n  endl;

  BIO_free_all(b64);



Confidentiality Notice:

This e-mail and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed.  If 
you are not the named addressee you should not disseminate, distribute or copy 
this e-mail. Please notify the sender immediately by e-mail if you have 
received this e-mail by mistake and delete this e-mail from your system.  If 
you are not the intended recipient you are notified that disclosing, copying, 
distributing or taking any action in reliance on the contents of this 
information is strictly prohibited.
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   [EMAIL PROTECTED]


Re: Base64 Help

2005-10-13 Thread Thomas J. Hruska

Adam Jones wrote:

Visual C++ did not complain nor did it error out when it ran, but you are
correct it does take a BUF_MEM structure. I also added another BIO method to
the code. I also read that section in the book you suggested. I also made
the code simple, but it appears that it still does not give me the base64
encoding. Any suggestions...

int main()
{
BIO *bmem, *b64;
char message[] = Hello World \n;
int written = 0;

b64 = BIO_new(BIO_f_base64());
bmem = BIO_new(BIO_s_mem());
bmem = BIO_push(b64, bmem);
written = BIO_write(b64, message, strlen(message));
cout  written  endl;
BIO_flush(b64);
BIO_free_all(b64);
}


Take a good look at that code...you create the memory BIO, but then 
never bother to use it.  Specifically, you probably mean:


b64 = BIO_push(b64, bmem);

--
Thomas Hruska
Shining Light Productions

Home of BMP2AVI, Nuclear Vision, ProtoNova, and Win32 OpenSSL.
http://www.slproweb.com/

Ask me about discounts on any Shining Light Productions product!

__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   [EMAIL PROTECTED]


Re: Base64 Help

2005-10-13 Thread Joseph Oreste Bruni

Using VC++ is your first problem... :)

The call to BIO_push is your problem. You overwrite your reference to  
the b64 BIO with another reference to the mem BIO. So now, b64 points  
to mem.


Do this:

int main()
{
BIO *bmem, *b64;
char message[] = Hello World \n;
int written = 0;

b64 = BIO_new(BIO_f_base64());
bmem = BIO_new_fp(stdout,0);
b64 = BIO_push(b64, bmem);
written = BIO_write(b64, message, strlen(message));
cout  written  endl;
BIO_flush(b64);
BIO_free_all(b64);
}

This will output your Base64 to stdout. Then if you need to use a mem  
BIO just change out the call to what you had, but you'll need to get  
pointers to the data to display it (or whatever).





On Oct 13, 2005, at 1:55 PM, Adam Jones wrote:

Visual C++ did not complain nor did it error out when it ran, but  
you are
correct it does take a BUF_MEM structure. I also added another BIO  
method to
the code. I also read that section in the book you suggested. I  
also made
the code simple, but it appears that it still does not give me the  
base64

encoding. Any suggestions...

int main()
{
BIO *bmem, *b64;
char message[] = Hello World \n;
int written = 0;

b64 = BIO_new(BIO_f_base64());
bmem = BIO_new(BIO_s_mem());
bmem = BIO_push(b64, bmem);
written = BIO_write(b64, message, strlen(message));
cout  written  endl;
BIO_flush(b64);
BIO_free_all(b64);
}



-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Joseph Oreste  
Bruni

Sent: Thursday, October 13, 2005 2:46 PM
To: openssl-users@openssl.org
Subject: Re: Base64 Help

b64 is a filter BIO, it won't hold on to your data. You need to  
append a
memory BIO to the back end of the filter bio so that your output  
can be

accumulated.

There are samples on how to do this in the OpenSSL book as well as  
a rather

lengthy discussion on BIO's in general.

Also BIO_get_mem_ptr() gives you a pointer to BUF_MEM structure,  
not a

char*. Your compiler should have yelled at you for that.


On Oct 13, 2005, at 12:41 PM, Adam Jones wrote:



Below is the code I am using to try and test the base64 encode in
openssl. I am using rand to generate a binary and then encoding that
to base64. Instead of using a file, I want to use memory to output  
the

base64 encoded buffer. This code compiles and runs, but my output
buffer is all 0. Any help would be appreciated. What have I missed?

The variable written does show 16 like it should..help!

#include iostream
#include memory.h
#include evp.h
#include rand.h
#include bio.h

using namespace std;

int main()
{
 BIO *b64;
 unsigned char *pbuffer = new unsigned char [16];  unsigned char
*pOutput = new unsigned char [100];  int written;

 memset(pOutput, '0', 100);
 RAND_bytes(pbuffer, 16);
 b64 = BIO_new(BIO_f_base64());
 written = BIO_write(b64, pbuffer, 16);

 cout  written  endl;

 BIO_get_mem_ptr(b64, pOutput);

 for ( int nLoop = 0; nLoop 16; nLoop++)  {  cout  pOutput[nLoop];
}  cout  \n  endl;

 BIO_free_all(b64);





Confidentiality Notice:

This e-mail and any files transmitted with it are confidential and  
intended solely for the use of the individual or entity to whom  
they are addressed.  If you are not the named addressee you should  
not disseminate, distribute or copy this e-mail. Please notify the  
sender immediately by e-mail if you have received this e-mail by  
mistake and delete this e-mail from your system.  If you are not  
the intended recipient you are notified that disclosing, copying,  
distributing or taking any action in reliance on the contents of  
this information is strictly prohibited.

__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   [EMAIL PROTECTED]





smime.p7s
Description: S/MIME cryptographic signature