AES key size in Java

Testing RSA for AES key encryption, I realized that RSA has only 1 block with a limited size (set by the programmer), keep the encrypted key. The question is when I use:

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

Will AES keys be of constant size on every computer and jvm implementation?

+7
java encryption aes
source share
4 answers

KeyGenerator has an init method that lets you specify the number of bits.

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

Will this do what you need?

By default , up to 128 bits will be displayed, but I would not assume that all JVMs use the same default or that it will always be the default.

+11
source share

The Suns Java Cryptography Extension documentation claims that multiple key sizes are supported for AES keys and does not provide any default size information.

The maximum key size may also vary depending on the jurisdictional files used by different versions of Suns JVM.

+2
source share

KeyGenerator has several init() methods; you must call one of them before generating the key. The Javadoc for KeyGenerator indicates that in case you do not call one of the init() methods, then "each provider must provide (and the document) default initialization."

So it depends on the provider. Since you initialize the key generator using the name of the AES algorithm, it can be assumed that you will get a key with a size suitable for AES, that is 128, 192 or 256 bits (16, 24 and 32 bytes, respectively). But the one you get depends on the actual provider, which may depend on the JVM and possibly on its configuration.

0
source share

https://docs.oracle.com/javase/7/docs/api/javax/crypto/Cipher.html

Each implementation of the Java platform is required to support the following standard encrypted conversions with keys in parentheses:

 AES/CBC/NoPadding (128) AES/CBC/PKCS5Padding (128) AES/ECB/NoPadding (128) AES/ECB/PKCS5Padding (128) DES/CBC/NoPadding (56) DES/CBC/PKCS5Padding (56) DES/ECB/NoPadding (56) DES/ECB/PKCS5Padding (56) DESede/CBC/NoPadding (168) DESede/CBC/PKCS5Padding (168) DESede/ECB/NoPadding (168) DESede/ECB/PKCS5Padding (168) RSA/ECB/PKCS1Padding (1024, 2048) RSA/ECB/OAEPWithSHA-1AndMGF1Padding (1024, 2048) RSA/ECB/OAEPWithSHA-256AndMGF1Padding (1024, 2048) 
0
source share

All Articles