예제 #1
0
        private void Decrypt(string privateKey, string outputFile)
        {
            string encryptedResourceKey = FindEncryptedResource();

            if (encryptedResourceKey == null)
            {
                Logger.Error(string.Format("Could not find encrypted resourse. Assembly contains following resources: {0}", string.Join(",", ExecutingAssembly.GetManifestResourceNames())));
                throw new ApplicationException("Missing embedded package");
            }

            Logger.Debug(string.Format("Encrypted data is stored as resource with the key {0}", encryptedResourceKey));
            using (Stream inputStream = ExecutingAssembly.GetManifestResourceStream(encryptedResourceKey))
                using (Stream privateKeyStream = privateKey.OpenStream())
                {
                    PgpDecryptor.Decrypt(inputStream, privateKeyStream, passPhrase, outputFile);
                }
        }
예제 #2
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);
            }
        }