Skip to content

Instantly share code, notes, and snippets.

@guidovranken
Created October 24, 2019 17:17
Show Gist options
  • Select an option

  • Save guidovranken/df72c49e53ed4da21da1fe93a776bdb6 to your computer and use it in GitHub Desktop.

Select an option

Save guidovranken/df72c49e53ed4da21da1fe93a776bdb6 to your computer and use it in GitHub Desktop.
<html>
<body>
<script>
function getKeyMaterial() {
let enc = new TextEncoder();
return window.crypto.subtle.importKey(
"raw",
enc.encode("PW"),
"HKDF",
false,
["deriveBits", "deriveKey"]
)
}
async function encrypt(plaintext, salt, iv) {
let keyMaterial = await getKeyMaterial();
return window.crypto.subtle.deriveBits(
{
"name": "HKDF",
salt: salt,
info: new Uint8Array(),
hash: "SHA-1",
},
keyMaterial,
4608
)
}
let plaintext = new Uint8Array(16);
let salt = new Uint8Array(16);
let iv = new Uint8Array(16);
encrypt(plaintext, salt, iv).then(console.log);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment