The node.js app (typescript) needs to send a signature to the web service, the process requires
- based on the algorithm SHA256WithRSA
- use client’s secret key to sign the client’s data and output the signature
- encode the signature into based64
I tried the code
<code> import { createHmac } from 'crypto';
const signature = createHmac('sha256', config.secret).update(data).digest('hex');
const signature1 = Buffer.from(signature, 'hex').toString('base64')
</code>
<code> import { createHmac } from 'crypto';
const signature = createHmac('sha256', config.secret).update(data).digest('hex');
const signature1 = Buffer.from(signature, 'hex').toString('base64')
</code>
import { createHmac } from 'crypto';
const signature = createHmac('sha256', config.secret).update(data).digest('hex');
const signature1 = Buffer.from(signature, 'hex').toString('base64')
but it seems HMAC is not SHA256WithRSA, so I tried the code
import { createSign } from ‘crypto’;
const sign = createSign(‘RSA-SHA256’);
sign.update(data);
const signature = sign.sign(config.secret, ‘base64’);
however the program throws out an error
<code>Error: error:1E08010C:DECODER routines::unsupported on 'signature = sign.sign(config.secret, 'base64')'
</code>
<code>Error: error:1E08010C:DECODER routines::unsupported on 'signature = sign.sign(config.secret, 'base64')'
</code>
Error: error:1E08010C:DECODER routines::unsupported on 'signature = sign.sign(config.secret, 'base64')'
how would I implement this task?