/** * 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)); }
/** * 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)); }
public function encrypt($text, $key = null) { return parent::encrypt($text, $key); }
/** * 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); } } } }); }