我的节点版本:v10.15.3
我尝试使用var controls = require('./controls.js');
describe('Automation', function() {
beforeEach(async() =>{ //This block will be executed before every `it` block
await browser.waitForAngualrEnabled(true);
await browser.get('https://prre2eauto.exterrocloud.info');
});
it('Form 1', async function(){
var a = require('./formOperations.js');
await a.form1();
});
it('Form 2', async function(){
var b = require('./formOperations.js');
await b.form2();
});
});
之类的api
我收到一个错误:crypto.privateDecrypt(privateKey, Buffer.from(encryptData, 'utf8'))
我知道我们可以像Error: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt
这样传递密码,但是我想检测一下这个私钥是否有密码。
有什么主意吗?
答案 0 :(得分:0)
使用本地crypto
模块似乎无法实现这样的功能。但是截至question为止,这是安全性交换。您可以检查是否已读取文件,这可以通过文件系统(fs)模块来实现。
const fs = require('fs');
const get_line = (filename, line_no, callback) => {
const stream = fs.createReadStream(filename, {
flags: 'r',
encoding: 'utf-8',
fd: null,
mode: 0666,
bufferSize: 64 * 1024
});
let fileData = '';
stream.on('data', (data) => {
fileData += data;
// The next lines should be improved
let lines = fileData.split("\n");
if(lines.length >= +line_no){
stream.destroy();
callback(null, lines[+line_no]);
}
});
stream.on('error', () => {
callback('Error', null);
});
stream.on('end', () => {
callback('File end reached without finding line', null);
});
}
const hasPassphrase = (keyFile, callback) => {
get_line(keyFile, 1, (err, line) => {
if (line.indexOf("Proc-Type:") === -1) {
callback(false);
} else {
callback(true);
}
})
}
hasPassphrase('./ssh-Key', hasPasspharse => {
// your logic here
});
您的想法正确,提取文件的第二行,然后检查是否有Proc-Type:
标头。修改适合您的代码。