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
 public function setCipher($cipher)
 {
     return parent::setCipher($cipher);
 }
Beispiel #3
0
     return $connection;
 };
 // Set the Logger Handler
 $di['logger'] = function () {
     return new FileLogger('../logs/debug.log');
 };
 //Register Volt as a service
 $di->set('voltService', function ($view, $di) {
     $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
     $volt->setOptions(array("compiledPath" => COMPILED_VIEW_PATH, "compiledExtension" => ".php"));
     return $volt;
 });
 $di->set('crypt', function () {
     $crypt = new Crypt();
     // 使用 blowfish
     $crypt->setCipher('blowfish');
     // 设置全局加密密钥
     $crypt->setKey('blowfish');
     return $crypt;
 }, true);
 // Setting up the view component
 $di['view'] = function () {
     $view = new View();
     $view->setViewsDir('../app/views/');
     $view->disableLevel(array(View::LEVEL_LAYOUT => true, View::LEVEL_MAIN_LAYOUT => true));
     $view->registerEngines(array(".phtml" => 'voltService', ".volt" => 'voltService', ".json" => 'voltService'));
     return $view;
 };
 // Setup a base URI so that all generated URIs include the "tutorial" folder
 $di['url'] = function () {
     $url = new Url();