Last active
August 24, 2018 05:02
-
-
Save abrarShariar/eb31f0f73fe76676fdb55a919d9be0b4 to your computer and use it in GitHub Desktop.
How to use nacl.secretbox.open(box, nonce, key)? #145
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
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