The beacon nodes play a key role in the process of unknown nodes' localization in wireless sensor networks' localization algorithms. However, the security of beacon nodes is often overlooked. A secure and optimal DV-Hop localization algorithm is proposed against malicious beacon nodes which send false location information in this paper. The proposed algorithm isolates malicious beacon nodes by the scheme of beacon-distance constraint and overcomes negative factor which is caused by the decline of beacon nodes' ratio and remaining malicious beacon nodes by the scheme of multi-correction balance. It improves the correction and security performance of localization algorithm.