title: Saving object to JSON file than using it back in function after reading
body: <p>I am completly new to node.js but have to use it in my student project that require this library: <a href="https://github.com/bitchan/eccrypto" rel="nofollow noreferrer">https://github.com/bitchan/eccrypto</a>.
  The goal is to encrypt file using ethereum public key, save it as JSON and than read it back to decrypt with private key:</p>
  <pre><code>var fs = require('fs');
  var crypto = require(&quot;crypto&quot;);
  var eccrypto = require(&quot;eccrypto&quot;);
  
  var content = fs.readFileSync('pdf_test.pdf');
  
  var importPrivateKey = &quot;c337ded6f56c07205fb7b391654d7d463c9e0c726869523ae6024c9bec878878&quot;
  var importPublicKey = &quot;04730a151f545f5dcdb1c6d99fb1251f5c70f216f39ba2681bcf10db16bd582e6720bc881d51f25ffbe961df6a0af24a9d39a4db3d86a7f6b3f9bf4eaac0e4006b&quot;
  
  var privateKey = new Buffer(importPrivateKey, &quot;hex&quot;);
  var publicKey = new Buffer(importPublicKey, &quot;hex&quot;);
  
  // Encrypting the file for B.
  eccrypto.encrypt(publicKey, Buffer(content)).then(function(encrypted) {
      //console.log('Encrypted message ' + JSON.stringify(encrypted));
  
  let data = JSON.stringify(encrypted);
  fs.writeFileSync('encrypted.json', data);
  console.log('encryption done');
  
  let rawData = fs.readFileSync('encrypted.json')
  let encryptedContent = JSON.parse(rawData);
  //console.log(encryptedContent);
  
   // B decrypting the file.
  eccrypto.decrypt(privateKey, encryptedContent).then(function(plaintext) {
      //console.log(&quot;Decrypted message: &quot;, plaintext.toString());
  
      fs.writeFile('decrypted.pdf', plaintext, function (err) {
        if (err) return console.log(err);
        console.log('decryption done');
  });
   });
  });
  </code></pre>
  <p>I get following error from this code: &quot;(node:271) UnhandledPromiseRejectionWarning: Error: Bad input.&quot;
  Everything is working when i replace &quot;encryptedContent&quot; variable with &quot;encrypted&quot; on eccrypto.decrypt function but i want to let user store encrypted object and decrypt it later with this function. How can i do that?</p>