title: Difference between signing with SHA256 vs. signing with RSA-SHA256
body: <p>I play with <strong>digital signatures</strong> using node.js. For test purpose, I created a digital signature of some XML data, first using only SHA256, then using RSA-SHA256.</p>
  
  <p>The thing that puzzles me is that <strong>both methods of signing create exactly the same signature</strong>. Both signatures are identical. If they're identical, then why two different methods (SHA256 vs. RSA-SHA256)?</p>
  
  <p>I include code below:</p>
  
  <pre><code>var crypto = require('crypto'),
      path   = require('path'),
      fs     = require('fs'),
  
      pkey_path = path.normalize('private_key.pem'),
      pkey = '';
  
  function testSignature(pkey) {
      var sign1 = crypto.createSign('RSA-SHA256'),
          sign2 = crypto.createSign('SHA256');
  
      fs.ReadStream('some_document.xml')
          .on('data', function (d) {
              sign1.update(d);
              sign2.update(d);
          })
          .on('end', function () {
              var s1 = sign1.sign(pkey, "base64"),
                  s2 = sign2.sign(pkey, "base64");
  
              console.log(s1);
              console.log(s2);
          });
  }
  
  // You need to read private key into a string and pass it to crypto module.
  // If the key is password protected, program execution will stop and
  // a prompt will appear in console, awaiting input of password.
  
  testSignature(fs.readFileSync(pkey_path));
  </code></pre>
  
  <p>The code above outputs some string, which is the signature, and then again exactly the same string, which is also a signature of the same data, but created with - supposedly - different algorithm, yet it's identical with previous one...</p>