CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Steve Hebert's Development Blog

Steve's Blog - From .Net to dotMath and everything in between.

detecting SQL traces and fun with encryption

I'm putting together a sql update script execution application and one concern is that someone could grab the script during execution by having a sql trace running.  After checking out the sql server documentation, I came across the following select statement:

select * from :: fn_trace_getinfo(default)

If one or more rows are returned, at least one trace is being run on the system.  Cool stuff!

This has been the one caveat to securing the process.  I'm using the SharpZipLib to compress the script before using TripleDESServiceProvider class to provide encryption.  As a test, I reversed the process to see how much repetition would appear in an uncompressed script.  Here are my numbers:

Script File Size = 3.9MB
Encryped File Size = 3.8MB
Encrypted then Zipped File Size = ~<3.8MB
Zipped File Size = 370000 bytes
Zipped then Encrypted File Size = 369000 bytes

I found it interesting that the encryption creates a random enough pattern to the data that compression doesn't work well.

I've read that compressing a file before encrypting is supposed to be more secure because it makes cracking the encryption. I imagine this could be true since it introduces another step that must be discovered in the process of hacking the file, however I wonder if it would be easier to hack since you'd know what the zip header has to look like.



Comments

Steve Hebert said:

If you compress and then encrypt, the file size is very small (file is <10% original size) and further attempts to compress don't provide additional space savings. The file looks like complete garbage (as it should). I'm then storing the bits in a resource file for runtime distribution.

I thought about posting the code, but it's mostly just a collection of some googled code. (Only invent when you absolutely have to.)
# January 13, 2005 6:09 AM

Steve Hebert's Development Blog said:

I blogged some time back about detecting running traces on Sql2000. You can detect a running trace on...
# June 15, 2006 12:13 PM
Check out Devlicio.us!

Our Sponsors