Encode and decode based on dkey.