密码中update()和dofinal()方法之间的区别 [英] difference between the methods update() and dofinal() in cipher

查看:2095
本文介绍了密码中update()和dofinal()方法之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过一篇有关密码中的update()和dofinal()方法之间差异的文章. 这是关于如果我们要加密4字节数组(当密码的块大小为8字节时)会发生什么.如果我们在此处调用update,它将返回null.我的问题是:如果我们调用带有4字节数组的doFinal()进行加密,并且缓冲区大小为8字节,会在返回时收到多少字节的编码数据,将会发生什么?

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?

推荐答案

  • update():一次又一次地输入数据,使您能够加密长文件,流.

    • update(): feed the data, again and again, enables you to encrypt long files, streams.

      dofinal():如果需要和必要,则将请求的填充方案应用于数据,然后进行加密. ECB和CBC模式需要填充,但CTR模式则不需要.如果NOPADDING使用了某些库,则可能秘密填充,在其他情况下,您必须自己处理填充.

      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.

      当您呼叫具有4字节数据的dofinal()时,如果未设置NOPADDING,则将其填充然后加密.

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

      来自Java Doc;

      From Java Doc;

      • update(byte[] input) 继续进行多部分加密或解密操作(取决于此密码的初始化方式),处理另一个数据部分.
      • doFinal() 根据此密码的初始化方式,完成多部分加密或解密操作.
      • 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.

      这篇关于密码中update()和dofinal()方法之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆