Skip to content

Instantly share code, notes, and snippets.

@abrarShariar
Last active August 24, 2018 05:02
Show Gist options
  • Save abrarShariar/eb31f0f73fe76676fdb55a919d9be0b4 to your computer and use it in GitHub Desktop.
Save abrarShariar/eb31f0f73fe76676fdb55a919d9be0b4 to your computer and use it in GitHub Desktop.
How to use nacl.secretbox.open(box, nonce, key)? #145
const decryptFile = (filePath, sKey) => {
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) throw err;
let hash = computeSHA256(sKey);
let buffer = Buffer.from(hash.toString(CryptoJS.enc.Hex), 'hex');
let key = new Uint8Array(buffer);
buffer = Buffer.from(data.toString(CryptoJS.enc.Hex), 'hex');
let encryptedData = new Uint8Array(buffer);
let decryptedData;
try {
decryptedData = nacl.secretbox.open(encryptedData, Rnonc, key);
} catch (e) {
console.log("Error in decryptFile: ", e);
}
console.log("DecryptedData: ", decryptedData);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment