I need to generate a key to use when encrypting a file symmetrically using AES256/CBC
The key itself will be encrypted with RSA public/private so I don't need a password applied.
In Java, this seems to be done as follows:
SecureRandom random = new SecureRandom();
byte[] keyBytes = new byte[32]; //32 Bytes = 256 Bits
random.nextBytes(keyBytes);
SecretKeySpec key = new SecretKeySpec(keyBytes, "AES");
However, SecretKeySpec
isn't defined in the C# BouncyCastle library available via NuGet.
What's the C# equivalent? Since I'm not using a password, is it sufficient to just grab the next n random bytes from SecureRandom
(which does exist)?