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

  • Home
  • SEARCH
  • 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 4025844
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:53:49+00:00 2026-05-20T10:53:49+00:00

Whenever I try to base64 decode files (using OpenSSL’s BIO_f_base64() ) larger than 8192,

  • 0

Whenever I try to base64 decode files (using OpenSSL’s BIO_f_base64()) larger than 8192, I always seem to get some wrong value.

What is with this magic number 8192? Any help to educate me is greatly appreciated!

UPDATED:

Here is part of my code:

int dgst(char *alg)
 {
 EVP_MD_CTX ctx;
 const EVP_MD *md;
 unsigned char md_value[EVP_MAX_MD_SIZE];
 unsigned int md_len, i;
 char *toB64val = NULL;
 char *data = NULL;

 OpenSSL_add_all_digests();

 md = EVP_get_digestbyname(alg);

 if(!md) {
        printf("Unknown message digest %s\n", alg);
        exit(1);
 }

 data = readFileBuffer("file_out");
 printf("strlen(data) %d\n", strlen(data));
 EVP_MD_CTX_init(&ctx);
 EVP_DigestInit_ex(&ctx, md, NULL);
 EVP_DigestUpdate(&ctx, data, strlen(data));

 EVP_DigestFinal_ex(&ctx, md_value, &md_len); //retrieve digest from ctx unto md_value and #bytes written is copied into   md_len
 EVP_MD_CTX_cleanup(&ctx);
 unsigned char *copy = malloc(md_len);
 memcpy(copy, md_value, md_len);
 char *buff = encbase64(copy, md_len);

 printf("Digest is:%s\n ", buff);

 free(buff);
 free(toB64val);
 free(data);
 return 0;
 }


char *readFileBuffer(char *name)
{
    FILE *file;
    char *buffer = NULL;
    unsigned long fileLen;
    //Open file
    file = fopen(name, "rb");
    if (!file)
    {
        fprintf(stderr, "Unable to open file %s", name);
        return;
    }
    //Get file length
    fseek(file, 0, SEEK_END);
    fileLen=ftell(file);
    printf("file length  = %ld\n", fileLen);
    fseek(file, 0, SEEK_SET);

    //printf("Allocate memory\n");
    buffer=(char *)malloc(fileLen+1);
    printf("length of write buffer = %d\n", strlen(buffer));
    if (!buffer)
    {
        fprintf(stderr, "Memory error!");

    }

    long int n = fread(buffer,1, fileLen,file);
    buffer[n] = '\0';
    printf("Read no. of bytes = %ld into buffer \n", n);
    printf("len of buffer  %d  \n", strlen(buffer));
    if (!buffer)
    {
        fprintf(stderr, "Memory error!");
        fclose(file);
    }
    fclose(file);
    return buffer;

}

char *encbase64( char *input, int length)
{
BIO *bmem, *b64;
BUF_MEM *bptr;

b64 = BIO_new(BIO_f_base64());
//BIO_set_flags(b64,BIO_FLAGS_BASE64_NO_NL);
bmem = BIO_new(BIO_s_mem());
b64 = BIO_push(b64, bmem);

BIO_write(b64, input, length);
BIO_flush(b64);
BIO_get_mem_ptr(b64, &bptr);


char *buff = (char *)malloc(bptr->length);
memcpy(buff, bptr->data, bptr->length-1);
buff[bptr->length-1] = 0;


BIO_free_all(b64);

return buff;
}
  • 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-20T10:53:49+00:00Added an answer on May 20, 2026 at 10:53 am

    it doesn’t seem to have any problems with 8k boundaries. could you show us soucecode how you call it?

    update:

    int dgst(char *alg)
     {
     EVP_MD_CTX ctx;
     const EVP_MD *md;
     unsigned char md_value[EVP_MAX_MD_SIZE];
     unsigned int md_len, i;
     char *toB64val = NULL;
     char *data = NULL;
    
     OpenSSL_add_all_digests();
    
     md = EVP_get_digestbyname(alg);
    
     if(!md) {
            printf("Unknown message digest %s\n", alg);
            exit(1);
     }
    
     data = readFileBuffer("file_out");
     //printf("strlen(data) %d\n", strlen(data)); <- don't use strlen on binary data
     EVP_MD_CTX_init(&ctx);
     EVP_DigestInit_ex(&ctx, md, NULL);
     EVP_DigestUpdate(&ctx, data, strlen(data));
    
     EVP_DigestFinal_ex(&ctx, md_value, &md_len); //retrieve digest from ctx unto md_value and #bytes written is copied into   md_len
     EVP_MD_CTX_cleanup(&ctx);
     unsigned char *copy = malloc(md_len);
     memcpy(copy, md_value, md_len);
     char *buff = encbase64(copy, md_len);
    
     printf("Digest is:%s\n ", buff);
    
     free(buff);
     free(toB64val);
     free(data);
     return 0;
     }
    
    
    char *readFileBuffer(char *name)
    {
        FILE *file;
        char *buffer = NULL;
        unsigned long fileLen;
        //Open file
        file = fopen(name, "rb");
        if (!file)
        {
            fprintf(stderr, "Unable to open file %s", name);
            return;
        }
        //Get file length
        fseek(file, 0, SEEK_END);
        fileLen=ftell(file);
        printf("file length  = %ld\n", fileLen);
        fseek(file, 0, SEEK_SET);
    
        //printf("Allocate memory\n");
        buffer=(char *)malloc(fileLen/*+1*/); // <- not a string - no need to +1
        //printf("length of write buffer = %d\n", strlen(buffer)); <- again strlen on binary data (you just allocated it, so it contains random bytes)
        if (!buffer)
        {
            fprintf(stderr, "Memory error!");
    
        }
    
        long int n = fread(buffer,1, fileLen,file);
        //buffer[n] = '\0';                  // not a string - no need to end it
        printf("Read no. of bytes = %ld into buffer \n", n);
        //printf("len of buffer  %d  \n", strlen(buffer));  <- buffer length is in 'n'
        if (!buffer)
        {
            fprintf(stderr, "Memory error!");
            fclose(file);
        }
        fclose(file);
        return buffer;
    
    }
    
    char *encbase64( char *input, int length)
    {
    BIO *bmem, *b64;
    BUF_MEM *bptr;
    
    b64 = BIO_new(BIO_f_base64());
    //BIO_set_flags(b64,BIO_FLAGS_BASE64_NO_NL);
    bmem = BIO_new(BIO_s_mem());
    b64 = BIO_push(b64, bmem);
    
    BIO_write(b64, input, length);
    BIO_flush(b64);
    BIO_get_mem_ptr(b64, &bptr);
    
    
    char *buff = (char *)malloc(bptr->length);
    memcpy(buff, bptr->data, bptr->length/*-1*/); // removed '+1'
    //buff[bptr->length-1] = 0;       // not a string
    
    
    BIO_free_all(b64);
    
    return buff;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Whenever I try to install a Click Once application, I always get a 404
Whenever I try to copy an entire working copy using simple drag and drop
I get the above error whenever I try and use ActionLink ? I've only
Whenever i try to open my Entity Model, i get a not very helpful
Whenever i try to run sqlmetal, i get this: 'sqlmetal' is not recognized as
Whenever I try to upload a sound file IO get the error The connection
Whenever I try to add a new project to my SourceSafe repository it creates
Whenever I try to write graphical programs (whether a game or really any GUI
whenever I try to run something in Java, Eclipse changes into the PHP perspective.
Why in Windows, can't you name a folder 'con'? Whenever I try to name

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.