Determine size of decrypted data from gcry_cipher_decrypt?

孤人 提交于 2019-12-02 11:49:39

You need to apply a padding scheme to your input, and remove the padding after the decrypt. gcrypt doesn't handle it for you.

The most common choice is PKCS#7. A high level overview is that you fill the unused bytes in your final block with the number of padded bytes (block_size - used_bytes). If your input length is a multiple of the block size, you follow it with a block filled with block_size bytes.

For example, with 8-byte blocks and 4 bytes of input, your raw input would look like:

AB CD EF FF 04 04 04 04

When you do the decrypt, you take the value of the last byte of the last block, and remove that many bytes from the end.

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