コード例 #1
0
 public GeneratedKeysFixture()
 {
     PublicKeyPath  = files.AddFile();
     PrivateKeyPath = files.AddFile();
     PgpKeyGenerator.GenerateKey(TestKeys.Username, TestKeys.Password, PublicKeyPath, PrivateKeyPath);
     PublicKey = File.ReadAllText(PublicKeyPath);
 }
コード例 #2
0
        public void Can_generate_keys()
        {
            using (var files = new TempFileCollection())
            {
                string publicKeyPath  = files.AddFile();
                string privateKeyPath = files.AddFile();

                PgpKeyGenerator.GenerateKey(DefaultCredentials.Username, DefaultCredentials.Password, publicKeyPath, privateKeyPath);

                publicKeyPath.Should().BeValidPublicKeyFilePath();
                privateKeyPath.Should().BeValidPrivateKeyFilePath();
            }
        }
コード例 #3
0
        private async Task <bool> GenerateKeys()
        {
            string publicKeyPath  = KeyGenerationStep.PublicKeyPath,
                   privateKeyPath = KeyGenerationStep.PrivateKeyPath;

            if (File.Exists(privateKeyPath) || File.Exists(publicKeyPath))
            {
                MessageBoxResult overwriteResult = CustomMessageBox.Show(Resources.KeyGenerationStep_DoYouWantOverwrite,
                                                                         noText: Resources.KeyGenerationStep_NoSelectAnother);
                if (overwriteResult == MessageBoxResult.No)
                {
                    return(false);
                }
            }

            await Task.Factory.StartNew(() =>
            {
                PgpKeyGenerator.GenerateKey(DefaultCredentials.Username, DefaultCredentials.Password, publicKeyPath, privateKeyPath);
            });

            return(true);
        }
コード例 #4
0
        public void Can_generate_keys_encrypt_and_decrypt_file()
        {
            using (var files = new TempFileCollection())
            {
                string publicKeyPath     = files.AddFile();
                string privateKeyPath    = files.AddFile();
                string inputFilePath     = files.AddFile();
                string encryptedFilePath = files.AddFile();
                string decryptedFilePath = files.AddFile();
                string content           = $"Hello Decryption {Guid.NewGuid()}";
                WriteAllText(inputFilePath, content);
                PgpKeyGenerator.GenerateKey(TestKeys.Username, TestKeys.Password, publicKeyPath, privateKeyPath);
                PgpEncryptor.EncryptFile(inputFilePath, encryptedFilePath, ReadAllText(publicKeyPath));

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

                decryptedFilePath.Should().BePathToFileWithContent(content);
            }
        }