Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't get the same result for encryption with mcrypt and phpseclib
    primarykey
    data
    text
    <p>I had an implementation that encrypts an input string using mcrypt. Unfortunately I can't use this anymore because mcrypt isn't installed on the server and I can't install it. So I've had a look at phpseclib but unfortunately I don't get the same encrypted string. Here is my code:</p> <pre><code>include('Crypt/AES.php'); $key256 = "1234567890123456"; $iv = "6543210987654321"; $cleartext = "This a teststring :)"; echo $cleartext . "&lt;br /&gt;&lt;br /&gt;"; $cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, ''); if (mcrypt_generic_init($cipher, $key256, $iv) != -1) { // PHP pads with NULL bytes if $cleartext is not a multiple of the block size.. $cipherText = mcrypt_generic($cipher,$cleartext ); mcrypt_generic_deinit($cipher); } $enc64 = bin2hex($cipherText); echo $enc64 . "&lt;br /&gt;"; while (strlen($cleartext) % 16 != 0) { $cleartext .= "\0"; } $aes = new Crypt_AES(); $aes-&gt;setKey($key256); $aes-&gt;setIV($iv); $cipherText = $aes-&gt;encrypt($cleartext); $enc64 = bin2hex($cipherText); echo $enc64; </code></pre> <p>After running the script (on the development server that has mcrypt installed) I get the following output:</p> <blockquote> <p>This a teststring :)</p> <p>0fc60e5a06eca68d4aada496e0e83ea65806abfe7d8f72723da470e6c9e86372 0fc60e5a06eca68d4aada496e0e83ea65806abfe7d8f72723da470e6c9e8637231b74e99d9b729813e974f211550d175</p> </blockquote> <p>As you can see both encrypted strings are identical. Almost. The one that has been encrypted with phpseclib is one block too long and I have no idea why. I've already tried different key and block sizes. I've also tried to use the Crypt_Rijndael class of phpseclib. Hope one of you can point me in the right direction.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload