Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created February 12, 2022 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/326f90d14a3a3038a405e66d7c9bc6e4 to your computer and use it in GitHub Desktop.
Save parzibyte/326f90d14a3a3038a405e66d7c9bc6e4 to your computer and use it in GitHub Desktop.
const desencriptar = async (contraseña, encriptadoEnBase64) => {
const decoder = new TextDecoder();
const datosEncriptados = base64ABuffer(encriptadoEnBase64);
const sal = datosEncriptados.slice(0, LONGITUD_SAL);
const vectorInicializacion = datosEncriptados.slice(0 + LONGITUD_SAL, LONGITUD_SAL + LONGITUD_VECTOR_INICIALIZACION);
const clave = await derivacionDeClaveBasadaEnContraseña(contraseña, sal, 100000, 256, 'SHA-256');
const datosDesencriptadosComoBuffer = await window.crypto.subtle.decrypt(
{ name: "AES-CBC", iv: vectorInicializacion },
clave,
datosEncriptados.slice(LONGITUD_SAL + LONGITUD_VECTOR_INICIALIZACION)
);
return decoder.decode(datosDesencriptadosComoBuffer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment