How to use NodeJS crypto to sign a file?

前端 未结 1 696
深忆病人
深忆病人 2020-12-16 17:29

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 d

相关标签:
1条回答
  • 2020-12-16 17:32

    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');
    
    0 讨论(0)
提交回复
热议问题