title: Create RSA-SHA256 sign with PEM key
body: <p>I've been creating a gateway for a legacy service, this legacy service needs a signature as a body parameter of a PUT request, in order to create this sign I need to follow the following steps: </p>
  
  <ol>
  <li>Create a <em>hash</em> with certain text as data, this <em>hash</em> needs to be <em>SHA256</em>.</li>
  <li>Encrypt the result of the <em>hash</em> using <em>RSA</em> with a PEM key</li>
  <li>Encode the result of the <em>RSA</em> to Base64</li>
  </ol>
  
  <p>Following the previous steps I create the following code</p>
  
  <pre><code>export class Signature {
    // class body
    public static sign(text: string){
      const key = readFileSync('key.pem')
      const passphrase = '12345678'
      const createdSign = createSign('RSA-SHA256')
      createdSign.write(text)
      createdSign.end()
      return createdSign.sign({ key, passphrase }).toString('base64')
    } 
  }
  </code></pre>
  
  <p>But I'm not sure if this the correct implementation, taking into consideration the previous steps, and the existence of the <em>hash</em> API in NodeJS.</p>
  
  <p>If someone could tell me if I'm correctly implementing this algorithm.</p>