Localization is one of the important issues in pervasive sensor networks. Extensive techniques have been proposed recently to make efficient localization schemes. Most existing localization schemes utilize some powerful nodes (called anchor nodes) which can discover their own locations through GPS or manual configuration, and then provide the location information of other sensor nodes. However, since most of these localization schemes have been studied in non-adversarial settings, these schemes are vulnerable to malicious attacks, especially, when anchor nodes are compromised. In this paper, we propose a general compiler that transforms the localization schemes in non-adversarial settings to the localization schemes secure against malicious attacks. This compiler is very useful in that it can cover not only the existing localization schemes but also the new schemes that will be proposed. Moreover, our proposed compiler also supports key management method between sensor nodes and anchor nodes. Therefore, there is no necessity for assuming that each sensor node already has pair-wise key with anchor node.