I had exactly the same problem and today it is fixed.
The problem is with your provider, which is probably Bouncy Castle . When you call getInstance() , just provide the name of your algorithm (which in my case is "AES / CTR / NoPadding"). DO NOT specify a supplier.
Let the code itself explain:
As @Robert said, the following code works correctly:
Cipher c = Cipher.getInstance("AES/CTR/NoPadding"); KeyGenerator kg = KeyGenerator.getInstance("AES"); c.init(Cipher.ENCRYPT_MODE, kg.generateKey()); System.out.println(c.update(new byte[1]).length);
However, if you specify the provider as "BC", this will be incorrect:
Cipher c = Cipher.getInstance("AES/CTR/NoPadding", "BC"); KeyGenerator kg = KeyGenerator.getInstance("AES"); c.init(Cipher.ENCRYPT_MODE, kg.generateKey()); System.out.println(c.update(new byte[20]).length);
This can be seen as a Bouncy Castle bug or a kind of (strange but reasonable) feature.
monnand
source share