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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:04:23+00:00 2026-06-14T23:04:23+00:00

I am using openssl libraries for purpose of encoding and decoding to base64, This

  • 0

I am using openssl libraries for purpose of encoding and decoding to base64, This is my encryption code

#include <openssl/buffer.h>
#include <stdlib.h>
char *base64(const unsigned char *input, int length);

int main(int argc, char **argv)
{
   char nonce[10];
   srand(time(NULL));
   printf("rand():%d\n", rand());
   sprintf(nonce, "%d", rand());
   char *output = base64(nonce, sizeof(nonce));
   printf("Base64: *%s*\n", output);
   free(output);
}

char *base64(const unsigned char *input, int length)
{
  BIO *bmem, *b64;
  BUF_MEM *bptr;
  char *buff;
  b64 = BIO_new(BIO_f_base64());
  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);
  buff = (char *) malloc(bptr->length);
  memcpy(buff, bptr->data, bptr->length-1);
  buff[bptr->length-1] = '\0';
  BIO_free_all(b64);
  return buff;
}

The o/p of this when was NjI0MjQ3MwAECA== the rand() output was 1308702736 (This is a an example for one instance of rand gen o/p), when i used the decode function to decode this value i get 6242473, which is totally diff, i have to get 1308702736 when decoded,

My decode function is as follows

#include <string.h>
#include <openssl/sha.h>
#include <openssl/hmac.h>
#include <openssl/evp.h>
#include <openssl/bio.h>
#include <openssl/buffer.h>

char *unbase64(unsigned char *input, int length);

int main(int argc, char **argv)
{
   char *output = unbase64("NjI0MjQ3MwAECA==\n", strlen("NjI0MjQ3MwAECA==\n"));
   printf("Unbase64: *%s*\n", output);
   free(output);
}
char *unbase64(unsigned char *input, int length)
{
   BIO *b64, *bmem;
   char *buffer = (char *)malloc(length);
   memset(buffer, 0, length);
   b64 = BIO_new(BIO_f_base64());
   bmem = BIO_new_mem_buf(input, length);
   bmem = BIO_push(b64, bmem);
   BIO_read(bmem, buffer, length);
   BIO_free_all(bmem);

   return buffer;
}

NOTE: to compile this code v have to use -lcrypto
I need a help in solving this i am stuck here, googled for solutions but didn’t get any,and have one more doubt why input to base64 decoder b terminated by \n ? can one one help me out in this

  • 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-14T23:04:24+00:00Added an answer on June 14, 2026 at 11:04 pm
    printf("rand():%d\n", rand());
    sprintf(nonce, "%d", rand());
    

    You call rand twice, giving you two different numbers. NjI0MjQ3MwAECA== decodes to 624247.

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

Sidebar

Related Questions

I'm looking for an example of using OpenSSL's AES CCM encryption. Apparently, this is
I have included the following header files in a C code using openssl libraries.
I'm using openssl BIO objects to convert a binary string into a base64 string.
I am using openssl APIs for AES in my code. What I noticed that
I'm trying to make simple IMAP client using winsock/OpenSSL, is this possible without additional
When using Delphi 2007 along with Indy 9, what are the latest OpenSSL libraries
I am using RSA algorithm for shared key encryption/decryption.I am using open ssl libraries
Note: Using OpenSSL for symmetric encryption of text. I made a Ruby script to
Whenever I try to base64 decode files (using OpenSSL's BIO_f_base64() ) larger than 8192,
For using openSSL API for public key encryption, how is the key (public &

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.