Crypt-PBC

 view release on metacpan or  search on metacpan

lib/Crypt/PBC.pod  view on Meta::CPAN

    # Please check the PBC docs ...
    Crypt::PBC::element_fprintf(\*OUTFILE, $format, $element);
    Crypt::PBC::element_fprintf(\*STDOUT, "example element=\%B\n", $element);
    # (You may be surprised how many bigints are in these group elements.)

    my $spewed_result = Crypt::PBC::export_element($element);
    # These are bytes, dumped from the $element, that can be used to
    # reconstruct the element or used for interacting with real life data.

    # Example:
    my $cipher = new Crypt::CBC({
        header => "randomiv", 
        key    => Crypt::PBC::export_element($element), 
        cipher => 'Blowfish', # hehe
    });

    my $big = Crypt::PBC::element_to_mpz( $element );
    # Returns a Math::BigInt::GMP, not a Math::BigInt!  WARNING: the
    # DESTROY() method from Math::BigInt::GMP will be missing unless you
    # require that package into your program.  You'll want to do that or you'll
    # have a memory leak...  Lastly, this is really only useful for elements in

lib/Crypt/PBC/Element.pod  view on Meta::CPAN

    # You may be surprised to see that a G1 Element is in fact two MPZs.

    $element->errdump; # dumps the element on STDERR instead of STDOUT

The following will be of major importance to anyone looking to use Crypt::PBC
for real-life applications.  C<as_bytes()> almost certainly has to be used in
conjunction with some other algorithm, but that is indeed what it is for.

    my $secret_key_bin = $element->as_bytes;

    my $example_cipher = new Crypt::CBC({
        header => "randomiv", 
        cipher => 'Blowfish'
        key    => $secret_key_bin,
    });

    my $secret = $example_cipher->encrypt("you can't read this!!");

There are, of course, other ways to export the bytes.  The bigint exporter
probably only works on Zr elements, but it probalby has uses.

t/07_BF2.t  view on Meta::CPAN

# vi:fdm=marker fdl=0 syntax=perl:

use strict;
use Test;

if( defined $ENV{SKIP_ALL_BUT} ) { unless( $0 =~ m/\Q$ENV{SKIP_ALL_BUT}\E/ ) { plan tests => 1; skip(1); exit 0; } }

my $bf = 0;
my $sh = 0;
eval q{
    use Crypt::CBC;
    use Crypt::Blowfish;

    $bf = 1;
};

eval q{
    use Digest::SHA1 qw(sha1);

    $sh = 1;
};

t/07_BF2.t  view on Meta::CPAN

my $w_from_U = $curve->init_GT->e_hat( $d_id, $U );

ok( $w_from_U->is_eq( $w ) );
ok( $w_from_U->as_bytes, $w->as_bytes ); # binary good
ok( $w_from_U->as_str,   $w->as_str   ); # hexidecimal

if( $bf ) {
    # If the three comparisons above worked, this is kindof a no-brainer; but,
    # personally, I was confused on how to M^H2(g^r) -- and here it is:

    my $cipher1 = new Crypt::CBC({header=>"randomiv", key=>$w->as_bytes,        cipher=>'Blowfish'});
    my $cipher2 = new Crypt::CBC({header=>"randomiv", key=>$w_from_U->as_bytes, cipher=>'Blowfish'});
    my $message = "Holy smokes, this is secret!!";
    my $encrypt = $cipher1->encrypt($message);
    my $decrypt = $cipher2->decrypt($encrypt);

    warn " using Crypt::CBC(Crypt::Blowfish) for 4th test\n" if $ENV{EXTRA_INFO};
    ok( $decrypt, $message );
}



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