Phalcon\Legacy\Crypt::setMode PHP Method

setMode() public method

Sets the encrypt/decrypt mode
public setMode ( string $mode ) : Phalcon\Legacy\CryptInterface
$mode string
return Phalcon\Legacy\CryptInterface
    public function setMode($mode)
    {
        $this->mode = $mode;
        return $this;
    }

Usage Example

Example #1
0
 /**
  * Tests the padding
  *
  * @author Nikolaos Dimopoulos <*****@*****.**>
  * @since  2014-10-17
  */
 public function testCryptPadding()
 {
     $this->specify("padding not return correct results", function () {
         $texts = [''];
         $key = '0123456789ABCDEF0123456789ABCDEF';
         $modes = [MCRYPT_MODE_ECB, MCRYPT_MODE_CBC, MCRYPT_MODE_CFB];
         $pads = [Crypt::PADDING_ANSI_X_923, Crypt::PADDING_PKCS7];
         for ($i = 1; $i < 128; ++$i) {
             $texts[] = str_repeat('A', $i);
         }
         $crypt = new Crypt();
         $crypt->setCipher(MCRYPT_RIJNDAEL_256)->setKey(substr($key, 0, 16));
         foreach ($pads as $padding) {
             $crypt->setPadding($padding);
             foreach ($modes as $mode) {
                 $crypt->setMode($mode);
                 foreach ($texts as $text) {
                     $encrypted = $crypt->encrypt($text);
                     expect($crypt->decrypt($encrypted))->equals($text);
                 }
             }
         }
     });
 }