what happened if I call doFinal() without any input?
Hi,
In partial of my encryption code using PBEWithMD5AndDES, by giving pass phrase, salt and iteration count, the key was generated. I used the following code to generate the output ciphertext[]:
PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, iterations);
SecretKeyFactory keyFac = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
SecretKey key = keyFac.generateSecret(new javax.crypto.spec.PBEKeySpec(pass phrase));
Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES");
cipher.init(Cipher.ENCRYPT_MODE, key, pbeParamSpec);
byte ciphertext[] = cipher.doFinal();
I didn't give any input to doFinal() call, and there was no update() call, what does this ciphertext[] exactly represent?
Thanks.
# 1
> Hi,
> In partial of my encryption code using
> PBEWithMD5AndDES, by giving pass phrase, salt and
> iteration count, the key was generated. I used the
> following code to generate the output ciphertext[]:
>
> PBEParameterSpec pbeParamSpec = new
> PBEParameterSpec(salt, iterations);
> SecretKeyFactory keyFac =
> SecretKeyFactory.getInstance("PBEWithMD5AndDES");
> SecretKey key = keyFac.generateSecret(new
> javax.crypto.spec.PBEKeySpec(pass phrase));
>
> Cipher cipher =
> Cipher.getInstance("PBEWithMD5AndDES");
> cipher.init(Cipher.ENCRYPT_MODE, key, pbeParamSpec);
> byte ciphertext[] = cipher.doFinal();
>
> I didn't give any input to doFinal() call, and there
> was no update() call, what does this ciphertext[]
> exactly represent?
>
> Thanks.
Junk.
# 4
> > Junk
>
> Have you tried it or are you just guessing?
>
> I suspect it represents an empty byte array (= new
> byte[0]) actually.
Oh, I just guessed. Sorry, you are right. It will be an encryption of an empty byte array.
By the way, just a further inquiry. What would a person want to do with an encrypted empty byte array? I mean what purpose would it serve? any clues?
Thanks.
# 10
> You have lost me. It is perfectly valid to encrypt a
> byte array of zero length. Decryption will then
> produce a byte array of zero length.
>
> P.S. How are you related to the OP?
Ok. I thought you meant something more complicated. My bad.
I am not related to the OP. I was just trying to understand what you meant by your post.
Thanks for the clarification.