Add try-catch block for encrypt method