在云中使用node.js对加密文件进行GPG解密
如何使用node.js在云中解密GPG加密文件而不在云中保存私钥 从onPrem移动到Azure云。目前,如果服务器上安装了onPrem GPG vault,则会在GPG vault中导入公钥/私钥,解密代码使用指纹对文件进行解密,但这意味着私钥实际存在于服务器上。随着移动到云,安全团队不希望在云吊舱上维护私钥。 私钥文件的后续内容将通过API调用提供。 尝试通过将私钥API的响应对象作为“收件人”和“密钥”作为参数传递给cryptoReader.js来解密加密文件,cryptoReader.js使用crpto、gpg模块执行解密。不走运。 如果我在将私钥导入GPG vault的机器上尝试相同的代码,它就会工作 这是否意味着必须将私钥物理导入将执行解密的服务器上的GPG vault? 其他对安全敏感的公司如何在云中实现这一点在云中使用node.js对加密文件进行GPG解密,node.js,gnupg,Node.js,Gnupg,如何使用node.js在云中解密GPG加密文件而不在云中保存私钥 从onPrem移动到Azure云。目前,如果服务器上安装了onPrem GPG vault,则会在GPG vault中导入公钥/私钥,解密代码使用指纹对文件进行解密,但这意味着私钥实际存在于服务器上。随着移动到云,安全团队不希望在云吊舱上维护私钥。 私钥文件的后续内容将通过API调用提供。 尝试通过将私钥API的响应对象作为“收件人”和“密钥”作为参数传递给cryptoReader.js来解密加密文件,cryptoReader.j
//KeyBuffer contains contents of private key .asc file as response from API call
Decryption call:
stream.decryptFilewithPGP(<encryptedFileName>, { skipEmptyLines: true, encoding: 'utf8' },
{
mode: 'PGP',
// key: keyBuffer,
recipient: keyBuffer,
passphrase: config.asymmetric.passphrase
// fingerprint: config.asymmetric.fingerprint //for onPrem, for cloud no fingerprint
});
Actual decryption implementation:
CryptoReader.prototype.decryptFilewithPGP = function (filepath, options, cipher) {
var self = this;
this._filepath = path.normalize(filepath);
this._encoding = options && options.encoding || 'utf8';
this._skipEmptyLines = options && options.skipEmptyLines || false;
this._streamOptions = { encoding: this._encoding };
if (options && options.start) {
this._streamOptions.start = options.start;
}
if (options && options.end) {
this._streamOptions.end = options.end;
}
let args = [
'--passphrase', self.decode(cipher.passphrase),
//'--recipient', cipher.key,
'--recipient', cipher.recipient,
'--trust-model', 'always',
'--decrypt'
];
console.log(`args: ${JSON.stringify(args)}`);
readStream = this._readStream ? this._readStream : fs.createReadStream(this._filepath);
outStream = this._outStream ? this._outStream : new Stream.PassThrough;
//var outStream = new Stream.PassThrough;
gpg.callStreaming(readStream, outStream, args, function (err) {
if (err) {
self.emit('error', err);
}
else {
var _decData='', lastLine;
outStream.on('data', function (data) {
self._readStream.pause();
self._outStream.pause();
let _data = self._lineFragment.concat(data.toString('utf8'));
self._lines = self._lines.concat(_data.split(/(?:\n|\r\n|\r)/g));
self._lineFragment = self._lines.pop() || ''; //hold last line
//console.log('data chunk size: ' + data.length + ' no. or rows: ' + self._lines.length);
setImmediate(function () {
self._nextLine();
});
});
outStream.on('end', function () {
self._end = true;
setImmediate(function () {
self._nextLine();
});
});
outStream.on('error', function (error) {
self.emit('error', err);
});
}
});
this._readStream = readStream;
this._outStream = outStream;
};
//KeyBuffer包含private key.asc文件的内容,作为API调用的响应
解密调用:
decryptFilewithPGP(,{skipmptylines:true,编码:'utf8'},
{
模式:“PGP”,
//键:键缓冲区,
收件人:keyBuffer,
密码短语:config.asymetric.passphrase
//指纹:config.asymetric.fingerprint//用于onPrem,用于云无指纹
});
实际解密实现:
CryptoReader.prototype.decryptFilewithPGP=函数(文件路径、选项、密码){
var self=这个;
这是._filepath=path.normalize(filepath);
这是._encoding=options&&options.encoding | | | utf8';
这是。_skipeptylines=options&&options.skipeptylines | | false;
this.\u streamOptions={encoding:this.\u encoding};
如果(选项和选项开始){
这。_streamOptions.start=options.start;
}
如果(选项和选项结束){
这。_streamOptions.end=options.end;
}
设args=[
'--passphrase',self.decode(cipher.passphrase),
//“--收件人”,cipher.key,
“--recipient”,cipher.recipient,
“--信任模型”,“始终”,
“--解密”
];
log(`args:${JSON.stringify(args)}`);
readStream=this.\u readStream?this.\u readStream:fs.createReadStream(this.\u filepath);
流出=这个。_流出?这个。_流出:新的Stream.PassThrough;
//var outStream=新的Stream.PassThrough;
调用流(readStream、outStream、args、function(err){
如果(错误){
self.emit('error',err);
}
否则{
var_decData='',最后一行;
扩展流打开('data',函数(data){
self._readStream.pause();
self._流出。暂停();
设_data=self._lineFragment.concat(data.toString('utf8'));
self._lines=self._lines.concat(_data.split(/(?:\n | \r\n | \r)/g));
self._lineFragment=self._lines.pop()| |“”;//保留最后一行
//console.log('数据块大小:'+data.length+'行数:'+self.\u line.length);
setImmediate(函数(){
self._nextLine();
});
});
exptream.on('end',函数(){
self.\u end=true;
setImmediate(函数(){
self._nextLine();
});
});
exptream.on('error',函数(error){
self.emit('error',err);
});
}
});
这是。_readStream=readStream;
这个。_流出=流出;
};
预期:应解密加密文件并返回明文(在导入私钥的onPrem服务器或开发人员计算机中发生的情况)
实际:未执行解密