title: node.js implementation of jCryption 3.0 server-side part
body: <p>Did anyone implement server-side part of <a href="http://jcryption.org/" rel="nofollow">jCryption 3.0 plugin</a> with node.js? Author uses PHP for server, <a href="https://github.com/HazAT/jCryption/blob/master/php/jcryption.php" rel="nofollow">here's code on GitHub</a>. I'm struggling with handshake handler, somehow I cannot decrypt request's base64 key with my private PEM key (I use 'ursa' module for RSA). Here's my handler (it's not completely finished in challenge part): </p>
  
  <pre><code>var ursa = require('ursa');
  ...
  // write public key to HTML with EJS 
  exports.getPublicKeyMiddleware = function(req, res, next){
      res.publicKey = req.app.get('publicKey'); // stores result of readFile(PUBLIC_KEY.PEM)
      next();
  };
  
  exports.handshake = function(req, res, next) {
      var base64key = req.body.key;
      var privateKey;
      var challenge;
  
      if (!!base64key) {
          myPrivateKey = ursa.createPrivateKey(req.app.get('privateKey'));
  
          try {
              challenge = privateKey.decrypt(base64key, 'base64', 'utf8');
              res.json({challenge: challenge});
  
          }
          catch (e) {
              res.json({error: 'Error decoding key'});
              console.log(e.message);
          }
  
       }
       else {
          res.json({error: 'No key in request'})
       }
  }
  </code></pre>
  
  <p>Now it's always an error when decrypt. Like this:</p>
  
  <pre><code>Error: error:0407A079:rsa routines:RSA_padding_check_PKCS1_OAEP:oaep decoding error
  </code></pre>
  
  <p>Can you please look at PHP workflow (link above) and point me what I am doing wrong maybe? Thanks</p>
  
  <p><strong>EDIT:</strong>
  Like HazA said padding was the case:</p>
  
  <pre><code>myPrivateKey.decrypt(base64key, 'base64', 'utf8', ursa.RSA_PKCS1_PADDING);
  </code></pre>