Movatterモバイル変換


[0]ホーム

URL:


CN106357393B - A kind of safe data transmission method and device - Google Patents

A kind of safe data transmission method and device
Download PDF

Info

Publication number
CN106357393B
CN106357393BCN201610744373.9ACN201610744373ACN106357393BCN 106357393 BCN106357393 BCN 106357393BCN 201610744373 ACN201610744373 ACN 201610744373ACN 106357393 BCN106357393 BCN 106357393B
Authority
CN
China
Prior art keywords
random number
data
preset
key
module
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201610744373.9A
Other languages
Chinese (zh)
Other versions
CN106357393A (en
Inventor
陆舟
于华章
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Feitian Technologies Co Ltd
Original Assignee
Feitian Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Feitian Technologies Co LtdfiledCriticalFeitian Technologies Co Ltd
Priority to CN201610744373.9ApriorityCriticalpatent/CN106357393B/en
Publication of CN106357393ApublicationCriticalpatent/CN106357393A/en
Application grantedgrantedCritical
Publication of CN106357393BpublicationCriticalpatent/CN106357393B/en
Activelegal-statusCriticalCurrent
Anticipated expirationlegal-statusCritical

Links

Classifications

Landscapes

Abstract

The invention discloses a kind of safe data transmission methods and device, are related to information security field.The described method includes: system, which generates random number, as current random number and is sent to terminal device, first key and the second key are calculated according to current random number and preset key corresponding with terminal device;Transmitting message is treated using first key to be encrypted to obtain the first data field, according to preset protocol header data organization header field, calculates the first check value using the second key pair header field and the first data field;According to header field, the first data field and the first check value organization instruction and it is sent to terminal device;The reply data for receiving and parsing through terminal device return obtains operating result, such as operates successfully, then updates current random number according to predetermined manner, terminates;Such as operation failure, then terminate.Technical solution in the present invention carries out encryption and decryption using different data keys every time when terminal device and system carry out data transmission, and ensure that the safety of data transmission.

Description

Safe data transmission method and device
Technical Field
The present invention relates to the field of information security, and in particular, to a secure data transmission method and apparatus.
Background
In the process of data transmission of terminal equipment and a system, data needs to be encrypted; and the encryption of the data is completed by means of the symmetric keys stored in the terminal equipment and the system. In the prior art, a common method is to store the same fixed data as a symmetric key in the terminal device and the background system respectively, and encrypt the data by using the fixed and unchangeable symmetric key every time of data transmission, so that the security of data transmission is reduced, and the problems that the data is easy to crack by a hacker and the data is tampered exist.
Disclosure of Invention
The invention aims to overcome the defects of the prior art and provide a safe data transmission method and device.
In one aspect, the present invention provides a secure data transmission method, including:
step A1: the system generates a random number as a current random number, sends the current random number to the terminal equipment, and calculates a first key and a second key according to the current random number and a preset key corresponding to the terminal equipment;
step A2: the system encrypts a message to be transmitted by using the first key to obtain a first data domain, organizes a header domain according to preset protocol header data, and calculates a first check value for the header domain and the first data domain by using the second key;
step A3: the system organizes an instruction according to the header field, the first data field and the first check value and sends the instruction to the terminal equipment;
step A4: the system receives and analyzes response data returned by the terminal equipment to obtain an operation result, if the operation result is successful, the current random number is updated according to a preset mode, and the operation is finished; and if the operation result is operation failure, ending the operation.
The invention also provides a safe data transmission method, which comprises the following steps:
step B1: the terminal equipment receives the random number sent by the system and takes the random number as the current random number;
step B2: the terminal equipment receives the instruction sent by the system and analyzes the received instruction to obtain a header field, a first data field and a first check value;
step B3: the terminal equipment calculates a first key and a second key according to the current random number and a preset key of the terminal equipment;
step B4: the terminal device verifies the header field and the first data field according to the second key and the first verification value, and if the verification is successful, step B5 is executed; if the verification fails, returning an error code to the system, and ending;
step B5: the terminal equipment decrypts the first data domain by using the first secret key to obtain a transmission message, sends the transmission message to a card and receives an operation result returned by the card, if the operation result is successful, organizes a successful response data and returns the successful response data to the system, updates the current random number according to a preset mode, and finishes; and if the operation result is operation failure, organizing failure response data and returning the failure response data to the system, and ending.
In another aspect, the present invention provides a secure data transmission system, including:
the generating module is used for generating a random number as a current random number;
the first sending module is used for sending the current random number generated by the generating module to the terminal equipment;
the first calculation module is used for calculating a first key and a second key according to the current random number and a preset key corresponding to the terminal equipment;
the encryption module is used for encrypting the message to be transmitted by using the first key calculated by the first calculation module to obtain a first data domain;
the first organizing module is used for organizing the current header field according to preset protocol header data;
a second calculation module, configured to calculate a first check value for the header field and the first data field using the second key calculated by the first calculation module;
a second organizing module for organizing instructions according to the header field, the first data field, and the first check value;
the second sending module is used for sending the instruction organized by the second organizing module to the terminal equipment;
the receiving module is used for receiving response data returned by the terminal equipment;
the analysis module is used for analyzing the response data received by the receiving module to obtain an operation result;
and the updating module is used for updating the current random number according to a preset mode when the operation result obtained by the analyzing module is successful.
The present invention also provides a secure data transmission device, comprising:
the first receiving module is used for receiving the random number sent by the system and taking the random number as the current random number;
the second receiving module is used for receiving the instruction sent by the system;
the analysis module is used for analyzing the instruction received by the second receiving module to obtain a header field, a first data field and a first check value;
the first calculation module is used for calculating a first key and a second key according to a current random number and a preset key of the first calculation module, wherein the current random number is the same as the random number in the system;
a checking module, configured to check the header field and the first data field according to the second key and the first check value;
the sending module is used for returning an error code to the system when the verification of the verification module fails, and ending;
the decryption module is used for decrypting the first data domain by using the first key to obtain a transmission message when the verification of the verification module is successful;
the sending module is also used for sending the transmission message obtained by the decryption module to a card;
the receiving module is also used for receiving an operation result returned by the card;
the organizing module is used for organizing the successful response data when the operation result received by the receiving module is successful; the receiving module is also used for organizing failure response data when the operation result received by the receiving module is operation failure;
the sending module is further configured to return successful response data organized by the organization module to the system; the system is also used for returning failure response data organized by the organization module to the system;
and the updating module is used for updating the current random number according to a preset mode after the sending module returns the successful response data organized by the organization module to the system.
Compared with the prior art, the invention has the following advantages:
when the terminal equipment and the system carry out data transmission, different keys are adopted to encrypt and decrypt the data each time, so that the safety of data transmission is ensured.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments of the present invention or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and other drawings can be obtained by those skilled in the art without creative efforts.
Fig. 1 is a flowchart illustrating a processing method of a system in a secure data transmission method according to an embodiment of the present invention;
fig. 2 is a flowchart of a processing method of a terminal device in a secure data transmission method according to an embodiment of the present invention;
fig. 3 is a flowchart of a processing method of a system in a secure data transmission method according to a second embodiment of the present invention;
fig. 4 is a flowchart of a processing method of a terminal device in a secure data transmission method according to a third embodiment of the present invention;
fig. 5 is a block diagram illustrating a module of a secure data transmission system according to a fourth embodiment of the present invention;
fig. 6 is a block diagram illustrating module components of a secure data transmission device according to a fifth embodiment of the present invention.
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.
The method is applied to a data interaction process comprising a system, terminal equipment and a card, wherein the system sends data to the card through the terminal equipment, the card executes corresponding operation according to the data sent by the terminal equipment to obtain an operation result, and the operation result is returned to the system through the terminal equipment; data interaction is performed between the terminal device and the system by using an application program in a PC (personal computer) end or a mobile terminal as a transmission medium, for example: application programs in computers, application programs in mobile phones, and the like.
Example one
An embodiment of the present invention provides a system processing method in a secure data transmission method, as shown in fig. 1, including:
step A1: the system generates a random number as a current random number, sends the current random number to the terminal equipment, and calculates a first key and a second key according to the current random number and a preset key corresponding to the terminal equipment;
in this embodiment, before step a1, sending the current random number to the terminal device, specifically:
the system organizes a setting command according to the current random number and sends the setting command to the terminal equipment;
or,
the system encrypts the current random number according to a preset encryption algorithm to obtain a ciphertext random number, and sends the ciphertext random number to the terminal equipment;
in this embodiment, in step a1, after sending the current random number to the terminal device, the method further includes:
step a: and the system receives a third check value returned by the terminal equipment, judges whether the received third check value is correct or not, calculates a first key and a second key according to the current random number and a preset key corresponding to the terminal equipment if the received third check value is correct, and otherwise, finishes the operation.
In the step a, determining whether the received third check value is correct specifically includes:
the system performs preset operation on the current random number and first preset data to obtain an operation result, reads data on preset bytes in the operation result to serve as a second check code, judges whether a second check value is equal to the second check code, and if yes, confirms that the second check value is correct, otherwise confirms that the second check value is incorrect; preferably, the first preset data is 0000000000000000.
Further, in this embodiment, before the step a1, the method further includes:
the system receives the equipment information of the terminal equipment sent by the application program and stores the received equipment information;
in step a1, after sending the current random number to the terminal device, the method further includes: the system acquires a preset first preset key and a preset second preset key corresponding to the terminal equipment according to the stored equipment information;
correspondingly, in step a1, the first key and the second key are calculated according to the current random number and the preset key corresponding to the terminal device, specifically: the system uses a first preset key to encrypt the current random number according to a preset algorithm to obtain a first key, and uses a second preset key to encrypt the current random number to obtain a second key.
In this embodiment, the random number is specifically data with a length of 16 bytes; for example, the current random number is: 2a5B67c264f979EA3D5c46B87a32dec4, the first preset key is B2a4c87D52E4f6c2514a3B5D85c9E3f0, the second preset key is 4a1989E4a1917E984a1989E4a1917E98, the calculated first key is 51ADEDEC586947D8B3CE0DB06E26FA37, and the calculated second key is DE4E1819E0DADF44EA602a 846DC 3A.
Further, in this embodiment, in step a1, the system generates a random number as a current random number, and sends the current random number to the terminal device, which may further be:
the system sends a request for obtaining the random number to the terminal equipment, receives the random number returned by the terminal equipment, and takes and stores the received random number as the current random number.
Step A2: the system encrypts a message to be transmitted by using a first key to obtain a first data domain, organizes a header domain according to preset protocol header data, and calculates a first check value for the header domain and the first data domain by using a second key;
in this embodiment, the encrypting the packet to be transmitted by using the first key by the system to obtain the first data field specifically includes:
step D1: the system judges whether the message to be transmitted needs to be filled, if so, preset data are filled in the preset position of the message to be transmitted to obtain first data to be encrypted, and the step D2 is executed, otherwise, the message to be transmitted is used as the first data to be encrypted, and the step D2 is executed;
in this embodiment, the system determines whether the packet to be transmitted needs to be filled, specifically:
the system sums the length of the message to be transmitted with the first preset length, judges whether the sum is integral multiple of the second preset length, and confirms that the message to be transmitted does not need to be filled if the sum is integral multiple of the second preset length; otherwise, confirming that the message to be transmitted needs to be filled;
preferably, the first preset length is 2 bytes and is used for filling the length of the message to be transmitted at the left end of the message to be transmitted, and the second preset length is 8 bytes.
Further, filling preset data in a predetermined position of the message to be transmitted to obtain first data to be encrypted, specifically:
filling the length of the message to be transmitted at the left end of the message to be transmitted, and filling one byte of second preset data and the third preset data with the least bytes at the right end of the message to be transmitted, so that the length of the first data to be encrypted is integral multiple of the second preset length;
preferably, in this embodiment, the second preset data is 80, and the third preset data is 00.
Step D2: the system uses the first key to encrypt the first data to be encrypted to obtain first ciphertext data, and the obtained first ciphertext data is used as a first data domain.
Further, in this embodiment, the data on the Lc byte in the header field is specifically the sum of the length of the first data field and the second length, and preferably, the second length is 4 bytes, that is, the length of the first check value is 4 bytes;
further, in this embodiment, the system uses the second key to calculate the first check value for the header field and the first data field, specifically:
the system fills fourth preset data in the data after the head domain and the first data domain are sequentially spliced to obtain first data to be verified, calculates the first data to be verified by using a second secret key according to a preset algorithm to obtain a calculation result, and reads data on preset bytes in the calculation result to serve as a first verification value; preferably, the fourth data is 8000000000000000.
For example, in this embodiment, the message to be transmitted is 010C00a4040007a0000003330101020E04DA9F790a0000000100003def5b86, and the first data to be encrypted obtained after filling is 001F010C00a4040007a0000003330101020E04DA9F790a0000000100003def5b 868000000000; the first data domain obtained by encrypting the first data to be encrypted by using the first key is 7B7376FB9B1E0B75DA7F01BEA2CDAF5E75923506ABEDF2712979BFD336276DA033ADF348C83188B4, the header domain formed according to the preset protocol header data is 7E5000002C, and the first check value calculated according to the second key header domain and the first data domain is 3DD52B 8F.
Step A3: the system organizes the instruction according to the header field, the first data field and the first check value and sends the instruction to the terminal equipment;
specifically, the system sequentially splices the header field, the first data field, and the first check value to obtain an instruction, for example, the instruction organized according to the header field, the first data field, and the first check value is
7E5000002C7B7376FB9B1E0B75DA7F01BEA2CDAF5E75923506ABEDF2712979BFD336276DA033ADF348C83188B43DD52B8F。
Step A4: the system receives and analyzes response data returned by the terminal equipment to obtain an operation result, if the operation result is successful, the current random number is updated according to a preset mode, and the operation is finished; and if the operation result is operation failure, ending the operation.
In this embodiment, the system receives and analyzes response data returned by the terminal device to obtain an operation result, specifically:
the system analyzes the received response data to obtain a second data domain and a second check value, the second data domain is checked according to a second secret key and the second check value, if the check is successful, the second data domain is decrypted according to the first secret key to obtain second data to be encrypted, the second data to be encrypted is analyzed to obtain plaintext response data, and the plaintext response data is analyzed to obtain an operation result; and if the verification fails, ending.
For example, the received response data is 164F22B44E1894BE308AFF09AB36F390AB08D6C6, wherein the second data field is 164F22B44E1894BE308AFF09AB36F390, the second check value is AB08D6C6, the second data to BE encrypted is 00080102900002029000800000000000, the plaintext response data is 0102900002029000, and the obtained operation result is 9000, which indicates that the operation is successful.
Further, in this embodiment, the updating the current random number according to a preset manner specifically includes:
the system changes the current random number by a preset step length, and takes the value after changing the preset step length as the current random number;
or,
the system takes the current random number as a seed random number, generates a new random number according to the seed random number, and takes the new random number as the current random number;
or,
the system calculates the current random number according to a preset algorithm to obtain a calculation result, and the calculation result is used as the current random number.
For example, increasing the value of the current random number by 1 results in 2a5b67c264f979ea3d5c46b87a32dec5, and taking 2a5b67c264f979ea3d5c46b87a32dec5 as the current random number;
further, in this embodiment, step a4 further includes:
and when the operation result is that the operation is successful, if the message is still to be transmitted, returning to the step A1.
The embodiment also provides a processing method of a terminal device in a secure data transmission method, as shown in fig. 2, including:
step B1: the terminal equipment receives the random number sent by the system and takes the random number as the current random number;
in this embodiment, step B1 specifically includes:
the terminal equipment receives a setting command sent by the system, analyzes the setting command to obtain a random number, and takes the obtained random number as a current random number;
or,
the terminal equipment receives the ciphertext random number sent by the system, decrypts the ciphertext random number according to a preset encryption algorithm to obtain a random number, and the obtained random number is used as a current random number;
in this embodiment, after the step B1, the method further includes: the terminal equipment calculates a third check value according to the received random number and sends the third check value to the system;
wherein, calculating the third check value according to the received random number specifically comprises: the terminal device performs preset operation on the received random number and first preset data to obtain an operation result, and reads data on preset bytes in the operation result to serve as a second check value, wherein preferably the first preset data is 0000000000000000.
Further, in this embodiment, the random number is specifically data with a length of 16 bytes, for example, the current random number is 2a5b67c264f979ea3d5c46b87a32dec 4.
Further, in this embodiment, step B1 may further be:
step f: the terminal equipment receives a random number acquisition request sent by the system and returns a preset random number serving as a current random number to the system.
Step B2: the terminal equipment receives an instruction sent by the system and analyzes the received instruction to obtain a header field, a first data field and a first check value;
step B3: the terminal equipment calculates a first key and a second key according to the current random number and a preset key of the terminal equipment;
specifically, the terminal device reads a first preset key and a second preset key preset by the terminal device, encrypts the current random number by using the first preset key according to a preset algorithm to obtain the first key, and encrypts the current random number by using the second preset key to obtain the second key; preferably, the preset algorithm is a 3DES operation;
in the present embodiment, the first preset key and the second preset key are preset inside the terminal device at the time of terminal device factory, for example, the first preset key is b2a4c87d52E4f6c2514a3b5d85c9E3f0, and the second preset key is 4a1989E4a1917E984a1989E4a1917E 98; the first key obtained by encrypting the current random number with the first preset key is 51ADEDEC586947D8B3CE0DB06E26FA37, and the second key obtained by encrypting the current random number with the second preset key is DE4E1819E0DADF44EA602AE5a846DC 3A.
Step B4: the terminal equipment verifies the header field and the first data field according to the second key and the first verification value, and if the verification is successful, the step B5 is executed; if the verification fails, returning an error code to the system, and ending;
specifically, the terminal device fills fourth preset data with data after sequentially splicing a header field and a first data field to obtain first data to be verified, calculates the first data to be verified by using a second secret key according to a preset algorithm to obtain a calculation result, reads data on preset bytes in the calculation result to serve as a first check code, judges whether the first check code is the same as the first check value, if so, confirms that the verification is successful, and otherwise, confirms that the verification is failed; preferably, the fourth preset data is 8000000000000000;
step B5: the terminal equipment decrypts the first data domain according to the first secret key to obtain a transmission message, sends the transmission message to the card and receives an operation result returned by the card, if the operation result is successful, organizes successful response data and returns the response data to the system, updates the current random number according to a preset mode, and finishes; and if the operation result is operation failure, organizing failure response data and returning the failure response data to the system, and ending.
In this embodiment, the terminal device decrypts the first data field according to the first key to obtain the transmission packet, which specifically includes:
the terminal equipment decrypts the first data domain by using the first secret key according to a preset algorithm to obtain first data to be encrypted, analyzes the first data to be encrypted to obtain the length of a transmission message, and reads corresponding data according to the length of the transmission message to obtain the transmission message.
In this embodiment, the terminal device organizes the response data, which specifically includes:
the terminal equipment organizes plaintext response data according to the operation result, organizes second data to be encrypted according to the plaintext response data, encrypts the second data to be encrypted by using a first secret key to obtain a second data field, fills fourth preset data in the second data field to obtain second data to be verified, calculates a second verification value for the second data to be verified by using a second secret key according to a preset algorithm, and splices the second data field and the second verification value to obtain response data.
Further, in this embodiment, the updating the current random number according to a preset manner specifically includes:
the terminal equipment changes the current random number by a preset step length, and takes the value after changing the preset step length as the current random number;
or,
the terminal equipment takes the current random number as a seed random number, generates a new random number according to the seed random number, and takes the new random number as the current random number;
or,
and the terminal equipment calculates the current random number according to a preset algorithm to obtain a calculation result, and the calculation result is used as the current random number.
Further, in this embodiment, after updating the current random number according to the preset manner in step B5, the method further includes:
and C, the terminal equipment judges whether the time length of waiting for receiving the data exceeds the preset time length, if so, the terminal equipment is powered off, and if not, the terminal equipment returns to the step B2.
Example two
An embodiment of the present invention provides a processing method for a system in a secure data transmission method, where after an application program sends acquired device information of a terminal device and transaction data input by a user to the system, as shown in fig. 3, the system executes the following operations:
step 201: the system receives the equipment information and the transaction data from the terminal equipment of the application program, saves the equipment information, takes the transaction data as the current transaction data, and executes the step 202;
preferably, in this embodiment, the device information is a device serial number;
for example, the received device information is 2016052611122233 and the transaction data is 100.00, wherein the transaction data represents a top-up of 100 dollars.
Step 202: the system generates a random number, takes the random number as a current random number, organizes a setting command according to the current random number and sends the setting command to the terminal equipment;
in this embodiment, the random number is specifically data with a length of 16 bytes, for example, the system-generated random number is: 2a5b67c264f979ea3d5c46b87a32dec 4;
the setting command sent is: 7E53000010012a5b67c264f979ea3d5c46b87a32dec 4.
Further, in this embodiment, step 202 may further be: the system sends a request for obtaining the random number to the terminal equipment, receives the random number returned by the terminal equipment, and takes the random number as the current random number and stores the current random number.
Step 203: the system receives a third check value returned by the terminal equipment, judges whether the third check value is correct or not, if so, executes step 204, otherwise, returns transaction failure information to the terminal equipment, and ends;
specifically, the system performs preset operation on the current random number and first preset data to obtain an operation result, reads data on preset bytes in the operation result to serve as a third check code, judges whether a third check value is equal to the third check code, if so, confirms that the third check value is correct, and otherwise, confirms that the third check value is incorrect;
preferably, in this embodiment, the first preset data is 0000000000000000, the preset algorithm is 3DES operation, and the preset bytes are first to fourth bytes in the operation result;
for example, in this embodiment, the second check value received by the system is D49C25C6, the system performs 3DES operation on the current random number 2a5b67C264f979ea3D5C46b87a32dec4 and the first preset data 000000000000 to obtain an operation result D49C25C67C864FB2, and reads the data D49C25C6 on the first byte to the fourth byte of the operation result as the third check code, which is the same as the third check value, so as to confirm that the third check value is correct.
Further, in this embodiment, when the system returns the transaction failure information to the terminal device, the system further includes an application program in the PC or the mobile terminal displaying the transaction failure information.
Step 204: the system acquires and stores a first preset key and a second preset key of corresponding terminal equipment according to the stored equipment information;
specifically, the first preset key and the second preset key are preset and stored in the terminal device and the system when the terminal device leaves the factory;
specifically, the system searches the same device information as the stored device information in the security database, reads a first preset key and a second preset key corresponding to the device information, and stores the first preset key and the second preset key in a preset storage area; for example, the first preset key is b2a4c87d52E4f6c2514a3b5d85c9E3f0, and the second preset key is 4a1989E4a1917E984a1989E4a1917E 98.
Step 205: the system encrypts the current random number by using the stored first preset key to obtain a ciphertext first preset key, and the ciphertext first preset key is used as the current first key;
preferably, the system performs 3DES operation on the stored first preset key and the current random number to obtain a ciphertext first preset key, and uses the ciphertext first preset key as the current first key;
for example, in this embodiment, the current random number 2a5B67c264f979ea3D5c46B87a32dec4 is subjected to 3DES operation on the current random number 2a5B67c264f979ea3D 46B87a32dec4 according to the saved first preset key B2a4c87D52E4f 2514a3B5D85c9E3f0 to obtain the ciphertext first preset key 51ADEDEC586947D8B3CE0DB06E26FA37, which is used as the current first key.
Step 206: the system encrypts the current random number by using the stored second preset key to obtain a ciphertext second preset key, and the ciphertext second preset key is used as the current second key;
preferably, the system performs 3DES operation on the stored second preset key and the current random number to obtain a ciphertext second preset key, and uses the ciphertext second preset key as the current second key;
for example, in this embodiment, the stored second preset key 4a1989E4a1917E984a1989E4a1917E98 and the current random number 2a5b67c264f979EA3d5c46b87a32dec4 are subjected to 3DES operation to obtain a ciphertext second preset key DE4E1819E0DADF44EA602AE5a846DC3A, which is used as the current second key.
Step 207: the system organizes a message to be transmitted according to the current transaction information, and takes the organized message to be transmitted as the current message to be transmitted;
for example, the system organizes the current message to be transmitted to 010C00A4040007A0000003330101020E04DA9F790A0000000100003def5b86 according to the current transaction information of "recharge 100.00 yuan".
Step 208: the system encrypts a current message to be transmitted by using a current first key to obtain a current ciphertext message to be transmitted, and takes the current ciphertext message to be transmitted as a current first data domain;
in this embodiment, step 208 specifically includes:
step 208-1: the system judges whether the current message to be transmitted needs to be filled, if so, the step 208-2 is executed, otherwise, the step 208-4 is executed;
specifically, the system sums the length of the current message to be transmitted with a first preset length, judges whether the sum is an integral multiple of a second preset length, if so, confirms that the current message to be transmitted does not need to be filled, otherwise, confirms that the current message to be transmitted needs to be filled;
preferably, in this embodiment, the first preset length is 2 bytes and is used to fill the length of the current packet to be transmitted, and the second preset length is 8 bytes.
Step 208-2: the system fills preset data in a preset position of a current message to be transmitted to obtain current first data to be encrypted, so that the length of the current first data to be encrypted is integral multiple of a second preset length;
preferably, the system fills the length of the current message to be transmitted at the left end of the current message to be transmitted, occupies 2 bytes, and fills one byte of second preset data and the least byte of third preset data at the right end of the current message to be transmitted; preferably, the second preset data is 80, and the third preset data is 00;
for example, in this embodiment, the length of the current packet to be transmitted is 31 bytes, and the length is converted into a binary representation of 001F, which indicates that 00 of 6 bytes needs to be filled; filling the length 001F of the current message to be transmitted at the left end of the current message to be transmitted, occupying 2 bytes, filling the right end of the current message to be transmitted with 80 bytes of 1 byte and 00 of 6 bytes, and obtaining the current first data to be encrypted 001F010C00A4040007A0000003330101020E04DA9F790A0000000100003def5b868000000000, wherein the length of the current data to be encrypted is 40 bytes.
Step 208-3: the system encrypts current first to-be-encrypted data by using a current first key to obtain a current first ciphertext to-be-transmitted message, and takes the current first ciphertext to-be-transmitted message as a current first data domain;
preferably, the system encrypts the current first data to be encrypted by using the current first key according to the 3DES algorithm;
for example, in this embodiment, the system encrypts the current first data to be encrypted 001F010C00a4040007a0000003330101020E04DA9F790a0000000100003def5B8680000000000000 according to the 3DES algorithm by using the current first key 51ADEDEC586947D8B3CE0DB06E26FA37, and the obtained current first data field is 7B7376FB9B1E0B75DA7F01BEA2CDAF5E75923506ABEDF2712979BFD336276DA ADF348C83188B 4.
Step 208-4: the system takes a current message to be transmitted as current first data to be encrypted, encrypts the current first data to be encrypted by using a current first key to obtain a current first ciphertext message to be transmitted, and takes the current first ciphertext message to be transmitted as a current first data domain;
specifically, the system encrypts the current message to be transmitted by using the current first key according to the 3DES algorithm to obtain the current first ciphertext message to be transmitted.
Step 209: the system organizes the current header field according to the preset protocol header data;
in this embodiment, the header field specifically includes CLA, INS, P1, P2, and Lc, where Lc is specifically a sum of a length of the current first data field and a second length, where the second length is 4 bytes, that is, a length of the current first check value obtained through checking;
for example, in the present embodiment, the current header field organized is 7E 5000002C.
Step 210: the system calculates a current first check value for the current head field and the current first data field by using a current second key, organizes a current instruction according to the current head field, the current first data field and the current first check value, and sends the current instruction to the terminal equipment;
specifically, the system fills fourth preset data with data after sequentially splicing a current header field and a current first data field to obtain current first data to be verified, calculates the current first data to be verified by using a current second key according to a preset algorithm to obtain a calculation result, takes data on preset bytes in the calculation result as a current first verification value, and sequentially splices the current header field, the current first data field and the current first verification value to obtain a current transaction instruction;
preferably, the fourth preset data is 8000000000000000, the preset algorithm is 3DES operation, and the preset bytes are the first byte to the fourth byte in the calculation result;
for example, in the present embodiment, the obtained current first to-be-verified data is 7E5000002C7B7376FB9B1E0B75DA7F01BEA2CDAF5E75923506 abef 2712979BFD336276DA033ADF348C83188B 480000000000000000000, the calculation result calculated on the current first to-be-verified data by using the current second key DE4E1819E0DADF44EA602AE5a846DC3A is 3DD52B8FD0E97498, the current first verification value is 3DD52B8F, and the current instruction is 7E5000002C7B7376FB9B1E0B75DA7F01BEA2CDAF5E75923506 abef 2712979BFD336276DA033ADF348C83188B43DD52B 8F.
Step 211: the system verifies the current response data according to the current second key, if the verification is successful, step 212 is executed; if the verification fails, returning transaction ending information to the terminal equipment, and ending;
it should be noted that, in this embodiment, the current response data is specifically in the form of "current second data field + current second check value";
specifically, the system analyzes the current response data to obtain a second data domain and a second check value, calculates a current second check code for the current second data domain according to a current second key, judges whether the calculated current second check code is the same as the current second check value, if so, confirms that the check is successful, otherwise, confirms that the check is failed;
more specifically, the system reads data on the last four bytes in the current response data to obtain a current second check value, and takes other data except the current second check value as a current second data field;
for example, in the present embodiment, the current response data is 164F22B44E1894BE308AFF09AB36F390AB08D6C6, the current second check value is AB08D6C6, and the current second data field is 164F22B44E1894BE308AFF09AB36F 390; the system calculates the current second key DE4E1819E0DADF44EA602AE5a846DC3A to the current second data domain to obtain the current second check code AB08D6C6, and confirms that the current response data is legal.
Further, in this embodiment, when the system returns the transaction failure information to the terminal device, the method further includes: and displaying the transaction failure by an application program in the PC terminal or the mobile terminal.
Step 212: the system decrypts the current response data according to the current first key to obtain current plaintext response data, analyzes the current plaintext response data to obtain a current operation result, and if the current operation result is successful, executes step 213; if the current operation result is operation failure, the transaction is failed, and the operation is finished;
specifically, the system decrypts the current second data field by using the current first key to obtain current second data to be encrypted, analyzes the second data to be encrypted to obtain current plaintext response data, and analyzes the current plaintext response data to obtain a current operation result;
more specifically, the system decrypts the current second data field by using the current first key according to the 3DES algorithm to obtain the current second data to be encrypted, reads the data on the first two bytes in the current second data to be encrypted to obtain the length of the current plaintext response data, reads the corresponding data after the third byte (including the third byte) in the current second data to be encrypted according to the length of the current plaintext response data to obtain the current plaintext response data, and analyzes the current plaintext response data to obtain the current operation result;
for example, in the present embodiment, the system decrypts the current second data field 164F22B44E1894BE308AFF09AB36F390 by using the current first key 51ADEDEC586947D8B3CE0DB06E26FA37 according to the 3DES algorithm to obtain 00080102900002029000800000000000 as the current second data to BE encrypted, 0102900002029000 as the current plaintext response data, and 9000 as the obtained current operation result, that is, the operation is successful.
Further, in this embodiment, when the current operation result is an operation failure, the method further includes: and displaying the transaction failure by an application program in the PC terminal or the mobile terminal.
Step 213: the system judges whether the transaction is finished, if yes, the system finishes the transaction, otherwise, the system updates the current random number according to a preset mode, takes the updated random number as the current random number, takes the current operation result as the current transaction information, and returns to the step 205.
In this embodiment, the current random number is updated according to a preset manner, and the updated random number is used as the current random number, which specifically includes:
the system changes the current random number by a preset step length, and takes the value after changing the preset step length as the current random number;
or,
the system takes the current random number as a seed random number, generates a new random number according to the seed random number, and takes the new random number as the current random number;
or,
the system calculates the current random number according to a preset algorithm to obtain a calculation result, and the calculation result is used as the current random number.
It should be noted that the system updates the current random number in the same manner as the terminal device.
Preferably, in this embodiment, the current random number is obtained by increasing the value of the current random number by 1, for example, obtaining the current random number 2a5b67c264f979ea3d5c46b87a32dec 5;
further, in this embodiment, when the transaction is ended, the method further includes: and displaying the transaction ending information by an application program in the PC terminal or the mobile terminal.
Further, in this embodiment, step 202 may be preceded by:
step e 1: the system judges whether the current transaction is the first transaction, if so, step 202 is executed, otherwise, step e2 is executed;
specifically, the system judges whether the equipment information is received, if so, the current transaction is determined to be the first transaction, and if not, the current transaction is determined not to be the first transaction.
Step e 2: after the system changes the current random number by the preset step size, the system performs step 205 as the current random number.
Accordingly, step 213 is replaced with:
step 213': and e, judging whether the transaction is finished or not by the system, if so, finishing, and if not, taking the current operation result as current transaction data and returning to the step e 1.
EXAMPLE III
An embodiment of the present invention provides a processing method for a terminal device in a secure data transmission method, as shown in fig. 4, including:
step 301: the terminal equipment waits for and receives a setting command sent by the system, analyzes the setting command to obtain a random number, and takes the random number as a current random number to be stored;
specifically, the terminal device receives a setting command sent by the system, reads data from the 7 th byte to the last byte in the setting command to obtain a random number, and takes the random number as a current random number and stores the random number;
in this embodiment, the random number is specifically data with a length of 16 bytes; for example, the terminal device receives a setting command of 7E53000010012a5b67c264f979ea3d5c46b87a32dec4 and reads a random number of 2a5b67c264f979ea3d5c46b87a32dec 4.
In this embodiment, step 301 may further be: the terminal equipment receives a random number acquisition request sent by the system and returns a preset random number serving as a current random number to the system.
Further, in this embodiment, before step 301, the method further includes: the terminal equipment receives an equipment information acquisition instruction sent by the application program, reads own equipment information and sends the equipment information to the application program;
preferably, in this embodiment, the device information is specifically a serial number of the device, and the command for obtaining the device information received by the terminal device is 7E 52000001;
more specifically, in the instruction to acquire device information, it is preferable that when the data on the fifth byte is 01, the serial number of the terminal device is acquired, when the data on the fifth byte is 02, the bluetooth name of the terminal device is acquired, when the data on the fifth byte is 03, the firmware version number of the terminal device is acquired, when the data on the fifth byte is 04, the state of the card is acquired, and when the data on the fifth byte is 00, all the above information is acquired;
for example, in the present embodiment, the terminal device reads its own serial number 2016052611122233.
Step 302: the terminal equipment calculates a third check value according to the current random number and sends the third check value to the system;
specifically, the terminal device performs preset operation on the current random number and first preset data to obtain an operation result, reads data on preset bytes in the operation result to serve as a third check value, and sends the third check value to the system;
preferably, in this embodiment, the first preset data is 0000000000000000, the preset algorithm is 3DES operation, and the preset bytes are first to fourth bytes in the operation result;
for example, in this embodiment, the terminal device performs 3DES operation on the current random number 2a5b67C264f979ea3D5C46b87a32dec4 and 0000000000000000 to obtain an operation result D49C25C67C864FB2, and the terminal device reads data D49C25C6 on the first byte to the fourth byte of the operation result as a third check value and sends the third check value to the system;
it should be noted that, in this embodiment, after receiving the third check value, the system checks the third check value, and when the checking fails, the method further includes: and the terminal equipment receives the transaction ending information returned by the system, and an application program in the PC terminal or the mobile terminal displays the transaction failure information.
Step 303: the terminal equipment waits for and receives an instruction sent by the system and takes the instruction as a current instruction;
for example, the current instruction received is 7E5000002C7B7376FB9B1E0B75DA7F01BEA2CDAF5E75923506ABEDF2712979BFD336276DA033ADF348C83188B43DD52B 8F.
Step 304: the terminal equipment analyzes the current instruction to obtain a current header field, a current first data field and a current first check value;
specifically, the terminal device reads data in the first five bytes of the current instruction to obtain a current header field, reads data in the last four bytes of the current instruction to obtain a current first check value, and the middle data is a current first data field;
for example, in this embodiment, according to the current command, the current header field is 7E5000002C, the current first data field is 7B7376FB9B1E0B75DA7F01BEA2CDAF5E75923506ABEDF2712979BFD336276DA033ADF348C83188B4, and the current first check value is 3DD52B 8F.
Step 305: the terminal equipment reads a first preset key preset by the terminal equipment, encrypts a current random number by using the first preset key to obtain a ciphertext first preset key, and takes the ciphertext first preset key as the current first key;
in this embodiment, the first preset key is predetermined and stored inside the terminal device when the terminal device is shipped from the factory, for example, the first preset key is b2a4c87d52e4f6c2514a3b5d85c9e3f 0;
preferably, the system performs DES operation on the first preset key and the current random number to obtain a ciphertext first preset key, and uses the ciphertext first preset key as the current first key;
for example, in this embodiment, the first preset key B2a4c87D52E4f6c2514a3B5D85c9E3f0 and the current random number 2a5B67c264f979ea3D5c46B87a32dec4 are subjected to 3DES operation to obtain 51ADEDEC586947D8B3CE0DB06E26FA37, which is used as the current first key.
Step 306: the terminal equipment reads a second preset key preset by the terminal equipment, encrypts the current random number by using the second preset key to obtain a ciphertext second preset key, and takes the ciphertext second preset key as the current second key;
in the present embodiment, the second preset key is predetermined at the time of factory shipment of the terminal device and is stored inside the terminal device, for example, the second preset key is 4a1989E4a1917E984a1989E4a1917E 98;
preferably, in this embodiment, the system performs 3DES operation on the current second preset key and the current random number to obtain a ciphertext second preset key, and uses the ciphertext second preset key as the current second key;
for example, in the present embodiment, the second preset key 4a1989E4a1917E984a1989E4a1917E98 and the current random number 2a5b67c264f979EA3d5c46b87a32dec4 are subjected to 3DES operation to obtain DE4E1819E0DADF44EA602AE5a846DC3A, which is used as the current second key;
alternatively, in this embodiment, the order of step 305 and step 306 may be reversed.
Step 307: the terminal equipment verifies the current head field and the current first data field according to the current second secret key and the current first verification value, if the verification is successful, the step 308 is executed, if the verification is failed, an error code is returned to the system, and the operation is finished;
specifically, the terminal device fills fourth preset data with data after sequentially splicing a current header field and a current first data field to obtain current first data to be verified, calculates the current first data to be verified by using a second key according to a preset algorithm to obtain a calculation result, reads data on preset bytes in the calculation result to serve as a current first verification code, judges whether the current first verification code is the same as the current first verification value, if so, verifies that the verification is successful, and otherwise, verifies that the verification is failed;
preferably, the fourth preset data is 8000000000000000, the preset algorithm is 3DES operation, and the preset bytes are the first byte to the fourth byte in the calculation result;
for example, in this embodiment, the obtained current first to-be-verified data is 7E5000002C7B7376FB9B1E0B75DA7F01BEA2CDAF5E75923506 abef 2712979BFD336276DA033ADF348C83188B 480000000000000000000, the calculation result calculated on the current first to-be-verified data by using the current second key DE4E1819E0DADF44EA602AE5a846DC3A is 3DD52B8FD0E97498, and the current first check code is 3DD52B8F, so as to confirm that the current first check value is correct.
Further, in this embodiment, when the transaction fails, the method further includes: and displaying the transaction failure information by an application program in the PC terminal or the mobile terminal.
Step 308: the terminal equipment decrypts the current instruction by using the current first key to obtain a current transmission message;
specifically, the terminal device decrypts a current first data domain by using a current first key according to a preset algorithm to obtain current first data to be encrypted, analyzes the current first data to be encrypted to obtain the length of a current transmission message, and reads corresponding data according to the length of the current transmission message to obtain the current transmission message;
more specifically, the terminal device decrypts a current first data domain by using a current first key according to a 3DES algorithm to obtain current first data to be encrypted, reads data on the first two bytes in the current first data to be encrypted to obtain the length of a current transmission message, and reads corresponding data after a third byte (including a third byte) in the current first data to be encrypted to obtain the current transmission message according to the length of the current transmission message;
for example, in this embodiment, the current first data field 7B7376FB9B1E0B75DA7F01BEA2CDAF5E75923506ABEDF2712979BFD336276DA033ADF348C83188B4 is decrypted by using the current first key 51ADEDEC586947D8B3CE0DB06E26FA37 according to the 3DES algorithm, so that the current first data to be encrypted obtained is 001F010C00a4040007a0000003330101020E04DA9F790a0000000100003def5B868000000000, the length of the current transmission packet is 001F, and the current transmission packet is 010C00a4040007a0000003330101020E04DA9F790a0000000100003def5B 86.
Step 309: the terminal equipment sends a current transmission message to the card and receives a current operation result returned by the card, if the current operation result is successful, the step 310 is executed, if the current operation result is operation failure, failure response data is organized, the failure response data is returned to the system as the current response data, and the operation is finished;
in this embodiment, step 309 further includes: when the terminal equipment has an error, the terminal equipment returns the error code as the current response data to the system, and the operation is finished;
further, in this embodiment, the method for organizing the failure response data is the same as the method for organizing the success response data, and is not described again.
Step 310: the terminal equipment organizes the current plaintext successful response data according to the current operation result;
for example, in this embodiment, the current successful plaintext response data of an organization is: 0102900002029000.
step 311: the terminal equipment encrypts the current plaintext successful response data according to the current first key to obtain current ciphertext successful response data, and the current ciphertext successful response data is used as a current second data domain;
in this embodiment, step 311 specifically includes:
step 311-1: the terminal equipment judges whether the current plaintext successful response data needs to be filled, if so, the step 311-2 is executed, otherwise, the step 311-4 is executed;
specifically, the terminal equipment sums the length of the current plaintext successful response data with a first preset length, judges whether the obtained sum is an integral multiple of a second preset length, if so, confirms that the current plaintext successful response data does not need to be filled, otherwise, confirms that the current plaintext successful response data needs to be filled;
preferably, in this embodiment, the first preset length is 2 bytes and is used to fill the length of the current plaintext successful response data, and the second preset length is 8 bytes;
step 311-2: the terminal equipment fills preset data in a preset position of the current plaintext successful response data to obtain current second data to be encrypted, so that the length of the current second data to be encrypted is integral multiple of the second preset length;
preferably, the terminal device fills the length of the current plaintext successful response data at the left end of the current plaintext successful response data and occupies 2 bytes, and fills 1 byte of second preset data and the minimum byte of third preset data at the right end of the current plaintext successful response data to obtain current second data to be encrypted, so that the length of the current second data to be encrypted is an integral multiple of 8 bytes; preferably, the second preset data is 80, and the third preset data is 00;
for example, in this embodiment, the length of the current plaintext response data is 8 bytes, and the length is converted into a binary representation of 0008, which indicates that 00 of 5 bytes needs to be filled; filling 0008 at the left end of the current plaintext response data, and occupying 2 bytes, and filling 80 bytes of 1 byte and 00 bytes of 5 bytes at the right end of the current plaintext response data, so as to obtain 00080102900002029000800000000000 of current second data to be encrypted;
step 311-3: the terminal equipment encrypts current second data to be encrypted by using a current first key to obtain current ciphertext successful response data, and the current ciphertext successful response data is used as a current second data domain;
specifically, the terminal equipment encrypts current second data to be encrypted by using a current first key according to a 3DES algorithm;
for example, in the present embodiment, the terminal device encrypts the current second data to BE encrypted according to the 3DES algorithm by using the current first key 51ADEDEC586947D8B3CE0DB06E26FA37, so as to obtain the current second data domain 164F22B44E1894BE308AFF09AB36F 390.
Step 311-4: and the terminal equipment takes the current plaintext successful response data as the current second data to be encrypted, encrypts the current second data to be encrypted by using the current first key to obtain current ciphertext successful response data, and takes the current ciphertext successful response data as the current second data domain.
Step 312: the terminal equipment calculates a current second check value for a current second data domain by using a current second key;
specifically, the terminal device performs data filling on a current second data domain to obtain current second data to be checked, calculates the current second data to be checked by using a current second key according to a 3DES algorithm to obtain a calculation result, and takes data on a first byte to a fourth byte of the calculation result as a current second check value;
preferably, the system fills fourth data at the right end of the current second data field to obtain current second data to be verified, where the fourth data is 8000000000000000;
for example, in the present embodiment, the current second data to BE verified is 164F22B44E1894BE308AFF09AB36F390800000000000, the calculation result calculated by using the current second key is AB08D6C64514AFAB, and the current second verification value is AB08D6C 6.
Step 313: the terminal equipment organizes the current successful response data according to the current second data domain and the current second check value, and sends the current successful response data as the current response data to the system;
specifically, the terminal device sequentially splices the current second data domain and the current second check value to obtain current successful response data, and sends the current successful response data serving as the current response data to the system;
for example, in this embodiment, the current response data organized by the terminal device according to the current second data domain and the current second check value is 164F22B44E1894BE308AFF09AB36F390AB08D6C 6.
Step 314: the terminal equipment updates the current random number according to a preset mode, takes the updated random number as the current random number, enters an idle state, takes the received instruction as the current instruction when receiving the instruction sent by the system, and returns to the step 304;
in this embodiment, the current random number is updated according to a preset manner, and the updated random number is used as the current random number, which specifically includes:
the terminal equipment changes the current random number by a preset step length, and takes the value after changing the preset step length as the current random number;
or,
the terminal equipment takes the current random number as a seed random number, generates a new random number according to the seed random number, and takes the new random number as the current random number;
or,
and the terminal equipment calculates the current random number according to a preset algorithm to obtain a calculation result, and the calculation result is used as the current random number.
Specifically, the terminal device and the system update the current random number in the same manner;
preferably, in this embodiment, a value obtained by increasing the value of the current random number by 1 is used as the current random number, for example, the current random number is 2a5b67c264f979ea3d5c46b87a32dec 5;
further, in this embodiment, when the terminal device is in the idle state for more than a preset duration, the terminal device is automatically turned off; preferably, in the present embodiment, the preset time period is 3 minutes.
Example four
An embodiment of the present invention provides a secure data transmission system, as shown in fig. 5, including:
a generating module 401, configured to generate a random number as a current random number;
a first sending module 402, configured to send the current random number generated by the generating module 401 to the terminal device;
a first calculating module 403, configured to calculate a first key and a second key according to the current random number and a preset key corresponding to the terminal device;
an encryption module 404, configured to encrypt the packet to be transmitted by using the first key calculated by the first calculation module 403 to obtain a first data field;
a first organizing module 405, configured to organize a current header field according to preset protocol header data;
a second calculation module 406, configured to calculate a first check value for the header field and the first data field using the second key calculated by the first calculation module 403;
a second organizing module 407 for organizing the instructions according to the header field, the first data field, and the first check value;
a second sending module 408, configured to send the instruction organized by the second organizing module 407 to the terminal device;
a receiving module 409, configured to receive response data returned by the terminal device;
the analyzing module 410 is configured to analyze the response data received by the receiving module 409 to obtain an operation result;
the updating module 411 is configured to update the current random number according to a preset manner when the operation result obtained by the parsing module 410 is that the operation is successful.
In this embodiment, the first sending module 402 is specifically configured to:
organizing a setting command according to the current random number, and sending the setting command to the terminal equipment;
or,
and encrypting the current random number according to a preset encryption algorithm to obtain a ciphertext random number, and sending the ciphertext random number to the terminal equipment.
The system in this embodiment further includes: a first judgment module;
correspondingly, the receiving module 409 is further configured to receive a third check value returned by the terminal device after the first sending module 402 sends the current random number generated by the generating module 401 to the terminal device;
the first judgment module is used for judging whether the third check value is correct or not;
the first calculating module 403 is specifically configured to: and when the first judgment module judges that the third check value is correct, calculating a first key and a second key according to the current random number and a preset key corresponding to the terminal equipment.
Further, in this embodiment, the first determining module is specifically configured to:
and performing preset operation on the current random number and the first preset data to obtain an operation result, reading data on preset bytes in the operation result to serve as a third check code, judging whether the third check value is equal to the third check code, if so, determining that the third check value is correct, and otherwise, determining that the third check value is incorrect.
The system in this embodiment further includes: a first acquisition module;
a receiving module 409, configured to receive the device information of the terminal device sent by the application before the generating module 401 generates the random number as the current random number, and store the received device information;
a first obtaining module, configured to obtain a preset first preset key and a preset second preset key corresponding to the terminal device according to the device information stored in the receiving module 409;
accordingly, the first calculating module 403 is specifically configured to: and encrypting the current random number by using a first preset key according to a preset algorithm to obtain a first key, and encrypting the current random number by using a second preset key to obtain a second key.
In this embodiment, the encryption module 404 specifically includes: the judgment sub-module, the filling sub-module, the acting sub-module and the encryption sub-module;
the judging submodule is used for judging whether the message to be transmitted needs to be filled;
the filling submodule is used for filling preset data in a preset position of the message to be transmitted to obtain first data to be encrypted when the judging submodule judges that the message to be transmitted needs to be filled;
the sub-module is used for taking the message to be transmitted as the first data to be encrypted when the judging sub-module judges that the message to be transmitted does not need to be filled;
the encryption submodule is used for encrypting the first to-be-encrypted data obtained by the filling submodule by using a first key to obtain first ciphertext data, and the first ciphertext data is used as a first data domain; and the first cipher key is also used for encrypting the first to-be-encrypted data obtained by the submodule by using the first key to obtain first cipher text data, and the first cipher text data is used as a first data domain.
More specifically, in this embodiment, the determining submodule is specifically configured to: summing the length of the message to be transmitted with a first preset length, judging whether the sum is an integral multiple of a second preset length, and if so, determining that the message to be transmitted does not need to be filled; otherwise, confirming that the message to be transmitted needs to be filled;
a fill submodule, specifically configured to: filling the length of the message to be transmitted at the left end of the message to be transmitted, and filling one byte of second preset data and the third preset data with the least bytes at the right end of the message to be transmitted, so that the length of the first data to be encrypted is integral multiple of the second preset length.
Further, in this embodiment, the second calculating module 406 is specifically configured to: and filling fourth preset data in the data after the head domain and the first data domain are sequentially spliced to obtain first data to be verified, calculating the first data to be verified by using a second secret key according to a preset algorithm to obtain a calculation result, and reading data on preset bytes in the calculation result to serve as a current first verification value.
Further, the second organizing module 407 is specifically configured to: and sequentially splicing the header field, the first data field and the first check value to obtain the instruction.
Further, the parsing module 410 is specifically configured to:
and analyzing the response data received by the receiving module 409 to obtain a second data field and a second check value, checking the second data field according to a second key and the second check value, if the checking is successful, decrypting the second data field according to the first key to obtain second data to be encrypted, analyzing the second data to be encrypted to obtain plaintext response data, analyzing the plaintext response data to obtain an operation result, otherwise, failing the transaction, and ending.
Further, the updating module 411 is specifically configured to:
changing the current random number by a preset step length, and taking the value after changing the preset step length as the current random number;
or,
taking the current random number as a seed random number, generating a new random number according to the seed random number, and taking the new random number as the current random number;
or,
and calculating the current random number according to a preset algorithm to obtain a calculation result, and taking the calculation result as the current random number.
Further, in the system of the present embodiment, the first calculating module 403 is further configured to: when the operation result is that the operation is successful, if a message is still to be transmitted, the first key and the second key are calculated according to the current random number obtained by the updating module 411 and the preset key corresponding to the terminal device.
The first sending module 402 may be further configured to send a request for obtaining a random number to the terminal device;
correspondingly, the receiving module 409 is further configured to receive the random number returned by the terminal device, and store the received random number as the current random number.
EXAMPLE five
An embodiment of the present invention provides a secure data transmission device, as shown in fig. 6, including:
a first receiving module 501, configured to receive a random number sent by a system, where the random number is used as a current random number;
a second receiving module 502, configured to receive an instruction sent by the system;
the analyzing module 503 is configured to analyze the instruction received by the second receiving module 502 to obtain a header field, a first data field, and a first check value;
a first calculating module 504, configured to calculate a first key and a second key according to the current random number and a preset key of the current random number;
a checking module 505, configured to check the header field and the first data field according to the second key and the first check value;
a sending module 506, configured to return an error code to the system when the verification module 505 fails, and end;
a decryption module 507, configured to decrypt the first data domain using the first key to obtain the transmission packet when the verification by the verification module 505 is successful;
the sending module 506 is further configured to send the transmission message obtained by the decryption module 507 to the card;
a third receiving module 508, configured to receive an operation result returned by the card;
an organizing module 509, configured to organize successful response data when the operation result received by the third receiving module 508 is that the operation is successful; the third receiving module 508 is further configured to organize failure response data when the operation result received by the third receiving module is an operation failure;
a sending module 506, configured to return successful response data organized by the organization module 509 to the system; and is further configured to return failure response data organized by the organization module 509 to the system;
an updating module 510, configured to update the current random number according to a preset manner after the sending module 506 returns the successful response data organized by the organizing module 509 to the system.
In this embodiment, the first receiving module 501 is specifically configured to:
receiving a setting command sent by a system, analyzing the setting command to obtain a random number, and taking the obtained random number as a current random number;
or,
and receiving the ciphertext random number sent by the system, decrypting the ciphertext random number according to a preset encryption algorithm to obtain a random number, and taking the obtained random number as the current random number.
The apparatus in this embodiment further includes: a second calculation module;
a second calculating module, configured to calculate a third check value according to the random number received by the first receiving module 501 after the first receiving module 501 receives the random number sent by the system and uses the random number as a current random number;
the sending module 506 is further configured to send the third check value calculated by the second calculating module to the system.
In this embodiment, the second calculating module is specifically configured to:
the random number received by the first receiving module 501 and the first preset data are subjected to preset operation to obtain an operation result, and data on a preset byte in the operation result is read as a third check value.
Further, in this embodiment, the first calculating module 504 is specifically configured to:
reading a first preset secret key and a second preset secret key preset by the user, encrypting the current random number by using the first preset secret key according to a preset algorithm to obtain the first secret key, and encrypting the current random number by using the second preset secret key to obtain the second secret key.
Further, the checking module 505 is specifically configured to:
and filling fourth preset data in the data after the head domain and the first data domain are sequentially spliced to obtain first data to be verified, calculating the first data to be verified by using a second secret key according to a preset algorithm to obtain a calculation result, reading data on preset bytes in the calculation result to serve as a first verification code, judging whether the first verification code is the same as the first verification value, if so, confirming that the verification is successful, and otherwise, confirming that the verification is failed.
Further, the decryption module 507 is specifically configured to:
and decrypting the first data domain by using the first key according to a preset algorithm to obtain first data to be encrypted, analyzing the first data to be encrypted to obtain the length of a transmission message, and reading corresponding data according to the length of the transmission message to obtain the transmission message.
Further, the organization module 509 is specifically configured to:
organizing plaintext response data according to a current operation result, organizing second data to be encrypted according to the plaintext response data, encrypting the second data to be encrypted by using a first secret key to obtain a second data field, filling fourth preset data in the second data field to obtain second data to be verified, calculating a current third verification value for the second data to be verified by using the second secret key according to a preset algorithm, and splicing the second data field and the third verification value to obtain response data.
Further, the update module 510 is specifically configured to:
changing the current random number by a preset step length, and taking the value after changing the preset step length as the current random number;
or,
taking the current random number as a seed random number, generating a new random number according to the seed random number, and taking the new random number as the current random number;
or,
and calculating the current random number according to a preset algorithm to obtain a calculation result, and taking the calculation result as the current random number.
Further, the apparatus in this embodiment further includes: the device comprises a judging module and a shutdown module;
the determining module is configured to determine whether a duration of waiting for receiving data exceeds a preset duration after the updating module 510 updates the current random number according to a preset manner;
the shutdown module is used for shutting down and ending when the judging module judges that the time length of waiting for receiving the data exceeds the preset time length;
the second receiving module 502 is further configured to receive an instruction sent by the system when the determining module determines that the duration of waiting for receiving data does not exceed the preset duration.
The device in this embodiment, the first receiving module 501, may also be configured to receive a request for obtaining a random number sent by a system;
correspondingly, the sending module 506 may be further configured to, after the first receiving module 501 receives the request for obtaining the random number sent by the system, return the preset random number to the system as the current random number.
According to the technical scheme, when the terminal equipment and the background system transmit data, different keys are used for encrypting and decrypting the data each time, and the safety of data transmission is guaranteed.
The above description is only for the preferred embodiment of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present invention, and all such changes or substitutions should be covered by the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims (44)

CN201610744373.9A2016-08-272016-08-27A kind of safe data transmission method and deviceActiveCN106357393B (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN201610744373.9ACN106357393B (en)2016-08-272016-08-27A kind of safe data transmission method and device

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN201610744373.9ACN106357393B (en)2016-08-272016-08-27A kind of safe data transmission method and device

Publications (2)

Publication NumberPublication Date
CN106357393A CN106357393A (en)2017-01-25
CN106357393Btrue CN106357393B (en)2019-09-13

Family

ID=57855811

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN201610744373.9AActiveCN106357393B (en)2016-08-272016-08-27A kind of safe data transmission method and device

Country Status (1)

CountryLink
CN (1)CN106357393B (en)

Families Citing this family (12)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN108881105A (en)*2017-05-082018-11-23中车株洲电力机车研究所有限公司A kind of method and system of connection setup
CN107395580B (en)*2017-07-102020-09-15深圳怡化电脑股份有限公司Data verification method and device
CN109298931B (en)*2017-07-252022-04-08迈普通信技术股份有限公司Buffer on-demand release method and network equipment
CN107682335B (en)*2017-10-092020-05-22平安普惠企业管理有限公司Data transmission method, server and computer readable storage medium
CN107959552B (en)*2017-10-272023-08-22浙江浙大网新众合轨道交通工程有限公司Method and system for realizing request confirmation operation in single channel
CN110022287A (en)*2018-01-102019-07-16厦门雅迅网络股份有限公司A kind of asynchronous distributed document transmission method, terminal device and storage medium
CN108833086B (en)*2018-05-042024-09-10深圳绿米联创科技有限公司Fingerprint lock and working method thereof
CN109327466B (en)*2018-11-162021-08-06广州创想云科技有限公司Data encryption transmission method, electronic equipment and storage medium
CN110149631B (en)*2019-05-292023-06-13飞天诚信科技股份有限公司Method and system suitable for cloud loudspeaker box connection establishment
CN111314062B (en)*2020-01-142022-10-18支付宝(杭州)信息技术有限公司Smart card data issuing method and device, electronic equipment and storage medium
CN112995210B (en)*2021-04-202023-04-07全球能源互联网研究院有限公司Data transmission method and device and electronic equipment
CN116506207A (en)*2023-05-172023-07-28深圳市火火兔智慧科技有限公司 A method for encryption and decryption protection of early education equipment resources

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN102611550A (en)*2012-02-262012-07-25光束(北京)国际工程技术研究院有限公司Method for encrypting data and method for transmitting encrypted data
CN105897748B (en)*2016-05-272019-05-10飞天诚信科技股份有限公司 Symmetric key transmission method and device

Also Published As

Publication numberPublication date
CN106357393A (en)2017-01-25

Similar Documents

PublicationPublication DateTitle
CN106357393B (en)A kind of safe data transmission method and device
CN110519260B (en)Information processing method and information processing device
US12200144B2 (en)Method for upgrading certificate of POS terminal, server, and POS terminal
US11258792B2 (en)Method, device, system for authenticating an accessing terminal by server, server and computer readable storage medium
CN111131278B (en)Data processing method and device, computer storage medium and electronic equipment
CN107395581B (en)Two-dimensional code generation and reading method, device, system, equipment and storage medium
CN1985466B (en) Method of delivering direct evidence private key to device by signing group using distribution CD
JP5827692B2 (en) Bound data card and mobile host authentication method, apparatus and system
CN106372497B (en)Application programming interface API protection method and protection device
US12192376B2 (en)Method and apparatus for realizing secure signature
CN104579680B (en)A kind of method of secure distribution seed
CN113872770A (en)Security verification method, system, electronic device and storage medium
CN108566368B (en)Data processing method, server and diagnosis connector
CN108170461B (en)Differential upgrade package generation method, differential upgrade method and device
CN109040055A (en)The method for realizing Web secure access using domestic password
CN107124279A (en) Method and device for erasing terminal data
CN106453430A (en)Method and device for verifying encrypted data transmission paths
CN114531242A (en)Certificate upgrading method, device, equipment and storage medium
JP2007173999A (en)Authentication system and device to be authenticated
KR101808315B1 (en)Method of roaming certification between mobile apparatus and user terminal and certification roaming system for performing the same
CN116132041A (en)Key processing method and device, storage medium and electronic equipment
CN106411964A (en)Traceable and encrypted data transmission method and device
CN109150867B (en)Network information transmission encryption/decryption device and encryption/decryption method
CN112737790A (en)Data transmission method and device, server and client terminal
JP2007020065A (en) Decryption backup method, decryption restore method, authentication device, individual key setting machine, user terminal, backup device, encrypted backup program, decryption restore program

Legal Events

DateCodeTitleDescription
C06Publication
PB01Publication
SE01Entry into force of request for substantive examination
SE01Entry into force of request for substantive examination
GR01Patent grant
GR01Patent grant
OL01Intention to license declared
OL01Intention to license declared

[8]ページ先頭

©2009-2025 Movatter.jp