What is the default size for AES keys?

In code

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

      

What is the size of the generated key?

+2


a source to share


2 answers


I'm not sure if there is a default size specification, but Sun JCE generates 16-byte (128-bit) keys.

You can find out by checking the encoded size,



  int keyBits = (key.getEncoded()).length * 8;

      

+5


a source


Could you just call the method getEncoded()

on the return key and then check the length?

Or you can call a method init()

on the KeyGenerator with 128, 192 or 256 bit options.



Or you can compare the returned key from the modeless version of the call with those where the length was explicitly set (using the method init()

) and see which one matches.

0


a source







All Articles