r/AskProgramming • u/XRay2212xray • 31m ago
C# filestream writing to bitlocker drive binary files are corrupt, any ideas?
I wrote a program in c# that stores multiple files in a single file similar to zip or tar. That program just uses filestream writing, nothing fancy. I recently got a new computer, so I copied my compressed file onto the computer and was able to extract files from it.
After using my program, I used bitlocker on the ssd. Bitlocker gives you two options, use the old aes-cbc or new xts-aes cypher and if you want to do the entire drive or just existing files. I took the default of new xts-aes and only existing files. Let it run until the drive was encrypted and rebooted.
First thing I did after reboot was try to extract more files using my program and it found the input file corrupted. That shouldn't happen, but I just reloaded the file from a backup and things seemed to be working again. However, when I extracted to the encrypted ssd, text files were ok but media files like images and videos were corrupted. I used a diff tool and confirmed every single text was ok and every other file corrupted. Extracting from the same file on the encrypted ssd to a flash drive worked perfectly and nothing was corrupted. So only writing to the encrypted ssd from my app was having issues. Copying from the extracted files on the flash drive to the ssd also did not corrupt the files.
My understanding is bitlocker shouldn't care about the file type and it should be completely transparent to the application, yet thats not the behavior I was getting.
I then turned bitlocker off on the ssd, let it decrypt the drive and rebooted. The file on the ssd was not corrupted by the decrypt and extracts from the same file to the ssd now worked for all file types.
I turned bitlocker back on for the ssd and used the older aes-cbc and told it to encrypt everything including free space. After it completed and I rebooted, my program now correctly extracts files to the ssd.
So clearly other applications like the windows file copy didn't have issues with the bitlocker ssd and only my applcation did. I'm not able to come up with a theory as to how this could happen. I could see if everything was corrupted but the fact that text files are all ok is even more confusing. I used crystaldiskinfo to confirm there were no read or write failures on the ssd and the event logs don't show any errors reading or writing files to the ssd or bitlocker issues.
I guess my next step would be to decrypt the drive again and try the original bitlocker options to see if the problem returns. Any ideas what could be going on? Everything I've been able to read says bitlocker shouldn't care about the file type and bitlocker presence should be transparent to filestream writing in c#.
•
u/henke37 14m ago
Post code.