如何使用NodeJS加密签名文件? [英] How to use NodeJS crypto to sign a file?

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

问题描述

我无法使用nodeJS签署文件。为此,我有一个p12证书(它包括私钥),密码短语和pem证书。

I wan't to use nodeJS to sign a file. For that I've one p12 certificate (it 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

提前感谢!

推荐答案

您应该能够使用 createSign crypto 模块中(见 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加密签名文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆