Exemplo n.º 1
0
 /// <summary>
 /// Encrypts a file and writes the ciphertext to another file.
 /// </summary>
 /// <param name="context">The <see cref="GpgContext"/> to operate on.</param>
 /// <param name="inputFilePath">The path to the unencrypted file.</param>
 /// <param name="outputFilePath">The path where the encrypted file should be saved.</param>
 /// <param name="encryptFlags">The encryption flags to be used.</param>
 /// <param name="overwrite">Whether the existing file should be overwritten if a file already exists at <paramref name="outputFilePath"/>.</param>
 /// <param name="recipients">The GPG keys for which the data should be encrypted.</param>
 public static void EncryptFile(this GpgContext context, string inputFilePath, string outputFilePath, IEnumerable <GpgKey> recipients, EncryptFlags encryptFlags = EncryptFlags.None, bool overwrite = false)
 {
     using (var file = File.Open(outputFilePath, overwrite ? FileMode.Create : FileMode.CreateNew))
         using (var plain = MemoryGpgBuffer.CreateFromFile(inputFilePath))
             using (var cipher = context.Encrypt(plain, recipients, encryptFlags))
             {
                 cipher.CopyTo(file);
             }
 }