The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Crypt::PBE::PBES2 - Perl extension for PKCS #5 Password-Based Encryption Schema 2 (PBES2)

SYNOPSIS

    use Crypt::PBE::PBES2;

    my $pbes2 = Crypt::PBE::PBES2->new(
        'hmac'       => 'hmac-sha256',
        'encryption' => 'aes-128',
        'password'   => 'mypassword'
    );

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

DESCRIPTION

PBES2 combines a password-based key derivation function, which shall be PBKDF2 with an underlying encryption scheme. The key length and any other parameters for the underlying encryption scheme depend on the scheme.

PBES2 is recommended for new applications.

CONSTRUCTOR

Crypt::PBE::PBES2->new ( %params )

Params:

  • password : The password to use for the derivation

  • hmac : HMAC digest algorithm ("hmac-sha1", "hmac-sha224", "hmac-sha256", "hmac-sha384" or "hmac-512")

  • encryption : Encryption method ("aes-128", "aes-192" or "aes-256")

  • count : The number of internal iteractions to perform for the derivation key (default "1_000")

METHODS

$pbes2->encrypt( $message )

Perform the encryption and return the encrypted message in binary format.

You can encode the encrypted message in Base64 using MIME::Base64:

    $b64_encrypted = encode_base64 $pbes2->encrypt('secret');

$pbes2->decrypt( $data )

Perform the decryption and return the original message.

    $decrypted = $pbes2->decrypt($encrypted);

You can decode the Base64 encrypted message using MIME::Base64:

    $decrypted = $pbes2->decrypt(decode_base64 $b64_encrypted);

SUPPORT

Bugs / Feature Requests

Please report any bugs or feature requests through the issue tracker at https://github.com/giterlizzi/perl-Crypt-PBE/issues. You will be notified automatically of any progress on your issue.

Source Code

This is open source software. The code repository is available for public review and contribution under the terms of the license.

https://github.com/giterlizzi/perl-Crypt-PBE

    git clone https://github.com/giterlizzi/perl-Crypt-PBE.git

AUTHOR

  • Giuseppe Di Terlizzi <gdt@cpan.org>

SEE ALSO

Crypt::PBE::PBKDF2
Crypt::PBE::PBES1
[RFC2898] PKCS #5: Password-Based Cryptography Specification Version 2.0 (https://tools.ietf.org/html/rfc2898)
[RFC8018] PKCS #5: Password-Based Cryptography Specification Version 2.1 (https://tools.ietf.org/html/rfc8018)

LICENSE AND COPYRIGHT

This software is copyright (c) 2020-2023 by Giuseppe Di Terlizzi.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.