Main Page | Report this Page
 
   
Science Forum Index  »  Cryptography Forum  »  decode base64...
Page 1 of 1    
Author Message
d-fan...
Posted: Tue May 20, 2008 11:24 am
Guest
void decodebio( unsigned char *encbuf, unsigned char * decbuf, int
destbuf ) {


/* Read Base64 encoded data from standard input and write the
decoded data to standard output: */

BIO *b64, *bio ;
long i ;
char buffer[512] ;
memset(buffer, 0, 512) ;

b64 = BIO_new(BIO_f_base64() ) ;
bio = BIO_new(BIO_s_mem()) ;

i=BIO_write(bio, encbuf, strlen(encbuf)) ;

bio = BIO_push(b64, bio) ;
//i = BIO_ctrl_pending(bio);
i = BIO_read(bio, decbuf, 1024) ;
printf( "the old buffer size is %d %d\n\r", i, strlen(decbuf)) ;

BIO_set_mem_eof_return(bio,0) ;
BIO_free_all(bio) ;
printf( "the resulting data is Length %d size %d text %s \n\r" ,
strlen(decbuf), sizeof(decbuf)) ;
}
int main(int argc, char **argv)
{
char *plain ;
unsigned char filebuf[1024] ;
unsigned char decodebuf[1024] ;
unsigned char *res ;
char *enc;
char *dec;
int len;
char *key1 = "The quick brown fox jumped over the speckled orange
hen." ;
char *key2 = "The quick brown fox jumped over the speckled orange
hen." ;

if (argc != 4)
{
printf("usage: %s plaintext key1 key2\n", argv[0]);
exit(1);
}

plain = argv[1];
len = strlen(plain);

strcpy( filebuf, "the cat in the hat\n") ;
strcat( filebuf, "\0") ;
printf( "after reading file size %d %s\n\r", strlen(filebuf),
filebuf ) ;

printf( "before decoding file size %d %s\n\r", sizeof(decodebuf),
decodebuf ) ;
decodebio( filebuf, decodebuf, sizeof(decodebuf) ) ;
//printf( "after decoding file size %d %s\n\r", strlen(res), res ) ;

I am using the code above to base64 decode a string of text. When I
run the code I get not data on the output. I attempt to decode the
literal "thecat in the hat" and I get an empty string. Is there
something wrong with my code?
 
Page 1 of 1       All times are GMT - 5 Hours
The time now is Fri Aug 29, 2008 7:58 pm