Two-dimensional (2D) barcode technology is an electronic tagging technology based on combination of computer and optical technology. It is an important way of information collection and input. 2D barcode technology has been widely used in various fields of logistics, production automation, and e-commerce, but it also has brought about a series of safety problems. Based on evolutionary encryption technology, this paper improved algorithm of traditional 2D barcode generation, to improve forgery-proof performance of 2D barcode. This algorithm is applied to agricultural products quality and safety traceability system and the results show that it is effective.