0

I have found an useful AES256 implementation to en/decrypt strings, all work fine except the fact i have to store the initialization vector (IV) for the decoding.

Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, secret);
AlgorithmParameters params = cipher.getParameters();
ivBytes = params.getParameterSpec(IvParameterSpec.class).getIV();

All there any (secure) alternative methods maybe without CBC, because with CBC i have to store an IV (and in my case i have to share the IV which is really not secure). I have read an article on this platform concerning it´s possible to encode without CBC but that´s not a good idea because of dictionary attacks.

so, are there any alternatives to encode a string with aes256 (without storing additional data like IV, or salt arrays)?

Arpit Srivastava
  • 2,249
  • 1
  • 16
  • 28
mikki
  • 27
  • 1
  • 5

1 Answers1

2

The idea behind an IV is to use a distinct new random one for every encryption (with the same key).

This is very important to ensure the the security of cipher-modes such as CTR or CBC which would not be secure at all without an IV. Also when using the same key to encrypt the same message twice it will result in two distinct ciphertexts (since the two IVs were distinct).

In short, you should always use an IV.

Usually you just prepend them to the ciphertexts and then extract them before encryption, so you don't have to store them individually.

i_turo
  • 2,679
  • 1
  • 13
  • 15
  • +1 The key point here being... the IV is not sensitive information, provided it is randomly chosen each time. The same is true for salt values. – Duncan Jones Aug 20 '14 at 09:53
  • @i_turo thank you for the answer, it works the same way like in example #1 from here http://stackoverflow.com/questions/8622367/what-are-best-practices-for-using-aes-encryption-in-android "return ivHex + encryptedHex;" i have to accept that it´s not a lack of serurity to add the IV to the encoded message. – mikki Aug 20 '14 at 11:23