Refactored the users encryption part and added tests