-
-
Save cardoso/0232aefe0bcc2314a1a7c716fec987b0 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
export default async (messageJSON, derivedKey) => { | |
try { | |
const message = JSON.parse(messageJSON); | |
const text = message.base64Data; | |
const initializationVector = new Uint8Array(message.initializationVector).buffer; | |
const string = atob(text); | |
const uintArray = new Uint8Array( | |
[...string].map((char) => char.charCodeAt(0)) | |
); | |
const algorithm = { | |
name: "AES-GCM", | |
iv: initializationVector, | |
}; | |
const decryptedData = await window.crypto.subtle.decrypt( | |
algorithm, | |
derivedKey, | |
uintArray | |
); | |
return new TextDecoder().decode(decryptedData); | |
} catch (e) { | |
return `error decrypting message: ${e}`; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment