Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AES key size in Java

Testing RSA to encrypt an AES key, I realized that RSA has only 1 block with a limited size (settable by the programmer) do store the encrypted key. The question is, when I use:

KeyGenerator.getInstance("AES").generateKey()

the AES keys will have a constant size in every computer and jvm implementation?

like image 701
The Student Avatar asked Apr 06 '10 14:04

The Student


1 Answers

There is an init method in the KeyGenerator that allows you to specify the number of bits.

KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
keyGenerator.init(128);
SecretKey key = keyGenerator.generateKey();

Will that do what you need?

The default appears to be 128 bits, but I would not assume that all JVM's use the same default, or that it will always be the default.

like image 94
Steve K Avatar answered Sep 26 '22 08:09

Steve K