Beispiel #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 = ['ecb', 'cbc', 'cfb'];
         $pads = [PhTCrypt::PADDING_ANSI_X_923, PhTCrypt::PADDING_PKCS7, PhTCrypt::PADDING_ISO_10126, PhTCrypt::PADDING_ISO_IEC_7816_4, PhTCrypt::PADDING_ZERO, PhTCrypt::PADDING_SPACE];
         for ($i = 1; $i < 128; ++$i) {
             $texts[] = str_repeat('A', $i);
         }
         $crypt = new PhTCrypt();
         $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);
                     $actual = $crypt->decrypt($encrypted);
                     expect($actual)->equals($text);
                 }
             }
         }
     });
 }
Beispiel #2
0
            $cache = new Phalcon\Cache\Backend\File($frontCache, ['cacheDir' => APP_URL . 'cache/model/']);
            break;
        case 'memcache':
            $cache = new Phalcon\Cache\Backend\Memcache($frontCache, ['host' => $config->memcache->host, 'port' => $config->memcache->port]);
            break;
    }
    return $cache;
};
$di['cache'] = function () use($di) {
    return $di->get('modelsCache');
};
/**
 * Access Control List
 */
$di['auth'] = function () {
    return new Auth();
};
/**
 * Init cookie
 */
$di->set('cookies', function () {
    $cookies = new Cookies();
    $cookies->useEncryption(true);
    return $cookies;
});
$di->set('crypt', function () {
    $crypt = new Crypt();
    $crypt->setMode(MCRYPT_MODE_CFB);
    $crypt->setKey('#1Pdj8$=dp?.ak#$');
    return $crypt;
});
 /**
  *  Initializes Crypt
  */
 public function initCrypt($options = [])
 {
     $config = $this->di['config'];
     $this->di->set('crypt', function () use($config) {
         $crypt = new PhCrypt();
         $crypt->setMode(MCRYPT_MODE_CFB);
         $crypt->setKey($config->app_crypt->encryptionkey);
         return $crypt;
     });
 }
Beispiel #4
0
 /**
  * Init crypt hash for cookie service.
  *
  * @param DI     $di     Dependency Injection.
  * @param Config $config Config object.
  *
  * @return void
  */
 public function _initCrypt($di, $config)
 {
     $di->set('crypt', function () use($config) {
         $crypt = new PhCrypt();
         $crypt->setMode(MCRYPT_MODE_CFB);
         $crypt->setKey($config->global->cookieEncryptionkey);
         return $crypt;
     });
 }
Beispiel #5
0
 public function setMode($mode)
 {
     return parent::setMode($mode);
 }