Patch to fix the encrypted msg parsing

This is a nasty bug and sorry for many attempts and I am just so exhausted to clean up the commits.
The bug will fix the multi-datacenter replication and make it replicates more reliably as equally as non-encryption version.