mattosaurus / PgpCore

.NET Core class library for using PGP
MIT License
244 stars 98 forks source link

DecryptFileAsync returns empty file when decrypting single file #158

Closed UroosaSania closed 2 years ago

UroosaSania commented 2 years ago

I am reading PGP files from a folder, iteratively in a loop and feeding each file to the asynchronous method DecryptFileAsync(inputFile, outputFile) for decryption. When the input folder has more than one file, the decryption works flawlessly, however, when there is only one file in the input folder, the method returns an empty (0KB) file in the target location. Note that I am using async-await to call the method DecryptFileAsync(inputFile, outputFile). Can you please offer a solution?

etkirsch10 commented 2 years ago

Not sure if it will help, but I was getting 0Kb files when I neglected to put the Await command in front of pgp.EncryptFileAsync(inputFile, encryptedfile)

Without the Await command, the code was racing ahead and closing the file stream before the encryption was completed.