I recommend reading Section 9.7 of Cryptography Engineering [1] to understand why choosing random elements from a set is harder than it seems. A good example of a similar bug is the nasty bug in Cryptocat's PRNG from 2013 [2].
I assume this step was done so the AES key could be included in the URL fragment, since a set of random bytes may not be url safe. I recommend feeding the random bytes of the key directly into the underlying cryptographic functions, and using a urlsafe encoding at a higher level when necessary.
Also, it appears you are using AES [3], a block cipher, but I cannot figure out what block cipher mode you are using. I'll have to dig into the CryptoJS code a little more to see what it defaults to, but I have a sinking feeling that it's ECB, which is completely insecure. Dan Boneh's Crypto I course on Coursera is a good way to learn the basics of block cipher modes.
[0]: https://github.com/jes/hardbin/blob/c77c2d7eb93586e0e009ea4b... [1]: https://www.amazon.com/Cryptography-Engineering-Principles-P... [2]: https://nakedsecurity.sophos.com/2013/07/09/anatomy-of-a-pse... [3]: https://github.com/jes/hardbin/blob/c77c2d7eb93586e0e009ea4b...
Matthew Green's blog, A Few Thoughts on Cryptographic Engineering [1], has a wealth of interesting posts that are often aimed at explaining cryptography to a "technical but non-cryptographer" audience, and tend to be motivated by recent events in security/cryptography news.
[0]: https://www.amazon.com/Cryptography-Engineering-Principles-P... [1]: https://blog.cryptographyengineering.com/
http://www.amazon.com/Cryptography-Engineering-Principles-Pr...
Instead, he recommends Cryptography Engineering: http://www.amazon.com/Cryptography-Engineering-Principles-Pr...
Another way to get a primer on crypto is to do the Matasano crypto challenges: http://cryptopals.com/
The solutions aren't (yet?) published, but don't let that stop you. It will be fairly obvious when you've come up with a solution that solves the challenge. It's also an excellent way to get you really thinking about all of the problems with crypto. And it will hopefully scare you from ever implementing your own crypto scheme, which is always a good thing.
Make sure to do all the challenges though. They get exponentially more difficult, but the best ones are near the end.
The first thing I did after the Snowden leaks was read through the entire thing and after doing so I really wished I had done this years earlier. There's very few books that I think should be required reading across the board for software engineers, but this is one that I do think everyone writing code should read every page of.
[0] http://www.amazon.com/Cryptography-Engineering-Principles-Pr...
0: http://www.amazon.com/Cryptography-Engineering-Principles-Pr...
Jean-Philippe Aumasson's _Serious Cryptography_: https://nostarch.com/seriouscrypto
Ferguson and Schneier's _Cryptography Engineering_: https://www.amazon.com/Cryptography-Engineering-Principles-P... --- dated, a little wrong about some things, but not insane (like _Applied Cryptography_ is).
Hoffman, Pipher, and Silverman's _Introduction to Mathematical Cryptography_: https://www.amazon.com/Introduction-Mathematical-Cryptograph... --- a good first step into theoretical cryptography.