Welcome Guest, Not a member yet? Register   Sign In
Encryption library key - issues modifying config file

@Narf - Maybe you can help on this one?

I'm working on a script that runs after installation of my project via composer's post-create-project hook. In it, I'm pulling up the Encryption library and generating a new key, then modifying the config file to set the encryption key automatically. However, when I do this, I end up with gibberish in the config file's encryption key. This is based on the latest CI3 code.

The function in the install script is:

       public function generateEncryptionKey()
        $key = $this->ci->encryption->create_key(128);

        $kit = new FileKit();

        $kit->replaceIn(BUILDBASE .'../application/config/config.php', 'PLEASE_CHANGE_ME!', $key);

I'm using a 128-character key to mesh with the default AES128/CBC encryption. I believe this is the correct length, right?

Second, the method from FileKit that does the replacing is:

   public function replaceIn($file, $search, $replace)
       $file_contents = file_get_contents($file);

       if ($file_contents === false)
           throw new \RuntimeException( sprintf( lang('errors.reading_file'), $file ) );

       $file_contents = str_replace($search, $replace, $file_contents);

       $result = file_put_contents($file, $file_contents);

       return (bool)$result;

Anyone have any ideas what I'm missing?

It turns out that the Encryption library is returning a binary value instead of a string, since my system (OS X Yosemite running MAMP Pro) doesn't seem to have mcrypt installed and the openssl_random_pseudo_bytes is returning a binary value.

I've submitted an issue on GitHub so this can probably be resolved there.

Theme © iAndrew 2016 - Forum software by © MyBB