NAME
Crypt::Mode::CBC::Easy - Encrypts/decrypts text and verifies decrypted text with a checksum and a random initialization vector.
VERSION
version 0.006
SYNOPSIS
my $crypt = Crypt::Mode::CBC::Easy->new(key => $bytes);
my $cipher_text = $crypt->encrypt("hello");
print "Cipher text: $cipher_text\n";
my $plain_text = $crypt->decrypt($cipher_text);
print "Plain text: $plain_text\n";
# encrypt and decrypt an array of values
my $cipher_text = $crypt->encrypt(@texts);
print "Cipher text: $cipher_text\n";
my @plain_texts = $crypt->decrypt($cipher_text);
for my $plain_text (@plain_texts) {
print "plain text: $plain_text\n";
}
# or get plain texts as one string separated by separator
my $plain_text = $crypt->decrypt($cipher_text);
print "Plain text: $plain_text\n";
DESCRIPTION
A convenience class that wraps Crypt::Mode::CBC and adds random initialization vector support along with a checksum to make sure that all decrypted text has not been tampered with.
METHODS
key
The key that will be used for encrypting and decrypting. The key should be the appropriate length for the Crypt::Cipher used with "crypt_mode_cbc". For the default Crypt::Cipher used, Twofish, the key should be 128/192/256 bits.
crypt_mode_cbc
Sets the Crypt::Mode::CBC that will be used for encryption. Make sure if you change this that you set "block_size" to the correct value for the Crypt::Cipher you have chosen. The default value uses Crypt::Cipher::Twofish.
block_size
Sets the block size for the Crypt::Cipher that is used. Default is 16, because this is the block size for Crypt::Cipher::Twofish.
checksum_digest_hex
This is a subroutine reference to the digest hex that will be used for the checksum.
my $crypt = Crypt::Mode::CBC::Easy->new(key => $bytes, checksum_digest_hex => \&Digest::SHA::sha256_hex);
Default is Digest::SHA::sha512_hex.
bytes_random_secure
A Bytes::Random::Secure instance that is used to generate the initialization vector for each encryption. Default is a Bytes::Random::Secure instance with NonBlocking set to true.
separator
Sets the separator between the initialization vector, the encrypted text, and the checksum. This should not need to be changed, and is only available for backwards compatability with DBIx::Raw which used to use DBIx::Raw::Crypt. Default value is '::~;~;~::'. If you need to change this for backwards compatability, use ':;:'.
encrypt
Encrypts plain texts or an array of plain texts.
my $cipher_text = $crypt->encrypt($text);
# OR
my $cipher_text = $crypt->encrypt(@texts);
decrypt
Decrypts cipher text into one plain text or an array of plain texts.
my $plain_text = $crypt->encrypt($cipher_text);
# OR
my @plain_texts = $crypt->decrypt($cipher_text);
If you previously encrypted an array of values and ask for a result in a scalar context, you will be returned the the decrypted values separated by "separator".
AUTHOR
Adam Hopkins <srchulo@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2017 by Adam Hopkins.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.