SQLite file containing garbage characters

I am currently using MonoTouch and SQLite to determine if using a database with encryption is better than a standard .txt file with encryption.

I am trying to use the RijndaelManaged and other System.Security.Cryptography methods to encrypt my SQLite DB, but the DB is getting corrupted.

I found a problem, but I have no idea why this is happening or how to fix it. This is a basic SQLite file with a separate table:

 SQLite format 3@ -β€š ΓΈΓΈ?gtablenewnewCREATE TABLE new (id int(5), name vchar(255)) 

After using the online application and encrypting this database, I get the following:

 SQLite format 3@ -    ?gtablenewnewCREATE TABLE new (id int(5), name vchar(255)) 

This results in damage to the DB. Does anyone know why this is happening? Can someone help me encrypt this DB WITHOUT using SQLCipher?

EDIT: I tried reading the original database as bytes and trying to convert the bytes to a string, but no matter what encoding I use, I get \ 0 after the first row.

+7
source share
2 answers

Without seeing my encryption / decryption routines, I can only guess. Since you are using Rijndael, you need to make sure that you set the Padding class for the class for encryption and decryption. Also, make sure that you encrypt FlushFinalBlock data. This call is not specified in the sample (although they call Close , which should call FlushFinalBlock , so if you call Close in CryptoStream , then you should be fine).

Edit
I thought about it more. I think this could be due to padding (again, without seeing how your code is hard to say). Depending on the selected fill mode, after decryption, you will need to remove the missing bytes from the plain text.

+3
source

The most likely places for your problem are when you read in an unencrypted database before encryption or open a new file to write to the recently decrypted database.

As troubleshooting steps, you can consider reading in the raw database file as bytes, and then writing it without any intermediate encryption / decryption. If it is still damaged, the first thing I checked is the encoding with which you open the output file.

+2
source

All Articles