Crypt-OpenSSL-AES

 view release on metacpan or  search on metacpan

t/03-large-data.t  view on Meta::CPAN

use strict;
use warnings;
use Test::More tests => 3;
use Digest::SHA qw(sha256 sha256_base64);
use Crypt::OpenSSL::Guess qw(openssl_version);

my ($major, $minor, $patch) = openssl_version();

BEGIN { use_ok('Crypt::OpenSSL::AES') };

{

SKIP: {
    skip "IVs unsupported - OpenSSL $major$minor", 2 if $major le '0.9' && $minor le '7';
    my $key = 'fe004cb16d14814b71e2c0e7c52f0c1d20fecdbca37bce926c6fc46de7f58ad5';
    my $iv = 'bb160a0e845bf36fe92310ba368c0d60';

    # Checksum calculated on Crypt::Mode::CBC ciphertext
    my $cbc_ciphertext_checksum = 'j2P40htNXAeq3qqORD4Ur/7q/a5iI0MqVatvXV3zwjs';
    my $data = do { local $/ = undef; <DATA> };
    my $checksum_orig = sha256_base64($data);

    my $coa = Crypt::OpenSSL::AES->new(pack("H*", $key),
                                    {
                                        cipher  => 'AES-256-CBC',
                                        iv      => pack("H*", $iv),
                                        padding => 1,
                                    });

    # Encrypt with Crypt::OpenSSL::AES
    my $ciphertext = $coa->encrypt($data);

    my $coa_ciphertext_checksum = sha256_base64($ciphertext);
    ok($coa_ciphertext_checksum eq $cbc_ciphertext_checksum, "Crypt::OpenSSL::AES - Created expected ciphertext");

    # Decrypt with Crypt::OpenSSL::AES
    my $plaintext = $coa->decrypt($ciphertext);

    # Verify Crypt::OpenSSL::AES and Decrypt its Encryption
    ok($checksum_orig eq sha256_base64($plaintext), "Crypt::OpenSSL::AES Encrypted and Decrypted Successfully");
}

}

done_testing;
__DATA__
This software is copyright (c) 2006 - 2023 by DelTel, Inc.

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

Terms of the Perl programming language system itself

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"

--- The GNU General Public License, Version 1, February 1989 ---

This software is Copyright (c) 2006 - 2023 by DelTel, Inc.

This is free software, licensed under:

  The GNU General Public License, Version 1, February 1989

                    GNU GENERAL PUBLIC LICENSE
                     Version 1, February 1989

 Copyright (C) 1989 Free Software Foundation, Inc.
 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

                            Preamble

  The license agreements of most software companies try to keep users
at the mercy of those companies.  By contrast, our General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users.  The
General Public License applies to the Free Software Foundation's
software and to any other program whose authors commit to using it.
You can use it for your programs, too.



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