in reply to same encrypt word ?

Okay, had zero luck making Crypt::MCrypt behave, and could not convince Crypt::Rijndael to do anything but RIJNDAEL-128. But after much casting about, success with Mcrypt:

use Mcrypt; my $key = 'test-math' . "\0" x 7; # Must be in blocks of 16, nul +l padded my $plaintext = "test-math" . "\0" x 23; # Must be in blocks of 32, n +ull padded my $td = Mcrypt->new( algorithm => 'rijndael-256', mode => 'ecb' ); $td->init($key, ' 'x32); # Second parameter is discarded, but warns +without my $encrypted = $td->encrypt($plaintext); print unpack('H*', $encrypted), $/; $td->end();

It prints the glorious output that matches what you're getting in PHP:

c2dbe4b6fec504f3249e2866dacc2a000964136de054865d407321433c001f98

Replies are listed 'Best First'.
Re^2: same encrypt word ?
by docofchaos (Novice) on Oct 30, 2014 at 15:24 UTC
    hi it works fine !!
    I am make a little adaptation of your code to use with variable
    sub chiffrer_string { my ($a_chiffrer,$cle) = @_; my $key = $cle; $key .= "\0" x (16 - length($key)); my $plain_text = $a_chiffrer; $plain_text .= "\0" x (32 - length($a_chiffrer)); my $cipher = Mcrypt->new( algorithm => 'rijndael-256', mode => + 'ecb' ); $cipher->init($key, ' 'x32); my $encrypted = $cipher->encrypt($plain_text); print unpack('H*', $encrypted), $/; $cipher->end(); }
    Very thank for your help :)