crabbdean has asked for the wisdom of the Perl Monks concerning the following question:
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.tie (%cryptohash, 'DB_File', undef, O_RDWR|O_CREAT, 0644, $DB_BTREE) or die "Database error: $!";
#!perl use DB_File; use Fcntl; # For the constants O_RDWR and O_CREAT use strict; use warnings; ## master file name my $cryptofile = "crypt.qap"; ## create Berkeley DB my %cryptohash; my %testhash; tie (%testhash, 'DB_File', undef, O_RDWR|O_CREAT, 0644, $DB_BTREE) or die "Database error: $!"; $testhash{'this'} = "hello"; print $testhash{'hello'}; tie (%cryptohash, 'DB_File', $cryptofile, O_RDWR|O_CREAT, 0644, $DB_BT +REE) or die "Database error: $!"; %cryptohash = %testhash; untie %cryptohash; untie %testhash;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Opening an Encrypted DB_File database
by iburrell (Chaplain) on Jul 14, 2004 at 16:11 UTC | |
by crabbdean (Pilgrim) on Jul 14, 2004 at 16:38 UTC | |
by MidLifeXis (Monsignor) on Jul 14, 2004 at 16:59 UTC | |
by crabbdean (Pilgrim) on Jul 14, 2004 at 18:10 UTC | |
by iburrell (Chaplain) on Jul 14, 2004 at 20:35 UTC | |
| |
|
Re: Opening an Encrypted DB_File database
by PodMaster (Abbot) on Jul 14, 2004 at 19:43 UTC |