Dipki

 view release on metacpan or  search on metacpan

lib/Dipki/Cipher.pm  view on Meta::CPAN

=cut

# Alg
use constant TDEA => 0x10;  #: Triple DES (3DES, des-ede3)
use constant AES128 => 0x20;  #: AES-128
use constant AES192 => 0x30;  #: AES-192
use constant AES256 => 0x40;  #: AES-256

# Mode
use constant ECB => 0;      #: Electronic Code Book mode (default)
use constant CBC => 0x100;  #: Cipher Block Chaining mode
use constant OFB => 0x200;  #: Output Feedback mode
use constant CFB => 0x300;  #: Cipher Feedback mode
use constant CTR => 0x400;  #: Counter mode

# Padding
use constant NOPAD        => 0x10000;  #: No padding is added
use constant PKCS5        => 0x20000;  #: Padding scheme in PKCS#5/#7
use constant ONEANDZEROES => 0x30000;  #: Pad with 0x80 followed by as many zero bytes necessary to fill the block
use constant ANSIX923     => 0x40000;  #: Padding scheme in ANSI X9.23
use constant W3C          => 0x50000;  #: Padding scheme in W3C XMLENC

lib/Dipki/Cipher.pm  view on Meta::CPAN

=item $prikeyfile

Key of exact length for block cipher algorithm  (see L<Cipher::KeyBytes>).

=item $iv

Initialization Vector (IV) of exactly the block size (see L<Cipher::BlockBytes>) or C<""> for ECB mode.

=item $algmodepad

 String containing the block cipher algorithm, mode and padding, e.g. C<"Aes128/CBC/OneAndZeroes">.
 Alternatively, set $algmodepad as C<""> and use option flags for Alg, Mode and Padding in the $opts parameter.

=item $opts

Options. Add Cipher::PREFIXIV to prepend the IV to the output.

=back

=head2 Example

  use Dipki;
  $ct = Dipki::Cipher::Encrypt($pt, $key, $iv, "Aes128/CBC/OneAndZeroes", Dipki::Cipher::PREFIXIV);
  $ct = Dipki::Cipher::Encrypt($pt, $key, $iv, "", Dipki::Cipher::AES128 | Dipki::Cipher::CBC | Dipki::Cipher::ONEANDZEROES | Dipki::Cipher::PREFIXIV);

=cut
sub Encrypt {
	croak "Missing input parameter" if (scalar(@_) < 4);
	my ($data) = shift;
	my ($key) = shift;
	my ($iv) = shift;
	my ($algstr) = shift;
	my ($opts) = shift || 0;
	my $dllfunc = Win32::API::More->new(

lib/Dipki/Cipher.pm  view on Meta::CPAN

=head1 EncryptBlock function

Encrypt a block of data using a block cipher. 

=head2 Synopsis

  $ct = Dipki::Cipher::EncryptBlock($data, $key, $iv, $alg, $mode);

=head2 Notes

Input data must be an exact multiple of block length for ECB and CBC mode. 
Output is always the same length as the input.

=cut
sub EncryptBlock {
	croak "Missing input parameter" if (scalar(@_) < 5);
	my ($data) = shift;
	my ($key) = shift;
	my ($iv) = shift;
	my ($alg) = shift;
	my ($mode) = shift;

lib/Dipki/Cipher.pm  view on Meta::CPAN

=head1 DecryptBlock function

Decrypt a block of data using a block cipher. 

=head2 Synopsis

  $pt = Dipki::Cipher::DecryptBlock($data, $key, $iv, $alg, $mode);

=head2 Notes

Input data must be an exact multiple of block length for ECB and CBC mode. 
Output is always the same length as the input.

=cut
sub DecryptBlock {
	croak "Missing input parameter" if (scalar(@_) < 5);
	my ($data) = shift;
	my ($key) = shift;
	my ($iv) = shift;
	my ($alg) = shift;
	my ($mode) = shift;



( run in 0.415 second using v1.01-cache-2.11-cpan-e1769b4cff6 )