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;
}