SQLite file containing garbage characters SQLite file containing garbage characters sqlite sqlite

SQLite file containing garbage characters


Without seeing your encrypt/decrypt routines I can only guess. Since you are using Rijndael, you need to ensure that you are setting the same Padding on the class for encrypt and decrypt. Also, make sure you call FlushFinalBlock when encrypting the data. That call is not listed in the sample (although they are calling Close which should call FlushFinalBlock, so if you are calling Close on the CryptoStream then you should be okay there).

Edit
I was thinking more about this. I think it may be related to the padding (again, without seeing your code its hard to say). Depending on the padding mode you choose, you will need to strip the padded bytes back off of the plain text after decrypting.


The most likely places for your problem to live is when you're reading in the unencrypted database prior to encryption, or opening a new file to write out the freshly decrypted database.

As troubleshooting steps, you might consider reading in the raw database file as bytes and then writing it out, without any intervening encryption/decryption. If it still gets corrupted, the first thing I'd check is the encoding with which you're opening your output file.