Skip to content

Instantly share code, notes, and snippets.

@ccapndave
Last active May 18, 2016 18:58
Show Gist options
  • Save ccapndave/4eaee7b27248343c991e64dad9912f62 to your computer and use it in GitHub Desktop.
Save ccapndave/4eaee7b27248343c991e64dad9912f62 to your computer and use it in GitHub Desktop.
fetch("http://localhost:3000/content/encrypted.json")
.then(res => res.text())
.then(x => cjs.AES.decrypt(x, "iamapassword")
.toString(cjs.enc.Utf8))
.then(decryptedTxt => console.log(decryptedTxt));
=��"I
�_��Ԃ�ȓ
��F�ZXcX�$�"
const stream = fs.createReadStream(fullPath);
stream.on('error', err => {
res.status(404).send("Content not found");
res.end();
});
// create encryption stream
const encrypt = crypto.createCipher("aes-256-ctr", "iamapassword");
stream.pipe(encrypt).pipe(res);
{
txt: "Can you decode me?"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment