The invention provides an anti-fake code generation and verification method based on a cipher machine and a universal serial bus key (USBKey). Calculation is performed to generate a specific anti-fake code according to parameters such as tax number, sum and code of an invoice, an invoice number and an invoice-making-out date, and a verification method is supported. USBKey data verification is synchronously provided, the problem of low USBKey timeliness is solved, effective, safe and timely 'one invoice one code' can be achieved, the cipher machine is applied, an algorithm which can support SM1 / SM2 / SM3 / SM4 / 3DES / SSF33 encryption is provided, an anti-fake code with national standard rule is generated according to invoice information of identify number of invoice maker taxpayer, invoice sum, invoice code, invoice number and invoice making date, hidden dangers that exist in network security can be avoided, and the problem of timeliness can not be solved if secret keys that are instilled by the USBKey are different from any group of secret keys of the cipher machine.