Generate Random AES Encryption Key

I was looking for a way to quickly generate a random AES key online, but couldn't find anything. I looked into a couple methods using JavaScript, but determined that a C# solution would be better.

I needed to base64 encode the key array to store that value in a config file.

Here's the code I ended up with:
https://gist.github.com/aaronhoffman/09b56f77a95205fe10365bde2f4a02e5


UPDATE

Using Visual Studio's "C# Interactive" screen you can generate a key in a single line:

var keyArray = new byte[32]; (new System.Security.Cryptography.RNGCryptoServiceProvider()).GetBytes(keyArray); Convert.ToBase64String(keyArray)





Hope this helps!
-Aaron



Comments

Popular posts from this blog

Configure SonarAnalyzer.CSharp with .editorconfig, no need for SonarCloud or SonarQube

Search iPhone Text Messages with SQLite SQL Query

Pixel Grid Images 8x8 pixel grid on 256 pixel image