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

119
Vistas
How to calculate SHA hash of a string in browser JavaScript

Very new to JavaScript I am.

What I think I know

  • There's the CryptoJS module for the frontend.
  • There's a Closure Library by Google.

I tried

  • Using the CryptoJS module. But I didn't get the hexadecimal hash.
  • Using the closure library according to this doc, this example and from this cdn.

But my question is

  • Is there a native crypto library on browser?
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

There is a native browser crypto.

A code example for what you want is:

const text = 'An obscure body in the S-K System, your majesty. The inhabitants refer to it as the planet Earth.';

async function digestMessage(message) {
  const encoder = new TextEncoder();
  const data = encoder.encode(message);
  const hash = await crypto.subtle.digest('SHA-256', data);
  return hash;
}

digestMessage(text)
  .then(digestBuffer => console.log(digestBuffer.byteLength));

The above example is found here which is a good start for in-browser cryptography.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Re : "Is there a native crypto library on browser?"

You may use CDN library.

https://cdnjs.com/libraries/crypto-js

Please quote the following script tag into your html :

<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js" integrity="sha512-E8QSvWZ0eCLGk4km3hxSsNmGWbLtSCSUcewDQPQWZF6pEU8GlT8a5fF32wOl1i8ftdMhssTrF/OhyGWwonTcXA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>

For how to use the methods from the library , please refer to the website below :

https://cryptojs.gitbook.io/docs/

The following page shows an example where my suggestion comes from :

https://codepen.io/omararcus/pen/QWwBdmo

about 4 years ago · Juan Pablo Isaza 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