views:

74

answers:

3

I use MySQL extensively, but it doesn't support database-level encryption without some external library.

What databases come with db-level support built-in, and if you know MySQL enough to compare, how close is its syntax to MySQL. I'd obviously prefer not to re-learn everything.

I also use PDO extensively to handle sql injections, so ideally PDO-friendly is preferred.

+1  A: 

I know Oracle 11g supports database level encryption, but i wouldn't say it's the most similar to MySQL...

gillyb
+2  A: 

Absolutely.

SELECT *, AES_DECRYPT(`field`, 'key') as `decrypted` FROM enc WHERE AES_DECRYPT(`field`, 'key')='$input'

I am not sure if there's a way of only calling AES_DECRYPT once per field.

quantumSoup
A: 

I've just been researching the same problem as I'm investigating mySQL after having used both column and db level encryption in SQL Server.

So this has answered my concerns that mySQL did not have out of the box db level encryption but it may be worth mentioning in the answer given above it would result in a table scan every time it is called. This is because each row will have to be read so the data can be decrypted before being compared. That invalidates any index that may have been put on the column (if there's any value in that too!) However the following statement would do the same thing but only calls ENCRYPT once and possibly gets around any table scans. Note: mySQL syntax is probably incorrect in places.

DECLARE $EncryptedValue ...
SELECT $EncryptedValue = AES_ENCRYPT(`$input`, 'key') 

SELECT 
   *, 
  $input as `decrypted` 
FROM enc 
WHERE 
  `field`=$EncryptedValue
Paul Hadfield