Encode database key on set