We are trying to build a merkle tree in web3j and put the root for verification into the smart contract. Due to this problem we can't generate the same route between web3j and solidity/js...
In javascript:
Buffer.from(keccak256('4cdecb9e5f6a88b1696ca7e28b3a7e3d7474058d')).toString('hex');
Buffer.from(keccak256('0x4cdecb9e5f6a88b1696ca7e28b3a7e3d7474058d')).toString('hex');
Gives:
07c50cf7885d2f22d0ebc2b0e03eaf1f51d453169eddd2205970b9c139ec9475 47413ead80d195beca855e500674fd1a0a70c2f51bb3e82043c82959cd43d1c8
In web3j:
Numeric.toHexString(Hash.sha3("4cdecb9e5f6a88b1696ca7e28b3a7e3d7474058d".getBytes()), 0, 40, false);
Numeric.toHexString(Hash.sha3("0x4cdecb9e5f6a88b1696ca7e28b3a7e3d7474058d".getBytes()), 0, 42, false);
Gives:
07c50cf7885d2f22d0ebc2b0e03eaf1f51d453169eddd2205970b9c139ec9475 0652712e0f4e9f734d7a1e1a47413791135ed765dd25779c0eb5a282e0739c6e
The first result is the same, the 2nd different. This seems to be so with anything having '0x' at the front - regardless of string length, etc.