title: How to convert phpseclib's CRYPT_RSA_SIGNATURE_PKCS1 to node
body: <p>How to convert PHP's <code>$rsa-&gt;verify</code> function to node? I used the crypto's verify function like this:</p>
  
  <pre><code>const crypto = require('crypto');
  const verify = crypto.createVerify('RSA-SHA256');
  
  verify.update('some data to sign');
  
  const public_key = getPublicKeySomehow();
  const signature = getSignatureToVerify();
  console.log(verify.verify(public_key, signature));
  </code></pre>
  
  <p>But it always return false. When I run my data and the signature through php it returns true! Any idea what I might be doing wrong?</p>
  
  <p>The php verify function looks like this :</p>
  
  <pre><code>function verify($message, $signature)
  {
      if (empty($this-&gt;modulus) || empty($this-&gt;exponent)) {
          return false;
      }
  
      switch ($this-&gt;signatureMode) {
          case CRYPT_RSA_SIGNATURE_PKCS1:
              return $this-&gt;_rsassa_pkcs1_v1_5_verify($message, $signature);
          //case CRYPT_RSA_SIGNATURE_PSS:
          default:
              return $this-&gt;_rsassa_pss_verify($message, $signature);
      }
  }
  </code></pre>
  
  <p>It seems to be using CRYPT_RSA_SIGNATURE_PKCS1. How to use it in node?</p>
  
  <pre><code>function _rsassa_pss_verify($m, $s)
      {
          // Length checking
  
          if (strlen($s) != $this-&gt;k) {
              user_error('Invalid signature');
              return false;
          }
  
          // RSA verification
  
          $modBits = 8 * $this-&gt;k;
  
          $s2 = $this-&gt;_os2ip($s);
          $m2 = $this-&gt;_rsavp1($s2);
          if ($m2 === false) {
              user_error('Invalid signature');
              return false;
          }
          $em = $this-&gt;_i2osp($m2, $modBits &gt;&gt; 3);
          if ($em === false) {
              user_error('Invalid signature');
              return false;
          }
  
          // EMSA-PSS verification
  
          return $this-&gt;_emsa_pss_verify($m, $em, $modBits - 1);
      }
  </code></pre>