Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset the Cipher to the state at the time of initialization?

To preserve the key, the iv, and the mode of operation and to reset all buffers and so on. doFinal() call is that correct? But doFinal () will do the extra work. And I do not need previous data.

Cipher с=Cipher.getInstance("AES/CBC/PKCS7Padding");
с.init(Cipher.DECRYPT_MODE, key, iv);
....

void Decode(Cipher c)
{
   c.doFinal();//reset cipher !?
   //Start a new decoding session
   ....
}
like image 420
Mixer Avatar asked Nov 19 '25 13:11

Mixer


1 Answers

You call Cipher.init(), of course.

You just need to rearrange your API so that the correct parameters are provided to your methods so they can call init().

You will probably need a new initialization vector for each separate encrypt/decrypt anyway.

like image 101
user207421 Avatar answered Nov 22 '25 02:11

user207421



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!