difference between the methods update() and dofinal() in cipher

耗尽温柔 提交于 2019-12-31 04:37:05

问题


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:


  • 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.


来源:https://stackoverflow.com/questions/54056151/difference-between-the-methods-update-and-dofinal-in-cipher

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!