Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6966681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:13:23+00:00 2026-05-27T16:13:23+00:00

I have this buffer given: unsigned char *buffer; int buffer_length; This is how I

  • 0

I have this buffer given:

unsigned char *buffer; 
int buffer_length; 

This is how I currently convert it to a base64-encoded buffer:

BIO *mem = BIO_new(BIO_s_mem()); 
BIO *b64 = BIO_new(BIO_f_base64()); 
mem = BIO_push(b64, mem); 

int write_length = BIO_write(mem, buffer, buffer_length); 
if (write_length != buffer_length) //* 
  return -1; 

int flush_result = BIO_flush(mem); 
if (flush_result != 1) 
  return -1; 

unsigned char *result; //** 
int result_length = BIO_get_mem_data(mem, &result); 

//use the base64-encoded result to do whatever I need to do 

BIO_free_all(mem); 
return 0;

So far, this seems to be working. However, is this good and robust code? I have particular questions about the code pieces marked with asterisks above:

  • (//*) Is it correct to assume that BIO_write() will always write out the whole base64-encoded string at once, or do I have to create a loop here?
  • (//**) Is it correct to have the type unsigned char* or must I use char * instead?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:13:24+00:00Added an answer on May 27, 2026 at 4:13 pm

    //* You should put your BIO_write() in a loop. The man page is pretty clear about that (that it attempts to write the requested number of bytes), and that’s consistent with the other write stuff in C.

    //** You should use char * since that’s what the man page specifies, though I’m not sure that’s a big deal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So.. I have a buffer with MP3 data (If I would save this buffer
Say I have a line in an emacs buffer that looks like this: foo
I have a file encrypted using the following code in c: unsigned char ckey[]
I have a char (ie. byte) buffer that I'm sending over the network. At
I have an oracle function which is given below. when I run this in
If you have a pending operation, eg stream.BeginRead(_buffer, 0, _buffer.Length, _asyncCallbackRead, this); and you
I have this code in jQuery, that I want to reimplement with the prototype
I have this idea for a free backup application. The largest problem I need
I have this gigantic ugly string: J0000000: Transaction A0001401 started on 8/22/2008 9:49:29 AM
I have this line in a javascript block in a page: res = foo('<%=

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.