Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created February 12, 2022 20:19
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/0c01a6361330a6f9efc79c731b87cf24 to your computer and use it in GitHub Desktop.
Save parzibyte/0c01a6361330a6f9efc79c731b87cf24 to your computer and use it in GitHub Desktop.
const derivacionDeClaveBasadaEnContraseña = async (contraseña, sal, iteraciones, longitud, hash, algoritmo = 'AES-CBC') => {
const encoder = new TextEncoder();
let keyMaterial = await window.crypto.subtle.importKey(
'raw',
encoder.encode(contraseña),
{ name: 'PBKDF2' },
false,
['deriveKey']
);
return await window.crypto.subtle.deriveKey(
{
name: 'PBKDF2',
salt: encoder.encode(sal),
iterations: iteraciones,
hash
},
keyMaterial,
{ name: algoritmo, length: longitud },
false,
['encrypt', 'decrypt']
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment