zeropadding
ZeroPadding,数据长度不对齐时使用0填充,否则不填充。使用0填充有个缺点,当元数据尾部也存在0时,在unpadding时可能会存在问题。
pkcs7padding
假设每个区块大小为blockSize
<1>已对齐,填充一个长度为blockSize且每个字节均为blockSize的数据。
<2>未对齐,需要补充的字节个数为n,则填充一个长度为n且每个字节均为n的数据。
pkcs5padding
PKCS7Padding的子集,只是块大小固定为8字节。
ECB 模式

//加密
string DES_encrypt(const char *key, string &content){
string cipher;
try{
ECB_Mode<DES>::Encryption e;
e.SetKey((const byte*)key, DES::KEYLENGTH);
StringSource(content, true, new StreamTransformationFilter(e,new StringSink(cipher)));
}
catch (const Exception &e){
cout << e.what() << endl;
}
return cipher;
}
//解密
string DES_decrypt(const char *key, string &cipher){
string plain;
try{
ECB_Mode<DES>::Decryption e;
e.SetKey((const byte*)key, DES::KEYLENGTH);
StringSource(content, true, new StreamTransformationFilter(e,new StringSink(plain)));
}
catch (const Exception &e){
cout << e.what() << endl;
}
return plain;
}
本文探讨了密码学中的几种填充方法,包括ZeroPadding、pkcs7padding和pkcs5padding,并详细介绍了DES加密解密算法在ECB模式下的实现过程。通过对比不同填充方式的特点,以及在实际应用中可能遇到的问题,加深了对密码学填充的理解。
2243

被折叠的 条评论
为什么被折叠?



