Sorry!
I have missed the following lines:

With previous version of Openssl, this code works fine. With actual
version (0.9.7.c) this code don't works. For example With n=1000 the
function decode return only 960 charaters. The last value of n that
works is n=720.

What is going wrong?


 
> g.sellitto>
> g.sellitto> 
> g.sellitto> I have de following code:
> g.sellitto> 
> g.sellitto> class CBase64
> g.sellitto> {
> g.sellitto> public:
> g.sellitto>     int encode(unsigned char* aPlain,char** 
> aOut,int aInlen);
> g.sellitto>     int decode(char* aPlain, std::string& strout);
> g.sellitto> };
> g.sellitto> 
> g.sellitto> int CBase64::encode(unsigned char* aPlain,char** 
> aOut,int aInlen) 
> g.sellitto> {
> g.sellitto>     int i;
> g.sellitto>     BIO *mbio,*b64bio,*bio;
> g.sellitto>     char* p=(char*)NULL;
> g.sellitto> 
> g.sellitto>     mbio=BIO_new(BIO_s_mem());
> g.sellitto>     b64bio=BIO_new(BIO_f_base64());
> g.sellitto>     
> g.sellitto>     //BIO_set_flags(b64bio,BIO_FLAGS_BASE64_NO_NL);
> g.sellitto> 
> g.sellitto>     bio=BIO_push(b64bio,mbio);
> g.sellitto>     BIO_write(bio,aPlain,aInlen);
> g.sellitto>     BIO_flush(bio);
> g.sellitto> 
> g.sellitto> 
> g.sellitto>     i=(int)BIO_ctrl(mbio,BIO_CTRL_INFO,0,(char *)&p);
> g.sellitto> 
> g.sellitto>     if(i>0) {
> g.sellitto>     *aOut=(char*)malloc(i);
> g.sellitto>     memcpy(*aOut,p,i);
> g.sellitto>     }
> g.sellitto> 
> g.sellitto>     BIO_free_all(bio);
> g.sellitto>     return i;
> g.sellitto> }
> g.sellitto> 
> g.sellitto> int CBase64::decode(char* aPlain, std::string& strout) 
> g.sellitto> {
> g.sellitto>     int i;
> g.sellitto>     BIO *mbio,*b64bio,*bio;
> g.sellitto>     unsigned char *buf;
> g.sellitto> 
> g.sellitto>     mbio=BIO_new(BIO_s_mem());
> g.sellitto>     b64bio=BIO_new(BIO_f_base64());
> g.sellitto> 
> g.sellitto> 
> g.sellitto>     //BIO_set_flags(b64bio,BIO_FLAGS_BASE64_NO_NL);
> g.sellitto>     BIO_puts(mbio,aPlain);
> g.sellitto>     BIO_flush(mbio);
> g.sellitto> 
> g.sellitto>     bio=BIO_push(b64bio,mbio);
> g.sellitto> 
> g.sellitto>     size_t t= BIO_ctrl_pending(bio);
> g.sellitto>     buf = (unsigned char*)malloc(t);
> g.sellitto>     i=BIO_read(bio, (void*)buf, t);
> g.sellitto>     if(i>0) 
> g.sellitto>     {
> g.sellitto>         strout.append((char*)buf,i);
> g.sellitto>     }
> g.sellitto> 
> g.sellitto>     BIO_free_all(bio);
> g.sellitto>     return i;
> g.sellitto> }
> g.sellitto> 
> g.sellitto> int main(int argc, char* argv[])
> g.sellitto> {
> g.sellitto>     
> g.sellitto>     // this is just a sample
> g.sellitto>     int n=1000;
> g.sellitto>     std::string str(n,'w');
> g.sellitto>              
> g.sellitto>     CBase64 b;
> g.sellitto>     char* out=0;
> g.sellitto>     b.encode((unsigned 
> char*)str.c_str(),&out,str.length());
> g.sellitto> 
> g.sellitto>     std::string strout;
> g.sellitto>     b.decode(out,strout);
> g.sellitto> 
> g.sellitto> 
> g.sellitto>   return 0;
> g.sellitto> }
> 

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to