Added Security::generateRandomHexKey(), used it for various tokens and default key generation

Fixes #4114.

Needs review.
Agree. That's better.

On Sunday, June 29, 2014, Carsten Brandt <notifications@github.com> wrote:

> In framework/base/Security.php:
>
> > @@ -325,6 +325,20 @@ public function generateRandomKey($length = 32)
> >      }
> >
> >      /**
> > +     * Generates a random string key.
> > +     *
> > +     * Note that length is in bytes of binary data, not in characters.
> > +     *
> > +     * @param integer $byteLength  the length of the key in bytes that should be generated
> > +     * @throws Exception Exception on failure.
> > +     * @return string the generated random key
> > +     */
> > +    public function generateRandomHexKey($byteLength = 32)
> > +    {
> > +        return bin2hex($this->generateRandomKey($byteLength));
>
> We might consider using http://php.net/manual/en/function.base-convert.php
> to get a shorter string using more characters to represent the value.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/yiisoft/yii2/pull/4115/files#r14332157>.
>