Disclosure of Invention
The embodiment of the invention aims to provide a method and a system for safely transmitting data between DH and NFCC, which ensure the safety and the integrity of interactive data such as secret keys in the transmission process by adopting an encryption safety mechanism.
To achieve the above object, in a first aspect, an embodiment of the present invention provides a method for securely transmitting data between a DH and an NFCC, including:
Before data transmission is carried out between DH and NFCC, generating an asymmetric key pair when the NFCC is initialized, wherein the asymmetric key pair comprises a public key and a private key;
when the NFC card enters the field, the NFCC sends a first message to the DH;
The DH generates a verification instruction according to the first message and sends the verification instruction to the NFCC, wherein the verification instruction comprises encrypted interaction data;
and the NFCC decrypts the verification instruction by adopting a private key to obtain interaction data.
As a specific implementation of the present application, DH is provided with eSE;
upon initialization of the NFCC, the NFCC specifies that the eSE generate an asymmetric key pair and returns the public key of the asymmetric key pair.
As a specific implementation mode of the application, the first message comprises a notification message, a public key and a random number Rand1, and the DH generates a verification instruction according to the first message, specifically:
the DH receives the notification message and generates a random number Session according to the notification message;
DH adopts the said public key to encrypt the said random number Session;
DH adopts symmetric encryption algorithm and said random number Session to encrypt random number Rand1 and MIFARE card key;
And generating a verification instruction according to the encrypted random number Session, the random number Rand1 and the interaction data.
As a specific implementation manner of the present application, the NFCC decrypts the verification instruction by using a private key to obtain the interaction data, which specifically includes:
The NFCC directly uses or designates eSE to decrypt the verification instruction by using the private key to obtain random number Session;
Decrypting the verification instruction by adopting a random number Session to obtain a random number Rand2;
judging whether the random number Rand2 is the same as the random number Rand 1;
If the verification instruction is the same, decrypting the verification instruction by using a random number Session to obtain interaction data;
if not, an error is returned.
As a preferred implementation manner of the present application, after obtaining the interaction data, the method further includes:
When the NFC card interaction flow is completed or interrupted, the DH and the NFCC destroy the random number Session.
In a second aspect, the embodiment of the application further provides a system for securely transmitting data, which comprises DH and NFCC, wherein the NFCC is used for:
Before data transmission is carried out between DH and NFCC, generating an asymmetric key pair when the NFCC is initialized, wherein the asymmetric key pair comprises a public key and a private key;
When the NFC card enters the field, the NFCC sends a first message to the DH;
the DH adopts an android system for:
Generating a verification instruction according to the first message, and sending the verification instruction to the NFCC, wherein the verification instruction comprises encrypted interaction data;
The NFCC is also for:
and decrypting the verification instruction by adopting a private key to obtain interactive data.
As a specific implementation manner of the application, the first message comprises a notification message, a public key and a random number Rand1, and the DH is specifically used for:
Receiving the notification message, and generating a random number Session according to the notification message;
Encrypting the random number Session by adopting the public key;
Encrypting the random number Rand1 and interaction data by adopting an SM4 algorithm and the random number Session;
And generating a verification instruction according to the encrypted random number Session, the random number Rand1 and the interaction data.
As a specific implementation of the present application, the NFCC is specifically configured to:
decrypting the verification instruction by using the private key by using or designating eSE to obtain a random number Session;
Decrypting the verification instruction by adopting a random number Session to obtain a random number Rand2;
judging whether the random number Rand2 is the same as the random number Rand 1;
If the verification instruction is the same, decrypting the verification instruction by using a random number Session to obtain interaction data;
if not, an error is returned.
By implementing the embodiment of the invention, a pair of asymmetric keys is generated during the initialization of the NFCC, and a secure channel is established between the DH and the NFCC to generate a session key. When the interactive data is transmitted, the session key is used for encrypting the information. Therefore, even if the data are intercepted, the original data cannot be directly analyzed, and the safety and the integrity of the interactive data such as the secret key in the transmission process can be ensured.
In addition, the session key is deleted after the NFC card interaction is completed, so that malicious acquisition or recovery is avoided. Namely, the embodiment of the invention also provides a key destruction mechanism which can effectively prevent the key from being exposed or abused for a long time.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and fully with reference to the accompanying drawings, in which it is evident that the embodiments described are some, but not all embodiments of the invention. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
It should be understood that the terms "comprises" and "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
The technical terms related to the embodiment of the application are described as follows:
NFC (NEAR FIELD Communication), near field Communication technology
NFCC (NEAR FIELD Communication Controller), short-range wireless communication controller, e.g.
NFC chip
DH (Device host), host, e.g. mobile phone terminal
ESE (embedded Secure Element), embedded security element
Referring to fig. 1, a main flow chart of a method for securely transmitting data between DH and NFCC according to an embodiment of the present invention mainly includes the following steps:
s1, before data transmission is carried out between DH and NFCC, generating an asymmetric key pair when the NFCC is initialized.
S2, when the NFC card enters the field, the NFCC sends a first message to the DH.
S3, the DH generates a verification instruction according to the first message and sends the verification instruction to the NFCC.
The verification instruction comprises encrypted interaction data, the first message comprises a notification message, a public key and a random number Rand1, and the DH generates the verification instruction according to the first message and specifically comprises the following steps:
the DH receives the notification message and generates a random number Session according to the notification message;
DH adopts the said public key to encrypt the said random number Session;
DH adopts SM4 algorithm and said random number Session to encrypt random number Rand1 and interactive data;
And generating a verification instruction according to the encrypted random number Session, the random number Rand1 and the interaction data.
S4, the NFCC decrypts the verification instruction by adopting a private key to obtain interaction data.
In specific implementation, step S4 includes:
The NFCC uses or appoints eSE to decrypt the verification instruction by using the private key to obtain a random number Session;
Decrypting the verification instruction by adopting a random number Session to obtain a random number Rand2;
judging whether the random number Rand2 is the same as the random number Rand 1;
If the verification instruction is the same, decrypting the verification instruction by using a random number Session to obtain interaction data;
if not, an error is returned.
S5, the NFCC and the NFC card interact.
And S6, when the NFC card interaction flow is completed or interrupted, the DH and the NFCC destroy the random number Session.
Two specific implementations are included in the main flow diagram, the first for a common DH and the second for a DH with an eSE. The following will describe each.
A first implementation is shown in fig. 3, comprising the steps of:
(1) The NFCC generates an asymmetric key pair upon initialization, the asymmetric key pair comprising a public key and a private key.
(2) When the NFC card enters the field, the NFCC sends the notification information to the DH along with the public KEY of the KEY and a random number Rand.
(3) The DH receives the notification, generates a random number Session, encrypts the Session using the public key and an asymmetric encryption algorithm, encrypts the MIFARE key and Rand using a symmetric encryption algorithm (e.g., SM4 algorithm) with the Session. And sending a verification instruction of the combination of the encrypted Session, rand and the interactive data key to the NFCC.
It should be noted that, since encryption and decryption efficiency of the symmetric algorithm is far higher than that of the asymmetric algorithm, in general, in terms of selection of the algorithm, people are used to preferentially select the symmetric algorithm DES, AES, SM, SM7, etc., and the signature/verification algorithm selects the asymmetric algorithm RSA, ECC, SM, SM9, etc., but may also be flexibly selected according to needs in some special practical application scenarios. In this embodiment, the DH end is considered to be an open unsafe environment, so an asymmetric algorithm is selected when encrypting Session, and the NFCC needs to generate an asymmetric key first.
(4) The NFCC uses the KEY private KEY to decrypt to obtain Session, then uses Session to decrypt to obtain Rand, judges whether the decrypted Rand is the same as the DH, uses Session to decrypt to obtain interactive data, and returns an error if the decrypted Rand is different from the Rand value transmitted to the DH.
(5) And finishing or interrupting the NFC card interaction flow, and destroying Session by DH and NFCC.
The second implementation is shown in fig. 4, and includes the following steps:
(1) Upon initialization of the NFCC, the designated eSE generates an asymmetric KEY pair KEY, which returns the public KEY.
(2) When the NFC card enters the field, the NFCC sends the notification information to the DH along with the public KEY of the KEY and a random number Rand.
(3) The DH receives the notice, generates a random number Session, encrypts the Session by using the public key and an asymmetric encryption algorithm, encrypts the interactive data and Rand by using a symmetric encryption algorithm (e.g., SM4 algorithm). And sending a verification instruction of the combination of the encrypted Session, rand and the interactive data to the NFCC.
(4) The NFCC appoints that the eSE uses the private KEY of the KEY to decrypt to obtain the Session, then uses the Session to decrypt to obtain the Rand, judges whether the decrypted Rand is the same as the DH, otherwise returns an error. And finally, decrypting by using Session to obtain interactive data.
(5) And finishing or interrupting the NFC card interaction flow, and destroying Session by DH and NFCC.
In the second implementation, the security may be further improved by performing the asymmetric key pair operation using the eSE.
By implementing the embodiment of the invention, a pair of asymmetric keys is generated during the initialization of the NFCC, and a secure channel is established between the DH and the NFCC to generate a session key. When the interactive data is transmitted, the session key is used for encrypting the information. Therefore, even if the data are intercepted, the original data cannot be directly analyzed, and the safety and the integrity of the interactive data such as the secret key in the transmission process can be ensured.
In addition, the session key is deleted after the NFC card interaction is completed, so that malicious acquisition or recovery is avoided. Namely, the embodiment of the invention also provides a key destruction mechanism which can effectively prevent the key from being exposed or abused for a long time.
Based on the same inventive concept, the embodiment of the invention also provides a system for safely transmitting data, which comprises DH and NFCC, wherein the NFCC is used for:
Before data transmission is carried out between DH and NFCC, generating an asymmetric key pair when the NFCC is initialized, wherein the asymmetric key pair comprises a public key and a private key;
When the NFC card enters the field, the NFCC sends a first message to the DH;
the DH adopts an android system for:
Generating a verification instruction according to the first message, and sending the verification instruction to the NFCC, wherein the verification instruction comprises encrypted interaction data;
The NFCC is also for:
and decrypting the verification instruction by adopting a private key to obtain interactive data.
Further, the first message includes a notification message, a public key, and a random number Rand1, where the DH is specifically configured to:
Receiving the notification message, and generating a random number Session according to the notification message;
Encrypting the random number Session by adopting the public key;
Encrypting the random number Rand1 and interaction data by adopting an SM4 algorithm and the random number Session;
And generating a verification instruction according to the encrypted random number Session, the random number Rand1 and the interaction data.
Further, the NFCC is specifically configured to:
decrypting the verification instruction by using the private key by using or designating eSE to obtain a random number Session;
Decrypting the verification instruction by adopting a random number Session to obtain a random number Rand2;
judging whether the random number Rand2 is the same as the random number Rand 1;
If the verification instruction is the same, decrypting the verification instruction by using a random number Session to obtain interaction data;
if not, an error is returned.
It should be noted that, please refer to the foregoing method embodiment, and the detailed description is omitted herein.
While the invention has been described with reference to certain preferred embodiments, it will be understood by those skilled in the art that various changes and substitutions of equivalents may be made and equivalents will be apparent to those skilled in the art without departing from the scope of the invention. Therefore, the protection scope of the invention is subject to the protection scope of the claims.