Disclosure of Invention
The embodiment of the invention provides an IC card encryption and authentication method and system, which are used for solving the technical problem that the existing entrance guard IC card can be easily copied and stolen to cause security management loopholes, so that the encryption and authentication method of the entrance guard IC card is optimized, and the security of entrance guard management is improved.
In order to solve the above technical problem, an embodiment of the present invention provides an IC card encryption method, which is executed by a card swiping device, and at least includes the following steps:
reading the card number of the IC card and generating a registration ciphertext according to the card number;
randomly generating a registration sector number, and writing the registration ciphertext into a sector of the IC card corresponding to the registration sector number;
and storing the card number and the registration sector number in a local memory in an associated manner.
Preferably, the registration ciphertext is obtained by performing MD5 calculation according to the card number.
Preferably, the IC card is a contactless IC card.
In order to solve the same technical problem, the invention also provides an IC card authentication method, comprising:
the card swiping device reads the card number of the IC card, and sends an authentication request to the IC card when a registration sector number associated with the card number of the IC card is inquired and stored in a local memory; the authentication request comprises the registration sector number and a verification ciphertext generated according to the card number of the IC card;
the IC card inquires the registration ciphertext of the corresponding sector of the IC card according to the registration sector number, and when the verification ciphertext is judged to be consistent with the registration ciphertext, a verification success instruction is fed back to the card swiping device;
and after the card swiping device receives the verification success command, controlling the unlocking and releasing of the access control device.
Preferably, the verification ciphertext is obtained by performing MD5 calculation according to the card number of the IC card.
Further, the IC card authentication method further includes:
and the IC card inquires the registration ciphertext of the corresponding sector of the IC card according to the registration sector number, and when the verification ciphertext is judged to be inconsistent with the registration ciphertext, a verification failure instruction is fed back to the card swiping device.
Preferably, the IC card is a contactless IC card.
In order to solve the same technical problem, the invention also provides an IC card encryption and authentication system, which comprises a card swiping device, an IC card and an access control device; wherein the content of the first and second substances,
the card swiping device is used for reading the card number of the IC card when the IC card is encrypted and generating a registration ciphertext according to the card number; randomly generating a registration sector number, and writing the registration ciphertext into a sector of the IC card corresponding to the registration sector number; storing the card number and the registration sector number in a local memory in an associated manner; the system comprises an IC card, an access control device and a local memory, wherein the IC card is used for reading the card number of the IC card when the IC card is authenticated, sending an authentication request to the IC card when a registration sector number associated with the card number of the IC card is inquired and stored in the local memory, and controlling the access control device to unlock and release after receiving a verification success instruction fed back by the IC card; the authentication request comprises the registration sector number and a verification ciphertext generated according to the card number of the IC card;
and the IC card is used for inquiring the registration ciphertext of the corresponding sector of the IC card according to the registration sector number, and feeding back a verification success instruction to the card swiping device when the verification ciphertext is judged to be consistent with the registration ciphertext.
Preferably, the registration ciphertext and the verification ciphertext are obtained by performing MD5 calculation according to the card number of the IC card; the IC card is a non-contact IC card.
The invention effectively prevents the existing entrance guard IC card from being easily copied and stolen by writing in the ciphertext during the registration of the IC card and verifying the ciphertext on the IC card in the card swiping authentication process, thereby effectively improving the reliability and the safety of entrance guard management.
Detailed Description
The technical solutions in the embodiments of the present invention will be described clearly and completely with reference to the accompanying drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, an embodiment of the present invention provides an IC card encryption method, which is executed by a card swiping device, and at least includes the following steps:
step S210, reading a card number of the IC card, and generating a registration ciphertext according to the card number;
in the embodiment of the present invention, it should be noted that a user needs to register an IC card through a card swiping device in an access control system. In the encryption process of the IC card, namely when the entrance guard IC card is registered, the MCU in the card swiping device firstly reads the card number of the IC card through the radio frequency chip, and then the card number is subjected to encryption operation to obtain a registration ciphertext.
Step S220, randomly generating a registration sector number, and writing the registration ciphertext into a sector of the IC card corresponding to the registration sector number;
in the embodiment of the present invention, it should be noted that the card swiping device randomly generates a sector number that the registration password needs to be stored, and writes the registration ciphertext into the corresponding sector of the IC card according to the generated sector number.
Referring to fig. 4, it can be understood that the IC card has 16 sectors, each sector having 4 blocks, wherein 0 block of the 1 st sector is a card serial number, and is read-only and cannot be written; the cipher text is stored in block 3 of each sector.
Step S230, storing the card number and the registration sector number in a local memory in an associated manner.
In the embodiment of the present invention, it should be noted that the MCU of the card swiping device needs to store the registration information of the IC card in the local memory in an associated manner, where the registration information includes the card number and the registration sector number.
Referring to fig. 3, the card swiping device mainly comprises a main control chip, a memory and a radio frequency chip.
In the embodiment of the present invention, as a preferable scheme, the registration ciphertext is obtained by performing MD5 calculation according to the card number.
In the embodiment of the present invention, preferably, the IC card is a contactless IC card.
It is understood that the IC card is a card form in which a microelectronic chip is embedded in a card base conforming to the ISO7816 standard. The communication mode between the IC card and the reader-writer can be contact type or non-contact type; it should be noted that, as a preferable aspect, the IC card in the embodiment of the present invention is a contactless IC card.
It should be noted that, the traditional access control IC card reading system only realizes verification of the IC card number, and when the card is swiped, the card number of the IC card is verified to be registered, that is, unlocking is realized, and lawless persons can easily realize the function of swiping the card to unlock by copying the card number by using an empty card or by using an analog card. By the IC card encryption and authentication method provided by the invention, when the card is verified and swiped, the system not only checks the card number, but also adds the function of checking the sector password of the IC card on the basis of the card number, thereby effectively preventing the use phenomenon of copying the simulated IC card.
The invention effectively prevents the existing entrance guard IC card from being easily copied and stolen by writing in the ciphertext during the registration of the IC card and verifying the ciphertext on the IC card in the card swiping authentication process, thereby effectively improving the reliability and the safety of entrance guard management.
In the embodiment of the present invention, it should be noted that a user needs to register an IC card through a card swiping device in an access control system. In the encryption process of the IC card, namely when the entrance guard IC card is registered, the MCU in the card swiping device firstly reads the card number of the IC card through the radio frequency chip, and then obtains a registration ciphertext through encryption operation of the card number, wherein the encryption operation can be MD5 calculation; then the MCU generates random numbers (1-16), then the MCU writes the registration ciphertext into a block 3 of a corresponding sector of the IC card according to the generated random numbers, and simultaneously the MCU stores the card number and the sector number of the random password, thereby completing the encryption process of the IC card. It can be understood that the door entry system includes an intercom main control MCU chip and a radio frequency chip RC 522. When the IC card is swiped to contact with the radio frequency card chip, the encryption and authentication processes of the IC card are realized by means of communication between the radio frequency chip and the master control MCU chip.
Referring to fig. 2, in order to solve the same technical problem, the present invention further provides an IC card authentication method, including:
step S310, the card swiping device reads the card number of the IC card, and when a registration sector number associated with the card number of the IC card is stored in a local memory, an authentication request is sent to the IC card; the authentication request comprises the registration sector number and a verification ciphertext generated according to the card number of the IC card;
in the embodiment of the invention, it should be noted that, in the authentication process of the IC card, that is, when a user swipes the card in response, the MCU of the door access card swiping device first reads the card number of the IC card through the radio frequency chip, and obtains a verification ciphertext through the MD5 calculation of the card number, and then determines whether the card number is registered, and when the card number is not queried in the local memory, it indicates that the card is not registered, and feeds back a reminder of card swiping failure; when the card number is inquired to be registered, the registration password storage sector number of the IC card is inquired through the associated registration information, then the MCU sends the verification ciphertext to the IC card through the radio frequency chip, and requests to verify the registration ciphertext of the corresponding sector.
Step S320, the IC card inquires a registration ciphertext of a corresponding sector of the IC card according to the registration sector number, and when the verification ciphertext is judged to be consistent with the registration ciphertext, a verification success instruction is fed back to the card swiping device;
in the embodiment of the invention, when the IC card receives the verification request, the internal part of the IC card chip compares whether the verification ciphertext sent by the card swiping device is consistent with the registration ciphertext of the corresponding sector, if so, the verification is successfully returned, and if not, the verification is failed in feedback.
And S330, after the card swiping device receives the verification success command, controlling the unlocking and releasing of the access control device.
In the embodiment of the present invention, it should be noted that when the card swiping device receives the verification success command returned by the IC card, the door access device is controlled to unlock and release, otherwise, an illegal card is prompted.
In the embodiment of the present invention, as a preferable scheme, the verification ciphertext is obtained by performing MD5 calculation according to the card number of the IC card.
In the embodiment of the present invention, further, the IC card authentication method further includes:
and the IC card inquires the registration ciphertext of the corresponding sector of the IC card according to the registration sector number, and when the verification ciphertext is judged to be inconsistent with the registration ciphertext, a verification failure instruction is fed back to the card swiping device.
In the embodiment of the present invention, preferably, the IC card is a contactless IC card.
In order to solve the same technical problem, the invention also provides an IC card encryption and authentication system, which comprises a card swiping device, an IC card and an access control device; wherein the content of the first and second substances,
the card swiping device is used for reading the card number of the IC card when the IC card is encrypted and generating a registration ciphertext according to the card number; randomly generating a registration sector number, and writing the registration ciphertext into a sector of the IC card corresponding to the registration sector number; storing the card number and the registration sector number in a local memory in an associated manner; the system comprises an IC card, an access control device and a local memory, wherein the IC card is used for reading the card number of the IC card when the IC card is authenticated, sending an authentication request to the IC card when a registration sector number associated with the card number of the IC card is inquired and stored in the local memory, and controlling the access control device to unlock and release after receiving a verification success instruction fed back by the IC card; the authentication request comprises the registration sector number and a verification ciphertext generated according to the card number of the IC card;
and the IC card is used for inquiring the registration ciphertext of the corresponding sector of the IC card according to the registration sector number, and feeding back a verification success instruction to the card swiping device when the verification ciphertext is judged to be consistent with the registration ciphertext.
In the embodiment of the present invention, as a preferred scheme, the registration ciphertext and the verification ciphertext are both obtained by performing MD5 calculation according to the card number of the IC card; the IC card is a non-contact IC card.
In summary, the method and system for encrypting and authenticating the IC card provided by the embodiment of the present invention effectively prevent the existing access control IC card from being easily copied and stolen by writing the ciphertext during the registration of the IC card and verifying the ciphertext during the card swiping authentication, thereby effectively improving the reliability and security of the access control management.
While the foregoing is directed to the preferred embodiment of the present invention, it will be understood by those skilled in the art that various changes and modifications may be made without departing from the spirit and scope of the invention.