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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:49:39+00:00 2026-06-09T12:49:39+00:00

how to do this in Javascript or Jquery? Please suggest in 2 steps: 1.-

  • 0

how to do this in Javascript or Jquery?

Please suggest in 2 steps:

1.- Word Array to Single Byte Array.

2.- Byte Array to String.

Maybe this can help:

function hex2a(hex) {
    var str = '';
    for (var i = 0; i < hex.length; i += 2)
        str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
    return str;
}
  • 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-09T12:49:40+00:00Added an answer on June 9, 2026 at 12:49 pm

    What you are trying to achieve is already implemented in CryptoJS. From the documentation:

    You can convert a WordArray object to other formats by explicitly calling the toString method and passing an encoder.

    var hash = CryptoJS.SHA256("Message");
    alert(hash.toString(CryptoJS.enc.Base64));
    alert(hash.toString(CryptoJS.enc.Hex));
    

    Honestly I have no idea why you want to implement that yourself… But if you absolutely need to do it “manually” in the 2 steps you mentioned, you could try something like this:

    function wordToByteArray(wordArray) {
        var byteArray = [], word, i, j;
        for (i = 0; i < wordArray.length; ++i) {
            word = wordArray[i];
            for (j = 3; j >= 0; --j) {
                byteArray.push((word >> 8 * j) & 0xFF);
            }
        }
        return byteArray;
    }
    
    function byteArrayToString(byteArray) {
        var str = "", i;
        for (i = 0; i < byteArray.length; ++i) {
            str += escape(String.fromCharCode(byteArray[i]));
        }
        return str;
    }
    
    var hash = CryptoJS.SHA256("Message");
    var byteArray = wordToByteArray(hash.words);
    alert(byteArrayToString(byteArray));
    

    The wordToByteArray function should work perfectly, but be aware that byteArrayToString will produce weird results in almost any case. I don’t know much about encodings, but ASCII only uses 7 bits so you won’t get ASCII chars when trying to encode an entire byte. So I added the escape function to at least be able to display all those strange chars you might get. 😉

    I’d recommend you use the functions CryptoJS has already implemented or just use the byte array (without converting it to string) for your analysis.

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

Sidebar

Related Questions

Can someone please help me out with a JavaScript/jQuery solution for this arithmetic problem:
How can I do this in Javascript/jQuery from PHP? I am trying to populate
JavaScript/JQuery var arr=[]; $('.element').each(function(i) { arr.push({id:i,value:$(this).attr('data-value')}); }); $.get('/json.php?arr='+arr,function(result) { alert(result); }); PHP <?php $j
Possible Duplicates: How does this JavaScript/JQuery Syntax work: (function( window, undefined ) { })(window)?
i am getting script error in Jquery. please suggest how to resolve this. Script
I have this Javascript/JQuery code: <script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js></script> <script type=text/javascript> name = $(#name).val(); alert(Name:
I am wondering if there is a better way to write this JavaScript (Jquery)
This will be implemented in Javascript (jQuery) but I suppose the method could be
Could this be done with javascript/jQuery : <div class=number>99,123,123</div> <div class=number>123,123,123</div> <div class=number>1,123,123,123</div> <div
I have this javascript code below that uses jquery, it is suppoed to be

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.