My application runs on Windows desktop. Algorithm used is Triple DES. The Data is encrypted on the server using Bouncycastle java API. The application is able to decrypt the data on Windows 10 but fails to decrypt correctly on windows 11. It decrypts the first part of the data correctly the remaining part is remains encrypted.
Java Code - Encryption
static final int BLOCK_SIZE_3DES = 8;
public byte[] encryptDESede(byte[] data, byte[] key, byte[] initVec) throws StandardException {
//add paddingif req
if(data.length % BLOCK_SIZE_3DES != 0) {
byte[] padding = new byte[BLOCK_SIZE_3DES - (data.length % BLOCK_SIZE_3DES)];
for (int i = 0; i < padding.length; i++)
padding[i] = (byte) padding.length;
data = Bytes.join(new byte[][]{data, padding});
}
BlockCipher engine = new DESedeEngine();
CBCBlockCipher cbc = new CBCBlockCipher(engine);
BufferedBlockCipher cipher = new BufferedBlockCipher(cbc); cipher.init(true, new ParametersWithIV(new KeyParameter(key), initVec));
byte[] out = new byte[data.length]; cipher.processBytes(data, 0, data.length, out, 0);
return out;
}
C++ Decryption Code
bool Decipher(CData & _Data) const {
DWORD FinalSize = _Data.size();
//check that size is multiple of 8
if ( _Data.size() % 8) {
return false;
}
BOOL Result = CryptDecrypt(m_Key, 0, TRUE, 0, _Data.data(), &FinalSize);
DWORD err = GetLastError();
if (Result == FALSE && err != NTE_BAD_DATA)
return false;
if ((Result == FALSE) && (err == NTE_BAD_DATA)) {
CData EmptyBlob;
Encipher(EmptyBlob);
}
else
{
// Return ciphered data and final size
_Data.resize(FinalSize);
}
return true;
}