33 lines
1.1 KiB
JavaScript
33 lines
1.1 KiB
JavaScript
|
|
exports.encrypt = (keyId, srcFile, destFile) => {
|
|
$$.shell().commands('sh', '-c', 'gpg -r ' + keyId + ' -e -o "' + destFile + '" ' + srcFile).start();
|
|
};
|
|
|
|
exports.encryptArmor = (keyId, srcFile, destFile) => {
|
|
$$.shell().commands('sh', '-c', 'gpg -r ' + keyId + ' -e -a --no-comment --comment "https://hatter.in/key" -o "' + destFile + '" ' + srcFile).start();
|
|
};
|
|
|
|
exports.decryptArmor = (gpgArmor) => {
|
|
var gpgArmorB64 = __.bytes.from(gpgArmor).asBase64();
|
|
var result = $$.shell().commands('sh', '-c', "echo '" + gpgArmorB64 + "' | base64 -D | gpg").start();
|
|
return __decrypt(result);
|
|
};
|
|
|
|
exports.decrypt = (gpgFile) => {
|
|
var result = $$.shell().commands('sh', '-c', 'cat ' + gpgFile + ' | gpg').start();
|
|
__decrypt(result);
|
|
};
|
|
|
|
var __decrypt = (result) => {
|
|
var out = result[0].string();
|
|
var err = result[1].string();
|
|
if (err.contains('public key decryption failed')) {
|
|
println('+ Decrypt file FAILED: ' + gpgFile);
|
|
if (!Packages.me.hatter.tools.jssp.main.StandaloneMain.JSSP_MAIN_MUTE) {
|
|
println("ERROR detail:\n" + err);
|
|
}
|
|
throw 'decrypt file failed: ' + gpgFile;
|
|
}
|
|
return out;
|
|
}
|