Is it legal in Spain for a male airport security guard to ask you to lift up your blouse and swab your bare stomach?

Is it actually legal to ask me to lift up my blouse, as I find it a bit indecent?

Yes, its “legal” because it is not against the law. The security personnel have asked me to remove shoes, belt, lift up my shirt, turn over my pant waist, all in the name of security and all in the public area.

I guess the question in your mind is if it is okay for a male to do that for a female. In many airports, you can ask for a person of the same gender to screen you in private, or have one present while screened. However, as mentioned in the comments this has to be requested and even then it may not be practical as there may not be someone available; which may add to a delay for you.

As for the reaction on your skin, simply apply any topical allergy cream or ointment. It is likely a reaction against the fiberglass strands in the swab. If the rash persists or it becomes itchy, consult a medical professional.