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