Hello, does anybody know why below 2 echoes are providing diferent results

<?php
   $in ='textInputTest'; $key ='AAAABBBBAAAABBBB'; $iv ='AAAABBBB';
   echo base64_encode(mcrypt_encrypt(MCRYPT_RC2, $key, $in, MCRYPT_MODE_CBC, $iv)) .":";
   echo base64_encode(openssl_encrypt($in, 'rc2-cbc', $key, true, $iv));
?>

(results: I6twEgBKQEaNzeP0nMeLJg== : 7bJWXaOJf31WYcJn2UcDrg==)
...
second result is the same that C# and some other tools provides. So OpenSSL conform my needs... But I still want to know why MCRYPT result is different because the same encryption mode, cypher, key and init-vector used...

I'm not sure, but I think the key must be binary.

Well, 16 plain ascii characters inside $key string should be exactly 128bits binary, and initialisation vector $iv 8asciichars =8bytes =64bit for rc2. Comparing to other php examples about encrypting, this is ok. Intention was rc2-128bit-cbc.

- Openssl library for php behaves exactly as supossed (compared to other languages tests) ... but sometimes there will be situation on some server where openssl is disabled... and i am wondering if MCRYPT functions are also good or unreliable.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.