Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: same encrypt word ?

by Loops (Curate)
on Oct 30, 2014 at 14:29 UTC ( [id://1105632]=note: print w/replies, xml ) Need Help??


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 :)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2024-04-25 11:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found