package KiokuDB::Serializer::Crypt; use Moose; use namespace::autoclean; # ABSTRACT: encrypt data stored in L use Crypt::Util; use KiokuDB::Backend::Hash; use KiokuDB::Backend::Serialize; =head1 SYNOPSIS use KiokuDB::Util; use KiokuDB::Serializer::Crypt; my $dsn = '...'; my $secret = '...'; my $backend = KiokuDB::Util::dsn_to_backend( $dsn, serializer => KiokuDB::Serializer::Crypt->new( serializer => 'json', crypt_cipher => 'Rijndael', crypt_mode => 'CFB', crypt_key => $secret, ), ) my $d = KiokuDB->new(backend => $backend); =head1 DESCRIPTION This is a custom serializer for L, which wraps an existing serializer, encrypting the data before it is stored, and decrypting the data as it is retrieved. It can use several different encryption schemes (it's based on L, so anything that that supports). =cut =attr crypt_key The encryption key to use for encrypting and decrypting. Corresponds to C in L. =cut has crypt_key => ( is => 'ro', isa => 'Str', lazy => 1, default => sub { my $self = shift; confess "The 'crypt_key' attribute for " . blessed($self) . " is required if the 'crypt' attribute is not given"; }, ); =attr crypt_cipher The encryption cipher to use. Corresponds to C in L, and defaults to C. You must ensure the appropriate cipher backend is installed (by adding, for instance, L to the dependency list for your application). =cut has crypt_cipher => ( is => 'ro', isa => 'Str', default => 'Rijndael', ); =attr crypt_mode The encryption mode to use. Corresponds to C in L, and defaults to C. You must ensure the appropriate mode backend is installed (by adding, for instance, L to the dependency list for your application). =cut has crypt_mode => ( is => 'ro', isa => 'Str', default => 'CFB', ); =attr crypt The L object which will be used for the encryption. Typically, this will be automatically created based on the other attribute values, but an already-built object can be passed in here for more complicated usages. =cut has crypt => ( is => 'ro', isa => 'Crypt::Util', lazy => 1, default => sub { my $self = shift; return Crypt::Util->new( disable_fallback => 1, default_cipher => $self->crypt_cipher, default_mode => $self->crypt_mode, default_key => $self->crypt_key, ); }, handles => ['encrypt_string', 'decrypt_string'], ); =attr serializer The underlying serializer to use. KiokuDB will use this serializer to get a string representation of the object which will then be encrypted. Defaults to 'storable'. =cut has serializer => ( is => 'ro', does => 'KiokuDB::Backend::Serialize', coerce => 1, default => 'storable', handles => 'KiokuDB::Backend::Serialize', ); around serialize => sub { my $orig = shift; my $self = shift; my (@args) = @_; my $collapsed = $self->$orig(@args); return $self->encrypt_string($collapsed); }; around deserialize => sub { my $orig = shift; my $self = shift; my ($collapsed, @args) = @_; return $self->$orig($self->decrypt_string($collapsed), @args); }; sub default_typemap { my $self = shift; return $self->serializer->default_typemap if $self->serializer->default_typemap; return KiokuDB::Typemap->new; } with 'KiokuDB::Backend::Serialize'; =head1 BUGS No known bugs. Please report any bugs through RT: email C, or browse to L. =head1 SEE ALSO L L =head1 SUPPORT You can find this documentation for this module with the perldoc command. perldoc KiokuDB::Serializer::Crypt You can also look for information at: =over 4 =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * RT: CPAN's request tracker L =item * Search CPAN L =back =begin Pod::Coverage default_typemap =end Pod::Coverage =cut 1;