difference between the methods update() and dofina

2019-08-11 08:49发布

I have read one article about difference between the methods update() and dofinal() in cipher. It was about what will happend if we want to encrypt 4 Bytes Array, when the block size of the cipher is for example 8 Bytes. If we call update here it will return null. My question is: what will happen if we call doFinal() with a 4 byte array to encrypt, and the buffer size is 8 bytes, how many bytes encoded data will we receive on the return?

1条回答
Deceive 欺骗
2楼-- · 2019-08-11 09:23
  • update(): feed the data, again and again, enables you to encrypt long files, streams.

  • dofinal(): apply the requested padding scheme to the data, if requested and necessary, then encrypt. ECB and CBC mode requires padding but CTR mode doesn't. If NOPADDING has used some libraries may secretly pad, in others you have to handle the padding yourself.

When you call, dofinal() with 4-byte data, if NOPADDING is not set, it will be padded and then encrypted.

From Java Doc;

  • update(byte[] input) Continues a multiple-part encryption or decryption operation (depending on how this cipher was initialized), processing another data part.
  • doFinal() Finishes a multiple-part encryption or decryption operation, depending on how this cipher was initialized.
查看更多
登录 后发表回答