refactor encrypt method