Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

239
Views
Javascript - Getting null when I expect number

I have some Javascript that hashes. msgBuffer definitely has bytes in it after the hash, but in the following code, the nonce ends up null. What do I need to do to add the first byte of msgBuffer to the nonce?

    var msgBuffer = await crypto.subtle.digest('SHA-256', toHash); //returns ArrayBuffer
    var nonce = 0;
    nonce += msgBuffer[0]; // results in null
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

await crypto.subtle.digest('SHA-256', toHash) would return ArrayBuffer.

You should first convert it to proper type, and then get the value.

e.g. do this.

var msgBuffer = await crypto.subtle.digest('SHA-256', toHash);
var myArr = new Uint8Array(msgBuffer);
var nonce = 0;
nonce += myArr[0];

I used Uint8Array, here because for crypto.subtle.digest this seems an appropriate choice, but for other use cases and types you expect in an ArrayBuffer in general, you should use the type array views.

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!