12

I want to use nodeJS to sign a file. I got one p12 certificate (which includes the private key), a passphrase and a pem certificate.

This here shows how it is been done in ruby: https://gist.github.com/de4b602a213b4b264706

Thanks in advance!

Menelaos Kotsollaris
  • 5,776
  • 9
  • 54
  • 68
Torsten
  • 253
  • 1
  • 3
  • 9

1 Answers1

28

You should be able to use createSign in the crypto module (see http://nodejs.org/docs/v0.4.2/api/all.html#crypto) to do what you want. The code will end up looking something like this (from http://chimera.labs.oreilly.com/books/1234000001808/ch05.html#chap7_id35952189):

var crypto = require('crypto');
var fs = require('fs');

var pem = fs.readFileSync('key.pem');
var key = pem.toString('ascii');

var sign = crypto.createSign('RSA-SHA256');
sign.update('abcdef');  // data from your file would go here
var sig = sign.sign(key, 'hex');
hackal
  • 15
  • 3
  • 8
Bill
  • 25,119
  • 8
  • 94
  • 125