Re: encrypt/decrypt sqlite data
| From: | Richard Lynch | Date: | Fri, 10 Dec 2004 23:01:49 +0000 |
| Subject: | Re: encrypt/decrypt sqlite data | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-204003@lists.php.net to get a copy of this message | ||
Shawn McKenzie wrote:
> This is my first adventure with mcrypt and also the sqlite stuff.
>
> Via file upload I am getting a SQL dump file and running it as a query
> to insert data into a sqlite db. This works great.
>
> Then I am trying to use an update query to encrypt fields in all rows by
> using the sqlite_create_function to run my encryption function that uses
> $_SESSION['key'] which is an md5 hash of a pass phrase):
>
> $db = sqlite_open("db");
> sqlite_create_function($db, 'enc', 'encrypt', 1);
>
> $sql = 'UPDATE mytable SET f1=enc(f1);'
> .'UPDATE results SET f2=enc(f2);';
>
> sqlite_query($db, $sql);
What are the data types of f1 and f2?
Are you sure they are large enough to hold the result of enc()?
If data is getting a little truncated, or not encryted/decrypted at the
end...
Some encryption functions require input data to be 'padded' to an even
multiple of a certain length. EG, it must be an even multiple of 32-bytes
to be encrypted/decrypted.
Others, I think, pad the results with spaces for similar reasons.
So, possibly, somewhere in all of this, you just need to tack on:
length(x)%32 spaces to your text.
Or maybe you need to be more careful about using trim() and similar
functions in there.
>
> function encrypt($txt)
> {
> $key = $_SESSION['key'];
> $txt = trim($txt);
I don't think any of the encryption routines care about line feeds, though
the functions you use to process in a shell script or even mysql_query()
*might*...
--
Like Music?
http://l-i-e.com/artists.htm