Student
Student

Reputation: 28375

What's the default size of AES generated keys?

In the code

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

What's the size of the generated key?

Upvotes: 3

Views: 1365

Answers (2)

shadit
shadit

Reputation: 2576

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.

Upvotes: 0

ZZ Coder
ZZ Coder

Reputation: 75496

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;

Upvotes: 6

Related Questions