We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

\Phalcon\Crypt

There is already a discussion about this, but i want to open a new one, since i am on Ubuntu. Basicaly decrypt it is not working. Here is my example:

        $crypt = new \Phalcon\Crypt();
        $crypt->setKey('mykey');

        ld($crypt->getAvailableModes());
        ld($crypt->getAvailableCiphers());
        echo $crypt->encryptBase64("calin");
        echo "\n";
        echo $crypt->decryptBase64("calin");

Results:

array (8) 
 · [0]: string (3) "cbc"
 · [1]: string (3) "cfb"
 · [2]: string (3) "ctr"
 · [3]: string (3) "ecb"
 · [4]: string (4) "ncfb"
 · [5]: string (4) "nofb"
 · [6]: string (3) "ofb"
 · [7]: string (6) "stream"

/project/apps/Tasks/UserRegistrationTask.php:25

array (19) 
 · [0]: string (8) "cast-128"
 · [1]: string (4) "gost"
 · [2]: string (12) "rijndael-128"
 · [3]: string (7) "twofish"
 · [4]: string (7) "arcfour"
 · [5]: string (8) "cast-256"
 · [6]: string (6) "loki97"
 · [7]: string (12) "rijndael-192"
 · [8]: string (9) "saferplus"
 · [9]: string (4) "wake"
 · [10]: string (15) "blowfish-compat"
 · [11]: string (3) "des"
 · [12]: string (12) "rijndael-256"
 · [13]: string (7) "serpent"
 · [14]: string (4) "xtea"
 · [15]: string (8) "blowfish"
 · [16]: string (6) "enigma"
 · [17]: string (3) "rc2"
 · [18]: string (9) "tripledes"

/project/apps/Tasks/UserRegistrationTask.php:26

FyWhBJksVoR8VodnHWtXwofM1+P6UunFEOeKsbstNRMXkKOn+UlimzNT1IgKk+izUkPioncQPW619jTVz0YbZg==

Size of IV is larger than text to decrypt

If I use just encrypt() and decrypt() :

�<z����9����k
               2K����1��6����
                              BXѻN�c�7s��9��A�6a��<-c*�x

PHP Warning:  mcrypt_decrypt(): The IV parameter must be as long as the blocksize in /project/apps/Tasks/UserRegistrationTask.php on line 32
{9tc��o��v_uS���U��/<�Ƕ'V

This might be a bug in the end. Maybe @Phalcon can confirm ?



98.9k

Not sure if I understand it, this message is generated when corrupt data is passed to decrypt:

The IV parameter must be as long as the blocksize

https://github.com/phalcon/cphalcon/blob/2.0.0/phalcon/crypt.zep#L404



51.2k

Ok :). But how can my data (in the example above) can be corrupted ? The tests were made with:

        $crypt = new \Phalcon\Crypt();
        $crypt->setKey('mykey');

        ld($crypt->getAvailableModes());
        ld($crypt->getAvailableCiphers());
        echo $crypt->encryptBase64("calin");
        echo "\n";
        echo $crypt->decryptBase64("calin");

and

        $crypt = new \Phalcon\Crypt();
        $crypt->setKey('mykey');

        ld($crypt->getAvailableModes());
        ld($crypt->getAvailableCiphers());
        echo $crypt->encrypt("calin");
        echo "\n";
        echo $crypt->decrypt("calin");

PHP 5.5.9 (CLI mode) + Phalcon 1.3.2



3.2k
Accepted
answer

Could it be that you are trying to decrypt the string calin which is not encrypted?



51.2k

Ha ha ha ! Shame on me ! Yes max. You are right.