Created
October 24, 2019 17:17
-
-
Save guidovranken/df72c49e53ed4da21da1fe93a776bdb6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <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