public override bool Execute(string[] parameters) { logger.LogInformation($"Executing {nameof(EncryptFiles)} task."); bool result = false; try { SetProperties(parameters); logger.LogInformation($"Files from '{inputDirectory}' are being encrypted to '{outputDirectory}' with key '{publicKey}'."); string[] files = System.IO.Directory.GetFiles(inputDirectory); foreach (var file in files) { using (Standard.PGP.Encrypt pgp = new Standard.PGP.Encrypt()) { string outputFile = $"{outputDirectory}\\{System.IO.Path.GetFileName(file)}.pgp"; pgp.FileType = Standard.Enums.PGPFileType.UTF8; pgp.EncryptFileWithPathKey( inputFilePath: file, outputFilePath: outputFile, publicKeyFilePath: publicKey, armor: true, withIntegrityCheck: false); logger.LogInformation($"Completed file encryption '{outputFile}'."); } } logger.LogInformation("Completed directory encryption."); result = true; } catch (Exception ex) { logger.LogError(ex, $"Could not complete {nameof(EncryptFiles)} task."); } logger.LogInformation($"{nameof(EncryptFiles)} task complete."); return(result); }
public override bool Execute(string[] parameters) { logger.LogInformation($"Executing {nameof(EncryptFile)} task."); bool result = false; try { SetProperties(parameters); using (Standard.PGP.Encrypt pgp = new Standard.PGP.Encrypt()) { logger.LogInformation($"'{inputFile}' is being encrypted to '{outputFile}' with key '{publicKey}'."); pgp.FileType = Standard.Enums.PGPFileType.UTF8; pgp.EncryptFileWithPathKey( inputFilePath: inputFile, outputFilePath: outputFile, publicKeyFilePath: publicKey, armor: true, withIntegrityCheck: false); logger.LogInformation($"Completed file encryption '{outputFile}'."); } result = true; } catch (Exception ex) { logger.LogError(ex, $"Could not complete {nameof(EncryptFile)} task."); } logger.LogInformation($"{nameof(EncryptFile)} task complete."); return(result); }