package KiokuDB::Serializer::Crypt; use Moose::Role; use namespace::autoclean; # ABSTRACT: encrypt data stored in kiokudb use Crypt::Util; =head1 SYNOPSIS package My::Serializer; use Moose; with 'KiokuDB::Serializer', 'KiokuDB::Serializer::Crypt'; sub serialize { ... } sub deserialize { ... } =head1 DESCRIPTION This is a role which wraps the C and C methods of a L class, encrypting the results before storing them into the database, and decrypting them when retrieving them. It can use several different encryption schemes (it's based on L, so anything that that supports). Unless you are writing a custom serializer, you probably want to look at the classes which consume this role: L, L, and L. =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', default => sub { 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'], ); 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); }; =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 =cut 1;