Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

238
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda