Refactored encrypt