-
-
Save parzibyte/89f64be230b975b9552269f0dd7cf42a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const encriptar = async (contraseña, textoPlano) => { | |
const encoder = new TextEncoder(); | |
const sal = window.crypto.getRandomValues(new Uint8Array(16)); | |
const vectorInicializacion = window.crypto.getRandomValues(new Uint8Array(16)); | |
const bufferTextoPlano = encoder.encode(textoPlano); | |
const clave = await derivacionDeClaveBasadaEnContraseña(contraseña, sal, 100000, 256, 'SHA-256'); | |
const encrypted = await window.crypto.subtle.encrypt( | |
{ name: "AES-CBC", iv: vectorInicializacion }, | |
clave, | |
bufferTextoPlano | |
); | |
return bufferABase64([ | |
...sal, | |
...vectorInicializacion, | |
...new Uint8Array(encrypted) | |
]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment