Encryption and decryption not working in deep-stream-app(model file)?

I have encrypted engine file by adding watermark. Also I have decrypted (above generated encrypted) file in function

TrtModelBuilder::deserializeEngine(const std::string& path, int dla)
{
 //my decryption code
}

The above function is inside file (/opt/nvidia/deepstream/deepstream-5.1/sources/libs/nvdsinfer/nvdsinfer_model_builder.cpp)

Now, that decrypted file is not working with deepstream-app.
Error:
ERROR: [TRT]: INVALID_STATE: std::exception
ERROR: [TRT]: INVALID_CONFIG: Deserialize the cuda engine failed.
ERROR: Deserialize engine failed from file: /opt/nvidia/deepstream/deepstream-5.1/samples/models/Primary_Detector_Nano/Encrypted.engine

Also, if i write any print statement, then its not working.

NOTE:
I have generated model engine file successfully, also able to run generated file with deepstream-app.
Thanks

please check if the decrypted engine data is the same as the TRT engine data you built.

I have checked encrypted & decrypted data, both are same in size, but that function is not working, even print statement is not working if I add some text in function.

TrtModelBuilder::deserializeEngine(const std::string& path, int dla)
{
print("A")
 //my decryption code
}

Any help will be appreciated. Thanks