is there a Java ECB provider?

Rafael picture Rafael · Apr 14, 2011 · Viewed 7.7k times · Source

Anyone know of a Rijndael-128bit ECB provider in Java???

Also, what's the difference between AES-128bit and ECB? or are they the same? (couldn't find answer any where else online)

Answer

artbristol picture artbristol · Apr 14, 2011

ECB is a way of using a block cipher (not a cipher itself). It is not very good. Here is a related question How to choose an AES encryption mode (CBC ECB CTR OCB CFB)?.

I suspect if you find an implementation of AES (which is the same as Rijndael, by the way), it will be configurable to use ECB.

Try the following to start you off

Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding", "SunJCE");
Key skeySpec = KeyGenerator.getInstance("AES").generateKey();
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
System.out.println(Arrays.toString(cipher.doFinal(new byte[] { 0, 1, 2, 3 })));