Exemplo n.º 1
0
 /**
  * Encrypts a text
  *
  *<code>
  *    $encrypted = $crypt->encrypt("Ultra-secret text", "encrypt password");
  *</code>
  *
  * @param string $text
  * @param string $key
  * @return string
  */
 public function encrypt($text, $key = null)
 {
     if ($key != null) {
         return base64_encode(parent::encrypt($text, $key));
     }
     return base64_encode(parent::encrypt($text, $this->encryptKey));
 }
Exemplo n.º 2
0
 /**
  * Constructor
  *
  * @param \Modules\User\Models\Users $user
  * @return string Access token
  */
 public static function createToken(\Modules\User\Models\Users $user)
 {
     $crypt = new Crypt();
     $di = DI::getDefault();
     $token = array();
     $token['uid'] = $user->uid;
     $token['username'] = $user->username;
     $token['address'] = $_SERVER['REMOTE_ADDR'];
     $token['agent'] = $_SERVER['HTTP_USER_AGENT'];
     $token['expiry'] = time() + $di->get('config')->app->tokenTimelife;
     $token = implode('|', $token);
     return bin2hex($crypt->encrypt($token, $di->get('config')->app->crypkey));
 }
Exemplo n.º 3
0
 public function encrypt($text, $key = null)
 {
     return parent::encrypt($text, $key);
 }
Exemplo n.º 4
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);
                 }
             }
         }
     });
 }