Crypt-PBE

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

            "ExtUtils::MakeMaker" : "0"
         }
      },
      "configure" : {
         "requires" : {
            "ExtUtils::MakeMaker" : "0"
         }
      },
      "runtime" : {
         "requires" : {
            "Crypt::CBC" : "0",
            "Crypt::DES" : "0",
            "Crypt::OpenSSL::AES" : "0",
            "Digest::MD2" : "0",
            "Digest::MD5" : "0",
            "Digest::SHA" : "0",
            "Term::ReadKey" : "0",
            "perl" : "5.008"
         }
      },
      "test" : {

META.yml  view on Meta::CPAN

license: artistic_2
meta-spec:
  url: http://module-build.sourceforge.net/META-spec-v1.4.html
  version: '1.4'
name: Crypt-PBE
no_index:
  directory:
    - t
    - inc
requires:
  Crypt::CBC: '0'
  Crypt::DES: '0'
  Crypt::OpenSSL::AES: '0'
  Digest::MD2: '0'
  Digest::MD5: '0'
  Digest::SHA: '0'
  Term::ReadKey: '0'
  perl: '5.008'
resources:
  repository: git://github.com/giterlizzi/perl-Crypt-PBE
version: '0.103'

Makefile.PL  view on Meta::CPAN

    EXE_FILES          => ['bin/pkcs5-tool'],
    MIN_PERL_VERSION   => 5.008,
    PL_FILES           => {},
    CONFIGURE_REQUIRES => {
        'ExtUtils::MakeMaker' => '0',
    },
    TEST_REQUIRES => {
        'Test::More' => '0',
    },
    PREREQ_PM => {
        'Crypt::CBC'          => '0',
        'Crypt::DES'          => '0',
        'Digest::MD2'         => '0',
        'Digest::MD5'         => '0',
        'Digest::SHA'         => '0',
        'Crypt::OpenSSL::AES' => '0',
        'Term::ReadKey'       => '0',
    },
    META_MERGE => {
        'meta-spec' => { version => 2 },
        'resources' => {

lib/Crypt/PBE/CLI.pm  view on Meta::CPAN

    ReadMode 'normal';
    print "\n";

    return $value;

}

sub show_version {

    require Crypt::PBE;
    require Crypt::CBC;
    require Crypt::DES;
    require Crypt::OpenSSL::AES;

    print <<"EOF";
pkcs5-tool v$VERSION

CORE
  Perl                 ($^V, $^O)
  Crypt::PBE           ($Crypt::PBE::VERSION)

CRYPT MODULES
  Crypt::CBC           ($Crypt::CBC::VERSION)
  Crypt::DES           ($Crypt::DES::VERSION)
  Crypt::OpenSSL::AES  ($Crypt::OpenSSL::AES::VERSION)

DIGEST MODULES
  Digest::MD2          ($Digest::MD2::VERSION)
  Digest::MD5          ($Digest::MD5::VERSION)
  Digest::SHA          ($Digest::SHA::VERSION)

EOF

lib/Crypt/PBE/PBES1.pm  view on Meta::CPAN

package Crypt::PBE::PBES1;

use strict;
use warnings;
use utf8;

use Carp;
use Crypt::CBC;
use Exporter qw(import);

use Crypt::PBE::PBKDF1;

our $VERSION = '0.103';

use constant ENCRYPTION => { 'des' => 'Crypt::DES', };

sub new {

lib/Crypt/PBE/PBES1.pm  view on Meta::CPAN

    $self->{dk_len} = $dk_len;

    return bless $self, $class;

}

sub encrypt {

    my ( $self, $data ) = @_;

    my $salt = Crypt::CBC->random_bytes(8);
    my $DK   = pbkdf1(
        hash     => $self->{hash},
        password => $self->{password},
        salt     => $salt,
        count    => $self->{count},
        dk_len   => $self->{dl_len}
    );

    my $key = substr( $DK, 0, 8 );
    my $iv  = substr( $DK, 8, 8 );

    my $crypt = Crypt::CBC->new(
        -key         => $key,
        -iv          => $iv,
        -literal_key => 1,
        -header      => 'none',
        -cipher      => 'Crypt::DES',
    );

    my @result = ( $salt, $crypt->encrypt($data) );

    return wantarray ? @result : join( '', @result );

lib/Crypt/PBE/PBES1.pm  view on Meta::CPAN

        hash     => $self->{hash},
        password => $self->{password},
        salt     => $salt,
        count    => $self->{count},
        dk_len   => $self->{dl_len}
    );

    my $key = substr( $DK, 0, 8 );
    my $iv  = substr( $DK, 8, 8 );

    my $ciper = Crypt::CBC->new(
        -key         => $key,
        -iv          => $iv,
        -literal_key => 1,
        -header      => 'none',
        -cipher      => 'Crypt::DES',
    );

    my $decrypted = $ciper->decrypt($encrypted);

    return $decrypted;

lib/Crypt/PBE/PBES1.pm  view on Meta::CPAN

        'password'   => 'mypassword'
    );

    my $encrypted = $pbes1->encrypt('secret');
    say $pbes1->decrypt($encrypted); # secret


=head1 DESCRIPTION

PBES1 combines the PBKDF1 function with an underlying block cipher, which shall
be either DES or RC2 in cipher block chaining (CBC) mode.

PBES1 is recommended only for compatibility with existing applications, since it
supports only two underlying encryption schemes, each of which has a key size
(56 or 64 bits) that may not be large enough for some applications.


=head1 CONSTRUCTOR

=head2 Crypt::PBE::PBES1->new ( %params )

lib/Crypt/PBE/PBES2.pm  view on Meta::CPAN

package Crypt::PBE::PBES2;

use strict;
use warnings;
use utf8;

use Carp;
use Crypt::CBC;
use Exporter qw(import);

use Crypt::PBE::PBKDF2;

our $VERSION = '0.103';

use constant KEY_SIZE => {
    'aes-128' => 16,
    'aes-192' => 24,
    'aes-256' => 32,

lib/Crypt/PBE/PBES2.pm  view on Meta::CPAN

    $self->{dk_len} = $dk_len;

    return bless $self, $class;

}

sub encrypt {

    my ( $self, $data ) = @_;

    my $salt = Crypt::CBC->random_bytes(16);
    my $iv   = Crypt::CBC->random_bytes(16);

    my $key = pbkdf2(
        prf      => $self->{hmac},
        password => $self->{password},
        salt     => $salt,
        dk_len   => $self->{dk_len},
        count    => $self->{count}
    );

    my $cipher = Crypt::CBC->new(
        -key         => $key,
        -keysize     => length($key),
        -iv          => $iv,
        -header      => 'none',
        -literal_key => 1,
        -cipher      => ENCRYPTION->{ $self->{encryption} }
    );

    my $encrypted = $cipher->encrypt($data);

lib/Crypt/PBE/PBES2.pm  view on Meta::CPAN

    }

    my $key = pbkdf2(
        prf      => $self->{hmac},
        password => $self->{password},
        salt     => $salt,
        dk_len   => $self->{dk_len},
        count    => $self->{count}
    );

    my $cipher = Crypt::CBC->new(
        -key         => $key,
        -keysize     => length($key),
        -iv          => $iv,
        -header      => 'none',
        -literal_key => 1,
        -cipher      => ENCRYPTION->{ $self->{encryption} }
    );

    return $cipher->decrypt($encrypted);



( run in 1.609 second using v1.01-cache-2.11-cpan-39bf76dae61 )