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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:07:01+00:00 2026-05-31T08:07:01+00:00

We have a communication protocol that requires us to Base64 Encoded a SHA1 hash

  • 0

We have a communication protocol that requires us to Base64 Encoded a SHA1 hash of a UTF-16 encoded password. We have been given Java, javascript, and visual basic examples however we are running under Linux (redhat)

the provided test string: TESTED@8691
the final output: rBbBKqbJodT5awZal/CSCYF/sFo=

I have tried

iconv_t conv = iconv_open("UTF-16LE","ASCII"); // open succeeds
char *from_string=strdup("TESTED@8691");
size_t from_length=strlen(from_string);
size_t to_length=from_length*3;
size_t original_to_length=to_length;

char *to_string=(char*)calloc(1,to_length);
int convert_return=iconv(conv,&from_string,&from_length,&to_string,&to_length);
// convert_return is 0 indicating success, to_length is 11, from_length is 0

run sha1 and base64 encoding on to_string with a length of 22
resulting output: GCXe7HMDoq/NRqo1WWYJDDYZzP0=

If I loop through to_string I get:

for (int i=0; i<original_to_length-to_length; ++i) {
   printf("to_string %d = %x",i,to_string[i]);  
}

output:
to_string 0 = 0
to_string 1 = 0
to_string 2 = 0
to_string 3 = 0
to_string 4 = 0
to_string 5 = 0
to_string 6 = 0
to_string 7 = 0
to_string 8 = 0
to_string 9 = 0
to_string 10 = 0
to_string 11 = 0
to_string 12 = 0
to_string 13 = 0
to_string 14 = 21
to_string 15 = 0
to_string 16 = 0
to_string 17 = 0
to_string 18 = 4
to_string 19 = 7e
to_string 20 = 13
to_string 21 = e

Here is the javascript conversion:

function str2rstr_utf16le(input)
{
   var output = "";
   for(var i = 0; i < input.length; i++)
    output += String.fromCharCode( input.charCodeAt(i) & 0xFF,
                              (input.charCodeAt(i) >>> 8) & 0xFF);

   return output;
}

What am I missing?
Thank You

  • 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-31T08:07:03+00:00Added an answer on May 31, 2026 at 8:07 am

    I checked using a shell script and it seems the result you were given is indeed correct, as long as you assume UTF-16 to be UTF-16LE (Little Endian):

    $ echo -e $(echo -n 'TESTED@8691' | iconv -f utf-8 -t utf-16le | sha1sum - | egrep -o '[0-9a-f]+' | sed -r 's/(..)/\\x\1/g') | tr -d '\n'  | base64
    rBbBKqbJodT5awZal/CSCYF/sFo=
    

    For Big-Endian, I get YrAwH9v3d88gjvsg0Hypu2Cfjc8= which is not your result, so I think endianness isn’t the issue here.

    The man page for iconv(3) states:

    The  iconv  function converts one multibyte character at a
    time, and for  each  character  conversion  it  increments
    *inbuf  and  decrements *inbytesleft by the number of con­
    verted input bytes, it increments *outbuf  and  decrements
    *outbytesleft by the number of converted output bytes, and
    it updates the conversion state contained in cd.
    

    This suggests that iconv modifies your target buffer pointer (to_string) – that’s why you pass it &to_string, not to_string itself. So, probably you need to subtract the number of bytes that were processed from to_string after iconv and before the further operations (SHA1 and BASE64).

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

Sidebar

Related Questions

I have a connection protocol that has been defined by our customer. Data are
I have client/server applications and a very simple protocol for communication. More precisely, it's
I have a background thread that handles communication with an external service. Each time
I have a legacy C++ application that uses DDS for asynchronous communication/messaging. I need
I have build C# program that work with RAPI (communication to PPC or WinCE)
I have a WCF client/service app that relies on secure communication between two machines
I have a client-server application written in Java using CORBA for the communication. The
I have recently written a socket server in PHP that will be handling communication
I need to have two way communication between threads in Tcl and all I
I have recently started working with Unified Communication Managed API 2.0 (UCMA) and Office

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.