Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert signature to base64 #294

Open
wellingtonsampaio opened this issue Dec 1, 2022 · 1 comment
Open

Convert signature to base64 #294

wellingtonsampaio opened this issue Dec 1, 2022 · 1 comment

Comments

@wellingtonsampaio
Copy link

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().

@cokron
Copy link

cokron commented Apr 13, 2023

Hello @wellingtonsampaio ,
this can be done like this:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants