Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

perl aes-256-cbc

by perlmdl (Initiate)
on May 14, 2020 at 11:56 UTC ( [id://11116783]=perlquestion: print w/replies, xml ) Need Help??

perlmdl has asked for the wisdom of the Perl Monks concerning the following question:

Hello All,

So here is the challenge, i have to integrate with a partner who has shared the working example on: http://aes.online-domain-tools.com/

Input text - set as HEX:

3132333435363738393031323334353632373832343634303031305468697320697320612074657374206D657373616765FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

Function: AES

Mode: CBC

Key set as HEX: 01F0E0D0C0B0A090807060504030201001F0E0D0C0B0A0908070605040302010

IV: 8006e3b6dbdb4865e079d0543c6007bc

Certain values changed for obvious reasons.

Challenge :

my $cipher = Crypt::CBC->new( -cipher => 'Crypt::Cipher::AES', -key => $key, -iv => $iv, -padding => 'none', -header => 'none', -keylength => '256' , -literal_key => 1 );

This is naturally failing due to IV size (not sure if it is related to hex values, etc. Any insight as to how to solve?

Thanks

Replies are listed 'Best First'.
Re: perl aes-256-cbc
by haukex (Archbishop) on May 14, 2020 at 12:27 UTC

    Works for me...

    use warnings; use strict; use Test::More tests=>2; use Crypt::CBC; my $cipher = Crypt::CBC->new( -cipher => 'Crypt::Cipher::AES', -key => pack('H*','01F0E0D0C0B0A090807060504030201001F0E0D +0C0B0A0908070605040302010'), -iv => pack('H*','8006e3b6dbdb4865e079d0543c6007bc'), -padding => 'none', -header => 'none', -keylength => '256' , -literal_key => 1 ); # Test cases from http://aes.online-domain-tools.com/ is $cipher->encrypt(pack('H*','313233343536373839303132333435363237383 +2343634303031305468697320697320612074657374206D657373616765FFFFFFFFFF +FFFFFFFFFFFFFFFFFFFF')), pack('H*','d899b35ce2b37036de3885227d8ca6b8ecc82c3f21ae89123b6d149 +67301b3bf08596e32df12de93621f15f90e6ea4b969a752c3f50fb771b8821eb0e606 +cf6c'); is $cipher->decrypt(pack('H*','313233343536373839303132333435363237383 +2343634303031305468697320697320612074657374206D657373616765FFFFFFFFFF +FFFFFFFFFFFFFFFFFFFF')), pack('H*','d97548a7925ff9d1f3a5fd4dac00c120a3faa51c931c203ec8cbad0 +25e3574299d1043fb51865a47469100a15e96203621396b7ec86d8202869b4fb1039f +aa8e');
      Thank you sir! i wasn't packing the Hex values, my stupidity NOOB

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11116783]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (7)
As of 2024-03-28 18:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found