Is it possible to pack 128- or 256-bit numbers (AES keys/ivs generated with Crypt::Random::makerandom) using the perl built-in pack? If yes, what should my template X in
pack('X', ($256_bit_number));
be?
Thank you.
Perl can't hold numbers that large, so it can't possibly pack them.
So let's look at what makerandom
actually returns.
$ perl -MData::Dumper -MCrypt::Random=makerandom \
-e'print(Dumper(makerandom(Size => 256, Strength => 1)));'
$VAR1 = bless( do{\(my $o = 148076988)}, 'Math::Pari' );
Ah, a Math::Pari object. Looking at the docs, there doesn't appear to be a straightforward means of pack those. But it looks like we don't have to. Crypt::Random provides makerandom_octet
that returns the "packed" number.
$ perl -MCrypt::Random=makerandom_octet \
-e'print(unpack("H*", makerandom_octet(Size => 256, Strength => 1)));'
1432698ef28c63d9cb0bba474c1644b4a6f9736616bd070102a612785332e94bb4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With