title: Sign / Verify with nodejs crypto always false
body: <p>I need to sign and verify messages in <code>node.js</code>. I followed the <code>crypto</code> package <a href="https://nodejs.org/api/crypto.html#crypto_class_verify" rel="nofollow noreferrer">document</a> but I always get a <code>false</code> on the verify method, which indicates that the signature is incorrect. </p>
  
  <p>The <code>RSA</code> <code>public key</code> and <code>private key</code> I'm using are working well for encrypt / decrypt messages with the same <code>crypto</code> package. </p>
  
  <p>Here's the code: </p>
  
  <pre><code>var crypto = require("crypto");
  var eol = require('os').EOL;
  </code></pre>
  
  <p>The sign and verify methods:</p>
  
  <pre><code>function RSASign(privateKey, data) {
      const sign = crypto.createSign('RSA-SHA256');
      sign.update(data);
      var sig = sign.sign(privateKey, 'hex')
      console.log(sig);
      return sig;
  }
  
  function RSAVerify(publicKey, signature, data) {
      const verify = crypto.createVerify('RSA-SHA256');
      verify.update(data);
      console.log(verify.verify(publicKey, signature));
  }
  </code></pre>
  
  <p>I'm calling the methods using </p>
  
  <pre><code>var dataToSign = "some data";
  var sig = RSASign(privateKey, dataToSign);
  RSAVerify(publicKey, sig, dataToSign);
  </code></pre>
  
  <p>The public key: </p>
  
  <pre><code>var pubStr = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCbbBSVpWzSmCGVeezhuVFgUEYowUxgX/SnFdymGRCHGc77d5I0xkMAnIOWbI2MmP8j/7sdfPuUF0V5zw+Hd/7iZ6vs2k4JRKdprrB/zSC4GGqCDpDkbRYydcw3kwDgKkHhDp6NwIKvvl87WsnFozi487tGPQ8NO15hngwsV7DrawIDAQAB';
  var publickKey = '-----BEGIN PUBLIC KEY-----' + eol + pubStr + eol + '-----END PUBLIC KEY-----';
  </code></pre>
  
  <p>The private key:</p>
  
  <pre><code>var p = 'MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAJtsFJWlbNKYIZV57OG5UWBQRijBTGBf9KcV3KYZEIcZzvt3kjTGQwCcg5ZsjYyY/yP/ux18+5QXRXnPD4d3/uJnq+zaTglEp2musH/NILgYaoIOkORtFjJ1zDeTAOAqQeEOno3Agq++XztaycWjOLjzu0Y9Dw07XmGeDCxXsOtrAgMBAAECgYAV13iFFzxV1B9UHFBX4G05Nc7GR3PuT03YdVAO35LdCZl26XTYicw8t8IeT58M1St16ahoGnpYc3TGC31JMmnVOr58At0jbd4JQgvUaE+2jVvgp0Lc6n/jN+7NYBGlEy44ZpIRbB1Biu7khCZ0D+8PZsDMi6WJK4jgI5Gf/aXvkQJBAOe6809U/1wEVDJFHZ6A++WI/8iebXSbw9hDa4a9qoXv8bsMjYkDiblD3UPRlTEdFsAOA/YuGdah+fKE7jKdKkcCQQCrszD8Z1MYWYE4dMQTRPxEKHGQZd5HHkTQu9l6FV7Bv2ga9wLhT4QTb/5U7WYGgbfxhFzklxoqsmhTJNuLlyO9AkBrA1nDZBQ9MT6UrHheL2Ckgpzkz8zqUdiicZghdEtgaQtv/v8JrBmY9e8jl5DXSoCsFozbzjReexTLW3oI462XAkEAnTQ/kZl4tz6b1XjzXUE4R59P+wmJ7kuEbijQAbs3OuVpB+dJN8l5/+H2VwPU+fgi1np+Ir1GM/mNEzMX4ELNcQJBAIk1s3Y7ep2gK0p4js4f9HU0u2vH25+6bu+y6JFfvIBd8OR1bCFEe3FIui1H/ohh0Eoo3ZgJZ/5JjwfsqJzOoBs=';
  var privateKey = '-----BEGIN PRIVATE KEY-----' + eol + p + eol + '-----END PRIVATE KEY-----'
  </code></pre>
  
  <p>What am I missing? </p>