Crypt-Util
view release on metacpan or search on metacpan
lib/Crypt/Util.pmc view on Meta::CPAN
}
sub __curry_instance {
my ($class, $method_name, undef, $col) = @_;
my $self = $col->{instance} ||= $class->__curry_flavoured_instance($col);
sub { $self->$method_name(@_) };
}
sub __curry_flavoured_instance {
my ( $class, $col ) = @_;
my %params; @params{ map { "default_$_" } keys %{ $col->{defaults} } } = values %{ $col->{defaults} };
$class->new( \%params );
}
__PACKAGE__;
__END__
=pod
=head1 NAME
Crypt::Util - A lightweight Crypt/Digest convenience API
=head1 SYNOPSIS
use Crypt::Util; # also has a Sub::Exporter to return functions wrapping a default instance
my $util = Crypt::Util->new;
$util->default_key("my secret");
# MAC or cipher+digest based tamper resistent encapsulation
# (uses Storable on $data if necessary)
my $tamper_resistent_string = $util->tamper_proof( $data );
my $verified = $util->thaw_tamper_proof( $untrusted_string, key => "another secret" );
# If the encoding is unspecified, base32 is used
# (hex if base32 is unavailable)
my $encoded = $util->encode_string( $bytes );
my $hash = $util->digest( $bytes, digest => "md5" );
die "baaaad" unless $util->verify_hash(
hash => $hash,
data => $bytes,
digest => "md5",
);
=head1 DESCRIPTION
This module provides an easy, intuitive and forgiving API for wielding
crypto-fu.
The API is designed as a cascade, with rich features built using simpler ones.
this means that the option processing is uniform throughout, and the behaviors
are generally predictable.
Note that L<Crypt::Util> doesn't do any crypto on its own, but delegates the
actual work to the various other crypto modules on the CPAN. L<Crypt::Util>
merely wraps these modules, providing uniform parameters, and building on top
of their polymorphism with higher level features.
=head2 Priorities
=over 4
=item Ease of use
This module is designed to have an easy API to allow easy but responsible
use of the more low level Crypt:: and Digest:: modules on CPAN. Therefore,
patches to improve ease-of-use are very welcome.
=item Pluggability
Dependency hell is avoided using a fallback mechanism that tries to choose an
algorithm based on an overridable list.
For "simple" use install Crypt::Util and your favourite digest, cipher and
cipher mode (CBC, CFB, etc).
To ensure predictable behavior the fallback behavior can be disabled as necessary.
=back
=head2 Interoperability
To ensure that your hashes and strings are compatible with L<Crypt::Util>
deployments on other machines (where different Crypt/Digest modules are
available, etc) you should use C<disable_fallback>.
Then either set the default ciphers, or always explicitly state the cipher.
If you are only encrypting and decrypting with the same installation, and new
cryptographic modules are not being installed, the hashes/ciphertexts should be
compatible without disabling fallback.
=head1 EXPORTED API
B<NOTE>: nothing is exported by default.
L<Crypt::Util> also presents an optional exported api using L<Sub::Exporter>.
Unlike typical exported APIs, there is no class level default instance shared
by all the importers, but instead every importer gets its own instance.
For example:
package A;
use Crypt::Util qw/:all/;
default_key("moose");
my $ciphertext = encrypt_string($plain);
( run in 0.815 second using v1.01-cache-2.11-cpan-39bf76dae61 )