Corrosion prevention of magnesium alloys