public string TransformToNewFile(string sourceFilePath)
        {
            string outputPath = $"{sourceFilePath}.{EncryptedExtensions}";

            PgpEncryptor.EncryptFile(sourceFilePath, outputPath, _publicKey);
            return(outputPath);
        }
        public void TestBytesAndStreams()
        {
            var fi          = new FileInfo(@"testfiles\dataFeb-8-2016_40M-pipe.csv");
            var fiOut       = new FileInfo(fi.FullName + ".gpg");
            var fiDecrypted = new FileInfo(@"testfiles\dataFeb-8-2016_40M-pipe-decrypted.csv");

            var fiPublicKey          = new FileInfo(@"testfiles\dummy2.asc");
            var fiPrivateKey         = new FileInfo(@"testfiles\dummyprivate2.asc");
            var privateKeyPassPhrase = "hello world!";

            // encrypt
            using (Stream publicKeyStream = File.OpenRead(fiPublicKey.FullName))
            {
                var bytes  = File.ReadAllBytes(fi.FullName);
                var output = PgpEncryptor.EncryptAes256(bytes, fi.Name, publicKeyStream, withIntegrityCheck: true, armor: false, compress: true);
                File.WriteAllBytes(fiOut.FullName, output.ToArray());
            }

            // decrypt
            using (Stream privateKeyStream = File.OpenRead(fiPrivateKey.FullName))
            {
                using (Stream encryptedDataStream = File.OpenRead(fiOut.FullName))
                {
                    var output = PgpEncryptor.DecryptPgpData(encryptedDataStream, privateKeyStream, privateKeyPassPhrase);

                    using (var fileStream = File.Create(fiDecrypted.FullName))
                    {
                        output.CopyTo(fileStream);
                    }
                }
            }
        }
Example #3
0
        public void Can_encrypt_file()
        {
            using (var files = new TempFileCollection())
            {
                string inputFilePath  = files.AddFile();
                string outputFilePath = files.AddFile();
                WriteAllText(inputFilePath, "Hello Encryption");

                PgpEncryptor.EncryptFile(inputFilePath, outputFilePath, TestKeys.PublicKey);

                outputFilePath.Should().BeExistingFilePath();
            }
        }
        public void TestBytesAndStreamsCmre()
        {
            var fi    = new FileInfo(@"testfiles\test-encryption-file.txt");
            var fiOut = new FileInfo(fi.FullName + ".gpg");

            var fiPublicKey = new FileInfo(@"\\vmware-host\Shared Folders\FileStore\JFM Concepts\Clients\RevSource\Data\CMRE Data\cmre.asc");

            // encrypt
            using (Stream publicKeyStream = File.OpenRead(fiPublicKey.FullName))
            {
                var bytes  = File.ReadAllBytes(fi.FullName);
                var output = PgpEncryptor.EncryptAes256(bytes, fi.Name, publicKeyStream, withIntegrityCheck: true, armor: false, compress: true);
                File.WriteAllBytes(fiOut.FullName, output.ToArray());
            }
        }
Example #5
0
        public void Can_decrypt_file()
        {
            using (var files = new TempFileCollection())
            {
                string inputFilePath     = files.AddFile();
                string encryptedFilePath = files.AddFile();
                string decryptedFilePath = files.AddFile();
                string content           = $"Hello Decryption {Guid.NewGuid()}";
                WriteAllText(inputFilePath, content);
                PgpEncryptor.EncryptFile(inputFilePath, encryptedFilePath, TestKeys.PublicKey);

                using (FileStream encryptedStream = OpenRead(encryptedFilePath))
                    using (FileStream privateKeyStream = OpenRead(TestKeys.PrivateKeyPath))
                    {
                        PgpDecryptor.Decrypt(encryptedStream, privateKeyStream, TestKeys.Password, decryptedFilePath);
                    }

                decryptedFilePath.Should().BePathToFileWithContent(content);
            }
        }
        public void TestFiles()
        {
            var fi          = new FileInfo(@"testfiles\dataFeb-8-2016_40M-pipe.csv");
            var fiOut       = new FileInfo(fi.FullName + ".gpg");
            var fiDecrypted = new FileInfo(@"testfiles\dataFeb-8-2016_40M-pipe-decrypted.csv");

            var fiPublicKey          = new FileInfo(@"testfiles\dummy2.asc");
            var fiPrivateKey         = new FileInfo(@"testfiles\dummyprivate2.asc");
            var privateKeyPassPhrase = "hello world!";

            // encrypt
            using (Stream publicKeyStream = File.OpenRead(fiPublicKey.FullName))
            {
                PgpEncryptor.EncryptAes256(fi.FullName, fiOut.FullName, publicKeyStream, withIntegrityCheck: true, armor: false, compress: true, overwrite: true);
            }

            using (Stream privateKeyStream = File.OpenRead(fiPrivateKey.FullName))
            {
                PgpEncryptor.DecryptPgpData(fiOut.FullName, fiDecrypted.FullName, privateKeyStream, privateKeyPassPhrase, true);
            }
        }