Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: same encrypt word ?

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


in reply to same encrypt word ?

Hi and welcome to the monastery

It seems that the algorithm includes a random salt so that every run produces a different result. Is that what you're seeing? Does the Php version return the same result every time? Could you maybe give example input and output you're using?

Replies are listed 'Best First'.
Re^2: same encrypt word ?
by docofchaos (Novice) on Oct 30, 2014 at 11:05 UTC
    hi, yes i can make an example of result

    with the php function :
    key : test-math
    encrypted text :
    c2dbe4b6fec504f3249e2866dacc2a000964136de054865d407321433c001f98
    decrypted text: test-math

    and it's the same result every time, i don't give another argument on the php function.
    I can decrypt the text with all online tool, if i choose the RIJNDAEL_256 and ECB mode.
    I have no idea to have the same result with perl function

      Okay, this algorithm requires both the key and the data to be in blocks of 16. So you may be running into differences in the way they're being automatically padded for you.

      If you set both the plain text and the key to "1234567890123456", you'll see it's encrypted as: "757ccd0cdc5c90eadbeeecf638dd0000". You can verify this yourself by using this online tool.

      use Crypt::Rijndael; my $plaintext = my $key = '1234567890123456'; my $cipher = Crypt::Rijndael->new( $key, Crypt::Rijndael::MODE_ECB ); my $encrypted = $cipher->encrypt($plaintext); printf "%02x", ord $_ for split //, $encrypted;
      Prints: 757ccd0cdc5c90eadbeeecf638dd0000. So hopefully that's what you're getting with your PHP as well.

      Update: Ah, I see that all the above was done using 128-bit ECB, and you're using 256-bit.. hmmm.

      By the way, Crypt::Rijndael says in no uncertain terms that ECB should be avoided

        hi ty for the answer, but i used rijndael_256, anf i can't decryp the text with http://rijndael.online-domain-tools.com/ i'll try to format my key to be in 16 blocksize.
        print "\n---- Test6 -------- \n"; my $key_6 = 'test-math'; $key_6 .= "\0" x (16 - length($key_6)); my $plaintext_6 = 'test-math'; my $cipher_6 = Crypt::Rijndael->new( $key_6, Crypt::Rijndael:: +MODE_ECB ); my $encrypted_6 = $cipher_6->encrypt($plaintext_6); printf "%02x", ord $_ for split //, $encrypted_6; print "---- Fin test 6 ---\n";
        i have an error like 'datasize not multiple of blocksize (16 bytes)' i'll find a way to use your code and adapt your code
        thanks to your answer and i hope it work :)

Log In?
Username:
Password:

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

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

    No recent polls found