1

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)

Simon
  • 9,962
  • 1
  • 26
  • 43
Rafael
  • 993
  • 4
  • 14
  • 31

1 Answers1

4

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 })));
Community
  • 1
  • 1
artbristol
  • 30,694
  • 5
  • 61
  • 93
  • Thanks artbristol. I am using the Java security package like so: cipher = Cipher.getInstance("AES"); I'm just not sure if that is the equivalent of using ECB. I tried using ECB instead of AES but get a 'could not find provider supporting ECB' error. – Rafael Apr 14 '11 at 16:08
  • ECB is not a cipher algorithm, it is a *way of using* a block cipher. – artbristol Apr 14 '11 at 16:09
  • Hehe. Got it. Thanks. Despite that ECB mode is not recommended, let's suppose I need to use the AES cipher algorithm in ECB mode in Java. I need to find a provider that a supports it, ah? Looks like SunJCE does not. Any chance you know of any? – Rafael Apr 14 '11 at 16:35
  • Have you tried using Cipher.getInstance("AES/ECB/") ? – artbristol Apr 14 '11 at 16:51
  • I tried cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); and cipher = Cipher.getInstance("AES/ECB/NoPadding"); and both gave the following error: No installed provider supports this key: (null) – Rafael Apr 14 '11 at 17:43
  • Sounds like you're on the right track, anyway. Does it work with other modes, e.g. CBC, or is this your first attempt to use the javax.crypto stuff? – artbristol Apr 14 '11 at 17:53
  • It does sound like it. This is my first attempt at javax.crypto stuff. I did try just ECB and CBC with no success. Thanks again for helping. – Rafael Apr 14 '11 at 17:58
  • why is this not as easy as it is in RoR: Aes.encrypt_buffer(128, 'ECB', SecuritySetting.cypher_key, nil, password).....;-) – Rafael Apr 14 '11 at 18:03
  • Maybe take a look at http://docstore.mik.ua/orelly/java-ent/jnut/ch26_01.htm it's a bit out of date, but probably still good. – artbristol Apr 14 '11 at 18:07
  • Thanks for the link. Great info. Sounds like I could do this: cipher = Cipher.getInstance("AES/ECB/PKCS5Padding", "SunJCE"); but I get null pointer exception in my next line of code: cipher.init(Cipher.ENCRYPT_MODE, skeySpec); – Rafael Apr 14 '11 at 18:15
  • updated answer with some more sample code. can't really help much more, i've not used it myself – artbristol Apr 14 '11 at 18:32