Ejemplo n.º 1
0
 public function testPadding()
 {
     $texts = array();
     $key = '0123456789ABCDEF0123456789ABCDEF';
     $modes = array('ecb', 'cbc', 'cfb');
     $pads = array(\Phalcon\Crypt::PADDING_ANSI_X_923, \Phalcon\Crypt::PADDING_PKCS7, \Phalcon\Crypt::PADDING_ISO_10126, \Phalcon\Crypt::PADDING_ISO_IEC_7816_4, \Phalcon\Crypt::PADDING_ZERO, \Phalcon\Crypt::PADDING_SPACE);
     for ($i = 1; $i < 128; ++$i) {
         $texts[] = str_repeat('A', $i);
     }
     $crypt = new \Phalcon\Crypt();
     $crypt->setCipher(MCRYPT_RIJNDAEL_256)->setKey($key);
     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);
                 $this->assertEquals($text, $actual);
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Return decrypt password
  *
  * @return string
  */
 public function getDecryptValue()
 {
     //Create an instance
     $crypt = new \Phalcon\Crypt();
     $crypt->setCipher($this->_cryptType);
     $key = \Engine\Tools\String::generateStringTemplate($this->_keyTemplate, $this->_form->getData(), '{', '}');
     $value = $this->_value;
     return $crypt->decryptBase64($value, $key);
 }
Ejemplo n.º 3
0
});
/**
 * Database connection is created based in the parameters defined in the configuration file
 */
$di->set('db', function () use($config) {
    return new DbAdapter($config->database->toArray());
});
/**
 * If the configuration specify the use of metadata adapter use it or use memory otherwise
 */
$di->set('modelsMetadata', function () {
    return new MetaDataAdapter();
});
$di->set('crypt', function () {
    $crypt = new \Phalcon\Crypt();
    $crypt->setCipher('blowfish');
    $crypt->setKey('vmS"TG<');
    return $crypt;
}, true);
/**
 * Start the session the first time some component request the session service
 */
$di->setShared('session', function () {
    $session = new SessionAdapter();
    $session->start();
    return $session;
});
$di->set('cookie', function () {
    $cookies = new Cookies();
    $cookies->useEncryption(true);
    return $cookies;
Ejemplo n.º 4
0
 public function testYamlConfigCallback()
 {
     $config = new Phalcon\Config\Adapter\Yaml('unit-tests/config/config.yml', array('!decrypt' => function ($value) {
         $crypt = new Phalcon\Crypt();
         return $crypt->setCipher('blowfish')->decryptBase64($value, CONFKEY);
     }, '!approot' => function ($value) {
         return APPROOT . $value;
     }));
     $this->assertTrue($this->_compareConfig($this->_config, $config));
 }
Ejemplo n.º 5
0
<?php

//Create an instance
$encryption = new Phalcon\Crypt();
//Use blowfish
$encryption->setCipher('blowfish');
$key = 'le password';
$text = 'This is a secret text';
echo $encryption->encrypt($text, $key);