elliptic icon indicating copy to clipboard operation
elliptic copied to clipboard

Convert signature to base64

Open wellingtonsampaio opened this issue 2 years ago • 1 comments

Hi,

I am signing a text with the following code:

` const privateKey: string = 'private-key-here';

const textToBeSigned: string = 'text-here';

const EC = require('elliptic').ec;

const ec = new EC('secp256k1');

const shaMsg = crypto.createHash('sha256').update(textToBeSigned).digets();

const signature = ec.sign(shaMsg, privateKey, { canonical: true }); `

How can I convert the signature to base64?

I only see a function to convert it to DER = signature.toDER().

wellingtonsampaio avatar Dec 01 '22 02:12 wellingtonsampaio

Hello @wellingtonsampaio , this can be done like this:

    const derSignature = signature.toDER('hex');
    const base64Signature = Buffer.from(derSignature, 'hex').toString('base64');

cokron avatar Apr 13 '23 18:04 cokron