Crypt-ECB
view release on metacpan or search on metacpan
- make Crypt:ECB work under perl-5.8.* again
- some changes actually made in v2.00 haven't been mentioned in the changelog
- add some more block ciphers to the test suite
- minor changes in test.pl
- minor documentation update
v2.00, 19.02.2016
- ATTENTION, there are subtle changes in the API, see README for details
- removed caching; the feature did finally not seem to make much sense
- removed constants indicating the padding mode (PADDING_AUTO, PADDING_NONE)
- removed errstring(), Crypt::CBC now dies when stumbling over errors
- better compatibility with current Crypt::CBC:
- allow passing options like Crypt::CBC does (new and old styles)
- allow passing an existing cipher object (RT ticket #112020)
- added padding styles, including custom padding
- adding 'null' padding fixes RT ticket #80456
- added methods for accessing keysize and blocksize of a cipher
- use Test::More (thanks to Xavier Guimard for providing a patch, RT ticket #82301)
- changed internal attribute names (foo -> _foo and Foo -> foo)
- much more internal code cleanup
- updated documentation
v1.45, 16.07.2008
- fixed test.pl so it will not stumble over an already installed Crypt::CBC
- fixed bug in t/70-funcstyle.t which could in some cases let tests wrongly fail
- test scripts: changed indentation, updated list of known ciphers
v1.40, 07.01.2005
- the '0' block problem still had survived in functions encrypt and decrypt... fixed
- some code cleanup
- changed versioning scheme to be more CPAN-like
v1.3, 06.01.2005
- no code changes, just some minor documentation update
_cipherobj => '', # contains the block cipher object
_buffer => '', # internal buffer used by crypt() and finish()
};
bless $self, $class;
if ($_[0])
{
my $options;
# options Crypt::CBC style
if ($_[0] =~ /^-[a-zA-Z]+$/)
{
my %tmp = @_;
$options->{substr(lc $_, 1)} = $tmp{$_} for keys %tmp;
}
# options like in Crypt::CBC before 2.13
elsif (ref $_[0] eq 'HASH')
{
$options = shift;
}
# and like Crypt::CBC before 2.0
else
{
$options->{key} = shift;
$options->{cipher} = shift || 'DES';
}
# cipher has to be called before keysize and blocksize
# otherwise it would override values provided by the user
$self->$_( $options->{$_} ) foreach qw(cipher keysize key blocksize padding);
}
# ...use it
$self->{_cipherobj} = $cipher;
$module = ref $cipher;
($cipher = $module) =~ s/^Crypt:://;
}
# else try to load the specified cipher module
else
{
# for compatibility with Crypt::CBC, cipher modules can be specified
# with or without the 'Crypt::' in front
$module = $cipher=~/^Crypt/ ? $cipher : "Crypt::$cipher";
eval "require $module";
die "Couldn't load $module: $@"."Are you sure '$cipher' is correct? If so,"
. " install $module in the proper path or choose some other cipher.\n"
if $@;
# delete possibly existing cipher obj from a previous crypt process
# otherwise changes in the cipher would not be recognized by start()
$plaintext = decrypt($key, 'Blowfish', $ciphertext);
$hexcode = encrypt_hex($key, $cipher, $plaintext);
$plain = decrypt_hex($key, $cipher, $hexcode);
=head1 DESCRIPTION
This module is a Perl-only implementation of the ECB mode. In
combination with a block cipher such as Blowfish, DES, IDEA or Rijndael,
you can encrypt and decrypt messages of arbitrarily long length. Though
for security reasons other modes than ECB such as CBC should be
preferred. See textbooks on cryptography if you want to know why.
The functionality of the module can be accessed via OO methods or via
standard function calls. Remember that some block cipher module like for
example Crypt::Blowfish has to be installed. The syntax of Crypt::ECB
follows that of Crypt::CBC.
=head1 METHODS
=head2 new()
$ecb = Crypt::ECB->new(
-cipher => $cipher,
-key => $key,
-padding => 'oneandzeroes',
-keysize => 8, # use to override cipher's default
keysize => 8, # use to override cipher's default
blocksize => 8, # use to override cipher's default
});
or (only key and cipher can be passed this way)
$ecb = Crypt::ECB->new($key, 'Blowfish');
$ecb = Crypt::ECB->new($key); # DES is assumed
The following options are recognized: cipher, key, keysize, blocksize
and padding. Options can be passed like in Crypt::CBC. All options
can be read and also be changed via corresponding methods afterwards.
If called without parameters you have to call at least B<key()> and
B<cipher()> before you can start crypting.
=head2 cipher(), module(), key()
$ecb = Crypt::ECB->new;
$ecb->cipher('Blowfish');
$ecb->key('some_key');
B<decrypt()>.
=head1 BUGS
None that I know of. Please report if you find any.
=head1 TODO
Implement 'random' padding, see http://www.di-mgt.com.au/cryptopad.html.
A taint check on the key like Crypt::CBC does could be added.
=head1 LICENSE
Crypt-ECB is Copyright (C) 2000, 2005, 2008, 2016 by Christoph Appel.
This module is distributed using the same terms as Perl itself. It is free
software; you can redistribute it and/or modify it under the terms of either:
a) the GNU General Public License as published by the Free Software
Foundation; either version 1, or (at your option) any later version, or
b) the "Artistic License".
=head1 AUTHOR
Christoph Appel (see ECB.pm for email address)
=head1 SEE ALSO
perl(1), Crypt::DES(3), Crypt::IDEA(3), Crypt::CBC(3)
=cut
Module Crypt::ECB
-----------------
DESCRIPTION
This module is a Perl-only implementation of the ECB mode. In
combination with a block cipher such as DES, IDEA or Blowfish, you can
encrypt and decrypt messages of arbitrarily long length. Though for
security reasons other modes than ECB such as CBC should be preferred.
See textbooks on cryptography if you want to know why.
The functionality of the module can be accessed via OO methods or via
standard function calls. Remember that some crypting module like for
example Blowfish has to be installed. The syntax follows that of
Crypt::CBC.
INSTALLATION
To install, just type
perl Makefile.PL
make
make test
make install
UPGRADING
Eight years after the last release I thought it was okay to make a major
upgrade. Which makes subtle changes to the API. So, if you are upgrading
from a version below 2.00, be aware that the API has changed:
- The caching feature is no longer available. Contact me if you really
think you need it.
- As I thought that exporting global constants isn't that nice and also
in order to be more compatible with Crypt::CBC I changed the way that
padding() is called:
$ecb->padding(PADDING_AUTO) should be replaced by $ecb->padding('standard')
(or could be omitted, because this is the default for Crypt-ECB-2.00 and
later).
$ecb->padding(PADDING_NONE) should be replaced by $ecb->padding('none').
$ecb->padding('none') is also needed if no padding was specified, because
no padding was the default for versions before v2.00.
( run in 1.815 second using v1.01-cache-2.11-cpan-e1769b4cff6 )