How to tell JRO.CompactDatabase to keep encrypted databases encryp

G

Guest

I have a (VB) application that creates a database with user-level security.
The user can choose when creating the database whether to encrypt it or not.
When I programmatically compact the database using the JRO CompactDatabase
routine, JRO decrypts the database. I would like the compacted DB to be
encrypted if the original DB was encrypted. And of course, I would like the
compacted DB to be unencrypted if the original DB was unencrypted.

One solution would be for me to find out if the original DB was encrypted
and then explicitely tell JRO whether or not to encrypt the compacted DB. But
I don't know how to tell if the original DB was encrypted. I was hoping that
I could look up the value of "Jet OLEDB:Encrypt Database" in the
ConnectionString, but that is set to False even if the DB is encrypted.

Any ideas?

Thanks!

--Miguel
 
T

TC

I don't know anything about JRO, so there could be a better answer that
this ...

You can tell if it is encrypted by checking the value of certain bytes
in the header block of the database file. Maybe you could work that
out. (The header block is the first 2 or 4 Kb for Jet 3 or 4
respectively.)

Alternatively, take the /second/ block, read the 2 or 4 k bytes
thereof, and look at the frequency distribution of the 256 possible
byte values (0 thru 255). If the file is encrypted, the distribtion
will be even, plus or minus a smidgeon. If it is /not/ encrypted, the
distribution will be substantially skewed - enough to tell the
difference.

HTH,
TC
 
G

Guest

TC said:
You can tell if it is encrypted by checking the value of certain bytes
in the header block of the database file. Maybe you could work that
out. (The header block is the first 2 or 4 Kb for Jet 3 or 4
respectively.)

Alternatively, take the /second/ block, read the 2 or 4 k bytes
thereof, and look at the frequency distribution of the 256 possible
byte values (0 thru 255). If the file is encrypted, the distribtion
will be even, plus or minus a smidgeon. If it is /not/ encrypted, the
distribution will be substantially skewed - enough to tell the
difference.

That would indeed work. Thanks!

If someone has an easier way, let us know...

--Miguel
 
T

TC

Another thought: instead of checking the distribution of all 256 values
from 0 to 255, you could probably just count the number of zeros. If
that was significantly more than (block size)/256, you know the file is
not encrypted. Messy, but easy to code!

HTH,
TC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top