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 9132195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:16:13+00:00 2026-06-17T08:16:13+00:00

I am trying to get Base 64 encode value for a string value simple

  • 0

I am trying to get Base 64 encode value for a string value “simple” by using the implementation mentioned here

#include<openssl/sha.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdint.h>
#include<stdlib.h>


static char encoding_table[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
                                'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
                                'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
                                'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
                                'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
                                'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
                                'w', 'x', 'y', 'z', '0', '1', '2', '3',
                                '4', '5', '6', '7', '8', '9', '+', '/'};

static int mod_table[] = {0,2,1};

char *base64_encode(const unsigned char *data,
                    size_t input_length,
                    size_t *output_length)
{
        printf("-- Begins -- ");
        *output_length = (size_t) (4.0 * ceil((double) input_length / 3.0));
        char *encoded_data = malloc(*output_length);

        for (int i = 0, j = 0; i < input_length;) {

        uint32_t octet_a = i < input_length ? data[i++] : 0;
        uint32_t octet_b = i < input_length ? data[i++] : 0;
        uint32_t octet_c = i < input_length ? data[i++] : 0;

        uint32_t triple = (octet_a << 0x10) + (octet_b << 0x08) + octet_c;

        encoded_data[j++] = encoding_table[(triple >> 3 * 6) & 0x3F];
        encoded_data[j++] = encoding_table[(triple >> 2 * 6) & 0x3F];
        encoded_data[j++] = encoding_table[(triple >> 1 * 6) & 0x3F];
        encoded_data[j++] = encoding_table[(triple >> 0 * 6) & 0x3F];
        }

    for (int i = 0; i < mod_table[input_length % 3]; i++)
        encoded_data[*output_length - 1 - i] = '=';
        printf(" -- Ends -- ");

    return encoded_data;


   }

int main(int argc, char **argv)
{
        unsigned char ibuf[] = "simple";
        size_t *outLen;
        size_t *inLen = (size_t) strlen(ibuf);
        char *encodeVal = base64_encode(ibuf, inLen, outLen);
        return(0);
}

When I tried debugging using gdb, all I got was:

Program received signal SIGSEGV, Segmentation fault.
0x000000000040073f in base64_encode (data=0x7fff65298a90 "simple", input_length=6, output_length=0x400a50) at openSha.c:25
25              *output_length = (size_t) (4.0 * ceil((double) input_length / 3.0));

What is the error here? I haven’t coded for a long time in C, so I am sorry if I am missing something obvious here.

  • 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-06-17T08:16:14+00:00Added an answer on June 17, 2026 at 8:16 am
     size_t *inLen = (size_t) strlen(ibuf);
    

    This looks wrong.

    inLen is a pointer to size_t but you are assigning it a size_t value.

    Also this call:

    base64_encode(ibuf, inLen, outLen);
    

    base64_encode expects a size_t as its second argument but you are passing a size_t *.

    And finally outLen is not initialized but you are passing its value to base64_encode.

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

Sidebar

Related Questions

I am trying get all html links within a string and replace them using
I am trying get all html links within a string and replace them using
I'm trying to get the base url (for example: https://stackoverflow.com/ ) without using javascript.
I am trying to get a search result base on category and keyword(using like
I'm trying to get a value that is associated (through mysql data-base row) to
I am trying get Struts 2 and Tiles to work and I am using
trying to get same string on tooltip as is in the Text e.g. Text=<%#
Trying to get a random string out of ListArray on the button pressed. Always
I am trying to get the base URL from the worker role. I can't
I am trying to get the image base of my process once it is

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.