|Just another Perl shrine|
Opening an Encrypted DB_File databaseby crabbdean (Pilgrim)
|on Jul 14, 2004 at 15:47 UTC||Need Help??|
crabbdean has asked for the
wisdom of the Perl Monks concerning the following question:
I'm creating a password encryption program to store passwords. I store the values into a DB_File database which I then encrypt. The problem comes in then opening and decrypting that database. Normally to tie the database you use:
and then refer to %cryptohash like any normal hash and save it back to file when done. Problem is once the file is encrypted you can't do the tie UNTIL you've decrypted it first (because DB_File doesn't recognise the file format and the tie fails). So you have to decrypt first and then tie.
Now I could just decrypt the master file to a temporary file and then tie to that temporary file (in DB_FILE format) but if during execution the program dies you then have a decrypted copy just lying around. SO ... I'm trying to find a way to decrypt the file into memory and then tie to that piece of memory, instead of to a file. Of course the memory has to be a hash because that is what DB_File utilises and ties to.
But how do you read a file into a hash in memory and then tie to it? OR, if I read the file into an @array how do I then translate that into a valid DB_File format again which can be tied? Its this one little step that I'm stuck at.
Now in my testing I found out you can tie a %hash to a undef'ined file value, which is literally stored in memory which you can then save to file (see below code). This helps solve part of the puzzle(and is an interesting trick), but still not all of the puzzle. Keep in mind I DON'T want to be creating an decrypted verion of the data to file due to security issues.
Any ideas how to bridge this gap?
The Funkster of Mirth
Programming these days takes more than a lone avenger with a compiler. - sam
RFC1149: A Standard for the Transmission of IP Datagrams on Avian Carriers