Crypt-SEED
view release on metacpan or search on metacpan
}
###
sub keyIndex {
my $this = shift;
defined $this->{index}->{$_[0]} ? $this->{index}->{$_[0]} : undef;
}
###
sub count { $#{ shift->{rkeys} } + 1; }
1;
__END__
=head1 NAME
Crypt::SEED - Perl extension for SEED encryption/decryption algorithm.
=head1 SYNOPSIS
use Crypt::SEED;
my $seed = new Crypt::SEED();
$seed->addKeys( @user_keys );
# or
my $seed = new Crypt::SEED( @user_keys );
# Each key must be in 16 bytes in length
my $seed = new Crypt::SEED( '0123456789ABCDEF' ); # userkey.
my $cipher = $seed->encrypt( $source_data, '0123456789ABCDEF' );
my $cipher = $seed->encrypt( $source_data, 3 );
# 3 above is an user key index. starting from 0.
my $recall = $seed->decrypt( $cipher, '0123456789ABCDEF' ); # by user key.
my $recall = $seed->decrypt( $cipher, 3 ); # by index
if( !$seed->hasAKey( $userKey ) ) {
$seed->addKey( $userKey );
}
my $index = $seed->replaceKey($userKey, $newKey);
my $number_of_keys = $seed->count();
my $idx = $seed->keyIndex($userKey);
my $userKey = $seed->findUserKey($idx);
=head1 DESCRIPTION
This module provides the Perl community with the SEED encryption
algorithm which has been made by Korean Information Security Agency(KISA,
http://www.kisa.or.kr).
SEED encryption/decryption uses a 'round key' which translated from a user key.
Whenever you add user keys to the module using new or addKey or addKeys, the
module will translate them to round keys and store them inside the module
with user keys. (Of course, in hash)
And, whenever you use the user key with encrypt, decrypt methods, the module
look for the matching round key from inside the module to do real job.
=head2 Important notes on Encoding
Please, E<lt>DO NOT use encoding 'blah';.E<gt>
I could not figure out how to restore those decoded bytes into an SV variable
in the script where 'use encoding...' inserted.
Do you know ? Let me know, please.
=head2 EXPORT
None by default.
=head1 Subroutines
=over
=item new
=over
my $seed = new Crypt::SEED();
my $seed = new Crypt::SEED('0123456789ABCDEF');
my $seed = new Crypt::SEED( LIST or Array );
This will create an object of Crypt::SEED.
It can accept any number of user keys as its parameter.
An user key is consist of 16 characters exactly.
Every objects have its own key set.
=back
=item addKey
=over
my $idx = $seed->addKey( $userKey );
my $cipher_data = $seed->encrypt($plain_text, $idx);
...
print SOCKET "$idx:$cipher_data\n"; # Do not send user key !!
You must add a key or more to the object before encryption or decryption.
An user key must be a 16 bytes long string.
Returns the index number of the key.
You can use this index number as an 'index' :-) and then you can deliver it
to the counter part who shares the same user key set.
(And do not deliver the user key itself for the sake of security.)
You can add user keys up to 99_999_999. (It is sufficient, isn't it? ;-)
Index number starts from 0, not 1.
=back
=item addKeys
=over
$seed->addKeys( a list of user keys );
This method simply calls $seed->addKey as many as it has beed requested.
Returns the number of user keys actually added.(including the keys which
exists already)
=back
=item removeKey
( run in 1.059 second using v1.01-cache-2.11-cpan-2398b32b56e )