Refactor encrypt