public static function _init() { static::$crypter = new Crypt_AES(); static::$hasher = new Crypt_Hash('sha256'); // load the config \Config::load('crypt', true); static::$config = \Config::get('crypt', array()); // generate random crypto keys if we don't have them or they are incorrect length $update = false; foreach (array('crypto_key', 'crypto_iv', 'crypto_hmac') as $key) { if (empty(static::$config[$key]) or strlen(static::$config[$key]) % 4 != 0) { $crypto = ''; for ($i = 0; $i < 8; $i++) { $crypto .= static::safe_b64encode(pack('n', mt_rand(0, 0xffff))); } static::$config[$key] = $crypto; $update = true; } } // update the config if needed if ($update === true) { // load the file config \Config::load('file', true); try { \Config::save('crypt', static::$config); chmod(APPPATH . 'config' . DS . 'crypt.php', \Config::get('file.chmod.files', 0666)); } catch (\FileAccessException $e) { // failed to write the config file, inform the user echo \View::forge('errors/crypt_keys', array('keys' => static::$config)); die; } } static::$crypter->enableContinuousBuffer(); static::$hasher->setKey(static::safe_b64decode(static::$config['crypto_hmac'])); }
public static function _init() { static::$crypter = new Crypt_AES(); static::$hasher = new Crypt_Hash('sha256'); // load the config \Config::load('crypt', true); static::$config = \Config::get('crypt', array()); // generate random crypto keys if we don't have them or they are incorrect length $update = false; foreach (array('crypto_key', 'crypto_iv', 'crypto_hmac') as $key) { if (empty(static::$config[$key]) || strlen(static::$config[$key]) % 4 != 0) { $crypto = ''; for ($i = 0; $i < 8; $i++) { $crypto .= static::safe_b64encode(pack('n', mt_rand(0, 0xffff))); } static::$config[$key] = $crypto; $update = true; } } // update the config if needed if ($update === true) { try { \Config::save('crypt', static::$config); } catch (\File_Exception $e) { throw new \Exception('Crypt keys are invalid or missing, and app/config/crypt.php could not be written.'); } } static::$crypter->enableContinuousBuffer(); static::$hasher->setKey(static::safe_b64decode(static::$config['crypto_hmac'])); }
/** * Magic method called when a class is first encountered by the Autoloader, * providing static initialization. * * @return void No value is returned */ public static function __initialize() { if ((static::$key = Config::get('crypt.key')) == '') { throw new \Exception('The Crypt class cannot be used without providing a shared key. Please specify on in your crypt configuration file'); } static::$defaultDriver = Config::get('crypt.driver', 'xcrypt'); static::$hasher = Config::get('crypt.hasher', 'sha1'); static::$key = md5(static::$key); }
public function __construct(array $attributes = array()) { // define dependencies // this is for when we are calling the model directly // these are usually defined by the IoC however as we are effectively breaking this to provide a consistent API // so we need to redefine them in the constructor // probably not the best approach... static::$hasher = \App::make('sentry.hasher'); static::$loginAttribute = \Config::get('cartalyst/sentry::users.login_attribute'); parent::__construct($attributes); }
/** * Set the hasher with which to hash passwords. * * @param Hasher $hasher */ public static function setHasher(Hasher $hasher) { static::$hasher = $hasher; }
/** * Unset the hasher used by the user. * * @return void */ public static function unsetHasher() { static::$hasher = null; }
/** * Sets a hasher strategy * * @param Xaamin\Hashing\Contracts\HasherInterface $hasher */ public static function setHasher(HashInterface $hasher) { static::$hasher = $hasher; }
/** * Use crypt_hash hash type * * @static * @access protected * @param string $string String to be hashed * @return string */ protected static function crypt_hash($string = '') { if (!class_exists('PHPSecLib\\Crypt_Hash', false)) { import('phpseclib/Crypt/Hash', 'vendor'); } null === static::$hasher and static::$hasher = new \PHPSecLib\Crypt_Hash(); $salt = Config::get('autho.salt', Config::get('crypt.crypto_key')); return base64_encode(static::$hasher->pbkdf2($string, $salt, 10000, 32)); }