Every employer is obliged to inform the government of who works for them and how much they pay in wages. The people who work for an employer automatically pay taxes and social security contributions from their wages (see an explanation of gross and net wages). In addition, an employer must personally pay an extra sum to the government. If your boss is doing all this, then you are working legally.
Anyone who works officially is allowed to join a healthcare insurance fund which will reimburse you with a large part of your medical expenses. If, for any reason, you are unable to work or if you retire, you are entitled to benefits or a pension. This is what happens with the money you pay in social security – it is used as a kind of insurance for anyone in difficulties.