本文介绍了如何使用 NodeJS 加密来签署文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 nodeJS 对文件进行签名.我得到了一个 p12 证书(包括私钥)、一个密码和一个 pem 证书.

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.

这里显示了它是如何在 ruby​​ 中完成的:https://gist.github.com/de4b602a213b4b264706

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

提前致谢!

推荐答案

您应该能够在 crypto 模块中使用 createSign(参见 http://nodejs.org/docs/v0.4.2/api/all.html#crypto) 做你想要什么.代码最终看起来像这样(来自 http://chimera.labs.oreilly.com/books/1234000001808/ch05.html#chap7_id35952189):

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');

这篇关于如何使用 NodeJS 加密来签署文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 02:01