I'm making program in C++ that works with vector<uint8_t> and uses Crypto++ library. I separate my vector to small ones and trying to convert it to Integer, but sometimes small vector block contains of zeros at the begining, so when i convert back from Integer to vector<uint8_t>, this vector does not contain this zeros. Here is the code:
void Test(vector<uint8_t> data)
{
vector<uint8_t> cipher;
size_t blockSize = _keySize / 8;
for (size_t i = 0; i < data.size(); i += blockSize)
{
size_t blockLength = min(blockSize, data.size() - i);
vector<uint8_t> block(data.begin() + i, data.begin() + i + blockLength);
Integer m;
m.Decode(block.data(), block.size());
size_t Size = m.MinEncodedSize();
vector<uint8_t> encrypt(Size);
m.Encode(encrypt.data(), encrypt.size());
if (encrypt != block)
{
cout << i << " " << unsigned(block[0]) << endl;
}
}
}
In this code _keySize is 1024, and data contains 140000 elements. Here is the output:
11264 0
17280 0
29952 0
53632 0
57728 0
63104 0
75392 0
137216 0
138880 0
I was trying to use OpenSSL library, but has same mistake.