minceme has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I'm using BerkeleyDB 4.1 (RedHad 7.3) together with BerkeleyDB.pm version 0.20. The version of DB4.1 supports encrypted datafiles and logfiles, but I can't seem to get it working. Grepping the database shows no encryption is taking place. This is what I have so far:
use strict ;
use BerkeleyDB ;

my $dbfile = 'encrypt.db'
unlink $dbfile;

my $env = new BerkeleyDB::Env
    -SetFlags=> DB_ENCRYPT;

my $db = tie my %hash, 'BerkeleyDB::Hash',
    -Filename   => $dbfile',
     -Env=> $env,
     -Flags     => DB_CREATE,
  or die "Cannot open $filename: $!\n" ;

$hash{jallah} = "bah" ;

undef $db ;
untie %hash ;
By inspecting the 'encrypt.db', I can find the string 'jallah' I stored in the database. :(
Clearly, no encryption has taken place.

I'm no C programmer, and find it difficult to use the docs from sleepycat. I find nothing about encryption in the pods for BerkeleyDB.pm, still when inspecting the sources of BerkeleyDB.pm I get the impression that it's supported? - Vlad

Replies are listed 'Best First'.
Re: Problems using BerkeleyDB encryption
by diotalevi (Canon) on Mar 26, 2003 at 22:38 UTC

    Actually no. In browsing the SleepyCat documentation see that you have to have either use DB_ENV->set_encrypt or DB->set_encrypt to set the encryption password. You did neither. Also, a browse of BerkeleyDB.xs doesn't show that either of those functions are supported by BerkeleyDB. I'd suggest you add the methods to BerkeleyDB and recompile. Send your modifications to the module author as a patch and hopefully we'll all benefit by that.

      Thanks, I'll take a look and see what I can do.

      My hopes aren't too high, but I'll fiddle a little with it. If something comes out of it, I'll mail the author a patch, as you suggested.

      -- Vlad

        You know... you could also pay someone to do the XS for you. I'm sure there are plenty of people here who would implement those functions for you for a suitable recompense. I'd think that perhaps a required donation to perlmonks might do it. Or whatever else they happen to want. I'm just thinking that its not a trivial task for you to implement some methods in C if you aren't already a C programmer.