Stores the keys array in the keystore file

@return void
@throws SecurityException
198195
public function shutdownObject()
    {
        if ($this->saveKeysOnShutdown === false) {
            return;
        }

        $temporaryKeystorePathAndFilename = $this->keystorePathAndFilename . Utility\Algorithms::generateRandomString(13) . '.temp';
        $result = file_put_contents($temporaryKeystorePathAndFilename, serialize($this->keys));

        if ($result === false) {
            throw new SecurityException('The temporary keystore file "' . $temporaryKeystorePathAndFilename . '" could not be written.', 1305812921);
        }
        $i = 0;
        while (($result = rename($temporaryKeystorePathAndFilename, $this->keystorePathAndFilename)) === false && $i < 5) {
            $i++;
        }
        if ($result === false) {
            throw new SecurityException('The keystore file "' . $this->keystorePathAndFilename . '" could not be written.', 1305812938);
        }
    }
1086171
protected function _setKeys($keys)
    {
        if (!is_array($keys)) {
            throw new Exception\InvalidArgumentException('Invalid options argument provided to filter');
        }

        foreach ($keys as $type => $key) {
            if (is_file($key) and is_readable($key)) {
                $file = fopen($key, 'r');
                $cert = fread($file, 8192);
                fclose($file);
            } else {
                $cert = $key;
                $key  = count($this->keys[$type]);
            }

            switch ($type) {
                case 'public':
                    $test = openssl_pkey_get_public($cert);
                    if ($test === false) {
                        throw new Exception\InvalidArgumentException("Public key '{$cert}' not valid");
                    }

                    openssl_free_key($test);
                    $this->keys['public'][$key] = $cert;
                    break;
                case 'private':
                    $test = openssl_pkey_get_private($cert, $this->passphrase);
                    if ($test === false) {
                        throw new Exception\InvalidArgumentException("Private key '{$cert}' not valid");
                    }

                    openssl_free_key($test);
                    $this->keys['private'][$key] = $cert;
                    break;
                case 'envelope':
                    $this->keys['envelope'][$key] = $cert;
                    break;
                default:
                    break;
            }
        }

        return $this;
    }
586530
public function store()
    {
        $user    = null;
        $message = '';
        $success = false;

        try{
            $input = Input::post();

            if($input['password'] != $input['confirm_password']){
                throw new Exception("Password and confirmation password not match", 1);
            }

            $user = Sentry::createUser(array(
                'email'       => $input['email'],
                'password'    => $input['password'],
                'first_name'  => $input['first_name'],
                'last_name'   => $input['last_name'],
                'activated'   => 1
            ));

            $success = true;
            $message = 'User created successfully';
        }catch (Exception $e){
            $message = $e->getMessage();
        }

        if(Request::isAjax()){
            Response::headers()->set('Content-Type', 'application/json');
            Response::setBody(json_encode(
                array(
                    'success'   => $success,
                    'data'      => ($user) ? $user->toArray() : $user,
                    'message'   => $message,
                    'code'      => $success ? 200 : 500
                )
            ));
        }else{
            Response::redirect($this->siteUrl('admin/user'));
        }
    }
239680
public function initializeObject()
    {
        if (file_exists($this->keystorePathAndFilename)) {
            $this->keys = unserialize(file_get_contents($this->keystorePathAndFilename));
        }
        $this->saveKeysOnShutdown = false;
    }
330474
protected static function flush_store() {
        $ids = array_keys(self::$sessionstore);
        unset(self::$sessionstore);
        self::$sessionstore = array();
        foreach ($ids as $id) {
            self::$sessionstore[$id] = array();
        }
    }
199170
public function generateKeyFile()
    {
        $this->output->outputLine();

        if ( file_exists($this->createFilePath([$this->localBackupTarget, 'key'])) ) {
            $this->output->outputLine('<b>You have already a keyfile!</b>');
            $this->output->outputLine('If you generate a new one, all existing Backups are worthless.');
            $this->output->outputLine();
            $this->output->outputLine('Call \'./flow backup:clear --force\' to delete all Backups and the Keyfile.');
            $this->output->outputLine();
            return;
        }

        $this->output->outputLine('<b>Generate a new Crypto Key</b>');
        $this->output->outputLine();

        $this->files->createDirectoryRecursively($this->localBackupTarget);

        try {
            $key = \Crypto::createNewRandomKey();
            file_put_contents($this->createFilePath([$this->localBackupTarget, 'key']), $key);
            // WARNING: Do NOT encode $key with bin2hex() or base64_encode(),
            // they may leak the key to the attacker through side channels.
        } catch (Ex\CryptoTestFailedException $ex) {
            die('Cannot safely create a key');
        } catch (Ex\CannotPerformOperationException $ex) {
            die('Cannot safely create a key');
        }

        $this->output->outputLine('done');
        $this->output->outputLine();

    }
77242
public function clear()
    {
        foreach ($this->keys() as $key) {
            unset($this->_store[$key]);
        }
        $frozenKeys = \array_keys($this->_frozen);
        foreach ($frozenKeys as $key) {
            unset($this->_frozen[$key]);
        }
    }
1238343
@Override
    protected void store(ConfidentialKey key, byte[] payload) throws IOException {
        try {
            Cipher sym = Secret.getCipher("AES");
            sym.init(Cipher.ENCRYPT_MODE, masterKey);
            try (OutputStream fos = Files.newOutputStream(getFileFor(key).toPath());
                 CipherOutputStream cos = new CipherOutputStream(fos, sym)) {
                cos.write(payload);
                cos.write(MAGIC);
            }
        } catch (GeneralSecurityException e) {
            throw new IOException("Failed to persist the key: "+key.getId(),e);
        } catch (InvalidPathException e) {
            throw new IOException(e);
        }
    }
401214
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)
		{
			try
			{
				\Config::save('crypt', static::$config);
			}
			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']));
	}
507706
private function prepare_signing_key() {
    $this->signing_key = $this->safe_encode($this->config['consumer_secret']) . '&' . $this->safe_encode($this->config['user_secret']);
  }
390610
public function store($key, $value)
    {
        $this->load();

        $this->config[$key] = $value;
        return true;
    }
392542
public function storeKey($name, $password)
    {
        if (strlen($name) === 0) {
            throw new SecurityException('Required name argument was empty', 1334215443);
        }
        if (strlen($password) === 0) {
            throw new SecurityException('Required password argument was empty', 1334215349);
        }
        $this->persistKey($name, $password);
    }
1360258
public function init() {
        //If available load the config from the security file, else create a new array
        if ($this->securityFile) {
            if (!$this->loadSecurityConfiguration()) {
                $this->config = array();
            }
        } else {
            $this->config = array();
        }
        //Set ready to true
        $this->ready = true;
    }
557484
function secured()
    {
        return collect($this->files->scandir($this->certificatesPath()))
                    ->map(function ($file) {
                        return str_replace(['.key', '.csr', '.crt', '.conf'], '', $file);
                    })->unique()->values()->all();
    }
459032
public static void saveKeyStore(File targetStoreFile, KeyStore store, String password) {
        File folder = targetStoreFile.getAbsoluteFile().getParentFile();
        if (!folder.exists()) {
            folder.mkdirs();
        }
        File tmpFile = new File(folder, Long.toHexString(System.currentTimeMillis()) + ".tmp");
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(tmpFile);
            store.store(fos, password.toCharArray());
            fos.flush();
            fos.close();
            if (targetStoreFile.exists()) {
                targetStoreFile.delete();
            }
            tmpFile.renameTo(targetStoreFile);
        } catch (IOException e) {
            String message = e.getMessage().toLowerCase();
            if (message.contains("illegal key size")) {
                throw new RuntimeException("Illegal Key Size! You might consider installing the JCE Unlimited Strength Jurisdiction Policy files for your JVM.");
            } else {
                throw new RuntimeException("Could not save keystore " + targetStoreFile, e);
            }
        } catch (Exception e) {
            throw new RuntimeException("Could not save keystore " + targetStoreFile, e);
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                }
            }

            if (tmpFile.exists()) {
                tmpFile.delete();
            }
        }
    }
415237
protected function store_supports_key_awareness() {
        if ($this->supportskeyawareness === null) {
            $this->supportskeyawareness = ($this->store instanceof cache_is_key_aware);
        }
        return $this->supportskeyawareness;
    }
1187100
private function initialize()
    {
        // generate key pair.
        $this->privateKey = $this->generator->createPrivateKey();
        $this->publicKey = $this->privateKey->getPublicKey();

        // generate salt
        $this->salt = openssl_random_pseudo_bytes(16);

        $this->publicKeyContent = hex2bin($this->serializer->serialize($this->publicKey->getPoint()));
    }