Skip to content

Pem private key sha256 digest signature #653

@edamazzio

Description

@edamazzio

Hi.

I'm trying to sign a string with SHA256 using a Private Key in PEM format, but I keep getting a different output than expected.

My goal is to produce the same output as

cat fileWithStringToSign.txt | openssl dgst -sha256 -sign $PEMFILE | openssl enc -base64 -A

My code is as follows:

var stringToSign = "blah blah";
var pem = '-----BEGIN PRIVATE KEY----- MIIEvQIB...';
var privateKey = forge.pki.privateKeyFromPem(pem);
var md = forge.md.sha256.create();
md.update(string); //I also tried md.update(string, 'utf8')
var signature = privateKey.sign(md);
return forge.util.encode64(signature);

Any help would be highly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions