views:

56

answers:

2

In the code

javax.crypto.KeyGenerator.getInstance("AES").generateKey();

What's the size of the generated key?

+2  A: 

I am not sure there is specification for the default size but the Sun JCE generates 16 bytes (128-bit) keys.

You can find out by checking the encoded size,

  int keyBits = (key.getEncoded()).length * 8;
ZZ Coder
Checked, its 128, thanks!
Tom Brito
A: 

Could you simply call the method getEncoded() on the returned key, then check the length?

Or, you could call the method init() on the KeyGenerator with parameters of either 128, 192, or 256 bits to be sure.

Or, you could compare the returned key from the no-length version of the call with ones where the length was explicitly set (using the init() method) and see which one matches.

shadit