Example #1
0
        public override bool Execute(string[] parameters)
        {
            logger.LogInformation($"Executing {nameof(DecryptFile)} task.");

            bool result = false;

            try
            {
                SetProperties(parameters);

                using (Standard.PGP.Decrypt pgp = new Standard.PGP.Decrypt())
                {
                    logger.LogInformation($"'{inputFile}' is being decrypted to '{outputFile}' with key '{privateKey}'.");

                    pgp.FileType = Standard.Enums.PGPFileType.UTF8;

                    pgp.DecryptFileWithPath(
                        inputFilePath: inputFile,
                        outputFilePath: outputFile,
                        privateKeyFilePath: privateKey,
                        passPhrase: passPhrase);

                    logger.LogInformation($"Completed file decryption '{outputFile}'.");
                    result = true;
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex, $"Could not complete {nameof(DecryptFile)} task.");
            }

            logger.LogInformation($"{nameof(DecryptFile)} task complete.");

            return(result);
        }
Example #2
0
        public override bool Execute(string[] parameters)
        {
            logger.LogInformation($"Executing {nameof(DecryptFiles)} task.");

            bool result = false;

            try
            {
                SetProperties(parameters);
                logger.LogInformation($"Files from '{inputDirectory}' are being decrypted to '{outputDirectory}' with key '{privateKey}'.");

                string[] files = System.IO.Directory.GetFiles(inputDirectory);

                foreach (var file in files)
                {
                    using (Standard.PGP.Decrypt pgp = new Standard.PGP.Decrypt())
                    {
                        string outputFile = $"{outputDirectory}\\{System.IO.Path.GetFileNameWithoutExtension(file)}";
                        pgp.FileType = Standard.Enums.PGPFileType.UTF8;

                        pgp.DecryptFileWithPath(
                            inputFilePath: file,
                            outputFilePath: outputFile,
                            privateKeyFilePath: privateKey,
                            passPhrase: passPhrase);

                        logger.LogInformation($"Completed file decryption '{outputFile}'.");
                    }
                }

                logger.LogInformation("Completed directory decryption.");
                result = true;
            }
            catch (Exception ex)
            {
                logger.LogError(ex, $"Could not complete {nameof(DecryptFiles)} task.");
            }

            logger.LogInformation($"{nameof(DecryptFiles)} task complete.");

            return(result);
        }