pkcs7padding c++实现

5020阅读 0评论2016-11-03 sxcong
分类:C/C++

(cryptography)



1 Padding :

string text;
int len = text.size();
char chT = (AES_BLOCK_SIZE - len%AES_BLOCK_SIZE); 
for (int i = 0; i< (AES_BLOCK_SIZE - len%AES_BLOCK_SIZE); i++) 

text.push_back(chT); 

2 UnPadding:
char chT = out[len-1]; 
for (int i = 0; i < chT; i++)
{
if (out[len - i -1] != chT)
{
return len;
}
}


The padding will be one of:

01
02 02
03 03 03
04 04 04 04
05 05 05 05 05
etc.

This padding method (as well as the previous two) is well-defined if and only if N is less than 256.

Example: In the following example the block size is 8 bytes and padding is required for 4 bytes

... | DD DD DD DD DD DD DD DD | DD DD DD DD 04 04 04 04 |


上一篇:摄像头avcodec_encode_video2编码后保存264播放的解决
下一篇: 围棋开源软件DarkForestGo学习