Cipher with AES/ECB128/PKCS5Padding keeps throwing "No such algorithm" exception

One Two Three picture One Two Three · May 2, 2012 · Viewed 8.2k times · Source

Does anyone know what's wrong with this code?

Cipher cipher = Cipher.getInstance("AES/ECB128/PKCS5Padding", "SunJCE");
  • Algorithm: AES
  • Mode of operation: ECB (with 128 appended to specify the block size)
  • PaddingSchemce: PKCS5Padding

This seems correct to me but it keeps throwing the "No such algorithm" exception during instantiation.

Answer

skiphoppy picture skiphoppy · May 2, 2012

With nothing but the stock JDK in my classpath, I ran this code snippet and grepped for AES in the output:

for (Provider provider: Security.getProviders()) {
  System.out.println(provider.getName());
  for (String key: provider.stringPropertyNames())
    System.out.println("\t" + key + "\t" + provider.getProperty(key));
}

I saw this line:

    Cipher.AES SupportedPaddings    NOPADDING|PKCS5PADDING|ISO10126PADDING

That suggests to me that your padding is supported.

I also saw this line:

    Cipher.AES SupportedModes       ECB|CBC|PCBC|CTR|CTS|CFB|OFB|CFB8|CFB16|CFB24|CFB32|CFB40|CFB48|CFB56|CFB64|OFB8|OFB16|OFB24|OFB32|OFB40|OFB48|OFB56|OFB64|CFB72|CFB80|CFB88|CFB96|CFB104|CFB112|CFB120|CFB128|OFB72|OFB80|OFB88|OFB96|OFB104|OFB112|OFB120|OFB128

I notice that ECB appears here, but ECB128 does not, so I wonder if that is the issue. I'm going to confess I don't know enough to know if this information is on the right track or not.

Edited to add: I am able to call Cipher.getAlgorithm("AES/ECB/PKCS5Padding") with ECB, instead of ECB128. It looks to me like with ECB you can't specify the block size, at least with what is available here. Not sure if this is sufficient for you or not.