A message encryption and decryption method and system

By using the terminal working key in the self-service device for message encryption and decryption and MAC value calculation, the problem of low encryption and decryption performance in serial port connection mode is solved, and efficient confidentiality and integrity guarantee of data are achieved.

CN114039728BActive Publication Date: 2024-09-17CHINA ELECTRONICS GREAT WALL CHANGSHA INFORMATION TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111601409.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-24
Publication Date
2024-09-17
Estimated Expiration
2041-12-24

AI Technical Summary

Technical Problem

Existing technology cannot effectively guarantee the encryption and decryption performance of self-service devices that use serial port connection for password keyboard connection when transmitting big data. This often results in encryption and decryption timeouts, affecting customer experience, and cannot guarantee the confidentiality and integrity of data at the same time.

Method used

By using the protection keys MSGKEY and MACKEY in the terminal working key on the requesting end and the responding end to perform message encryption and decryption and MAC value calculation, JS soft algorithm is used to implement encryption and MAC calculation to ensure the confidentiality and confidentiality of data during transmission. Integrity.

Benefits of technology

The encryption and decryption speed of self-service equipment under serial port connection mode is improved, and big data can be processed within milliseconds, ensuring the confidentiality and integrity of data and avoiding encryption and decryption timeouts.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114039728B
    Figure CN114039728B
Patent Text Reader

Abstract

The present invention discloses a message encryption and decryption method and system thereof, wherein the encryption and decryption process is that a front-end application system uses a protection key MACKEYENKEY and a protection key MSGKEYENKEY to encrypt message data containing customer information and calculate a MAC value, so that a back-end front-end system performs MAC value verification and decryption, and for response information of the back-end front-end system, the protection key MACKEYENKEY and the protection key MSGKEYENKEY are used to encrypt and calculate a MAC value, so that the front-end application system performs MAC value verification and decryption, forming an encryption and decryption system for encrypting and integrity checking customer information and encrypting and integrity checking response information, thereby ensuring the confidentiality and integrity of communication messages between the front-end and back-end of a self-service device; in particular, it can meet the security requirements of self-service devices whose password keyboard connection mode is a serial port connection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of encryption / decryption, and in particular relates to a message encryption / decryption method and a system thereof. Background Art

[0002] With the rapid development of the Internet, information security has become a focus of increasing concern. In order to ensure that the user data collected by users will not be leaked when they use the system, a confidentiality measure for the transmission and access of this information has emerged.

[0003] Not only are there security requirements for Internet application systems, but there are also further requirements for the security of network data transmission between internal application systems in the financial industry. Because the industry has more and more self-service channel businesses, many traditional counter businesses have been transferred to self-service devices, and customers complete the business processing by themselves. In this process, customer identity authentication is involved, and user ID cards, on-site photos and other documents and biometric information are collected. After the information is collected, it is sent from the self-service terminal to the back-end front-end system through communication messages, and then forwarded by the back-end front-end system to the bank's biometric identification system for customer identity identification. Correspondingly, for example, sensitive information about customers during the interaction between the front-end and back-end front-end systems may also be maliciously intercepted and tampered with during the transmission process, resulting in customer information leakage and illegal transactions.

[0004] Among them, for self-service devices whose password keyboards are connected via serial ports, the communication rate of their password keyboards is limited by the baud rate of their serial ports (up to 38400bps, about 4.8k bytes per second), so their encryption and decryption speeds are very slow and cannot meet the performance requirements for encryption and decryption of full large data messages (hundreds of KB to several megabytes of data). Encryption and decryption timeouts often occur, causing business interruptions and seriously affecting customer experience.

[0005] Although there are many technical means currently applied to these, such as HTTPS based on communication protocol, although it can play a certain confidentiality role, the protocol does not currently support the national encryption algorithm and cannot guarantee the integrity of the data. For example, the MAC (Message Authentication Code) verification, which is a relatively common message authentication method, can guarantee the integrity of the data to a certain extent, but does not provide data confidentiality. In solving the performance problem of full message encryption and decryption, most methods are: either replace the password keyboard, use USB connection to increase the processing speed; or do not encrypt a large number of transaction messages. These practices either increase huge costs or are not compliant.

[0006] Therefore, it is an urgent problem to provide an encryption and decryption method for self-service devices that can ensure the confidentiality and integrity of communication messages and meet the needs of serial port connection of password keyboards. Summary of the invention

[0007] The purpose of the present invention is to solve at least some of the problems existing in the above-mentioned prior art, and to provide a message encryption and decryption method and system thereof, which can be applied to bank self-service devices to ensure the confidentiality and integrity of communication messages between the front and back ends of the self-service devices; in particular, it can satisfy self-service devices whose password keyboard connection method is a serial port connection.

[0008] On the one hand, the present invention provides a message encryption method, which is applied to a requesting end or a responding end, and is used to encrypt message data containing sensitive data on the requesting end; or to encrypt response information of the responding end;

[0009] When applied to the request side, it includes:

[0010] Send a key application request to the responding end, and then obtain the terminal working key sent by the responding end and import it into the password keyboard; wherein the terminal working key includes: protection key MACKEYENKEY, protection key MSGKEYENKEY;

[0011] Obtain message data containing sensitive data;

[0012] Call the password keyboard, use the protection key MSGKEYENKEY to generate the message encryption and decryption key MSGKEY, and then encrypt the message data containing sensitive data; use the protection key MACKEYENKEY to generate the MAC calculation key MACKEY, and then calculate the MAC value based on the ciphertext; then send the MAC value and ciphertext to the responding end in the form of a message, so that the responding end can use the terminal working key to verify and decrypt the MAC value;

[0013] Among them, the encryption and / or MAC calculation process on the request end is implemented using the JS soft algorithm;

[0014] Or when applied to the response side, including:

[0015] Get the message data containing the response information;

[0016] Call the encryption machine, encrypt the message data containing the response information based on the message encryption and decryption key MSGKEY generated by the protection key MSGKEYENKEY; calculate the MAC value based on the MAC calculation key MACKEY generated by the protection key MACKEYENKEY and the ciphertext; then send the MAC value and ciphertext to the requesting end in the form of a message, so that the requesting end can use the terminal working key to verify and decrypt the MAC value, and finally execute the response;

[0017] Among them, the encryption key and MAC calculation process of the encryption process correspond one-to-one to the decryption key and MAC calculation process of the decryption process.

[0018] The method described in the present invention can be applied to self-service equipment to solve the problem that the communication rate of the password keyboard of the self-service equipment is limited by the baud rate of the serial port (maximum 38400bps, about 4.8k bytes per second), and its encryption and decryption speed is very slow, which cannot meet the encryption and decryption performance of large data full messages (hundreds of K to several megabytes of data).

[0019] The keys MSGKEY and MACKEY used by the request end in the method of the present invention are generated by encryption of the protection keys MSGKEYENKEY and MACKEYENKEY imported by the hardware module of the cipher keyboard, and are completely suitable for the cipher keyboard connected in the serial port mode; in addition, the encryption and decryption of the message data and the MAC calculation process on the request end are implemented using the JS soft algorithm, and its processing speed can reach a response within milliseconds for hundreds of K of its own data. Therefore, when the method is applied to the self-service device, the request end is the front end, which can effectively solve the problem that the communication rate of the cipher keyboard is constrained by its serial port baud rate, and encryption and decryption timeouts often occur.

[0020] In a second aspect, the present invention provides a message decryption method, which is applied to a requesting end or a responding end, and is used to decrypt encrypted response information sent by the responding end; or to decrypt encrypted message data containing sensitive data sent by the requesting end;

[0021] When applied to the response side, it includes:

[0022] Receive the key application request from the requesting end, then call the encryption machine to generate the terminal working key and feed it back to the requesting end; wherein the terminal working key includes: protection key MACKEYENKEY, protection key MSGKEYENKEY;

[0023] Receive encrypted message data sent by the requesting end; wherein the encrypted message data is obtained after the requesting end calls the password keyboard and uses the terminal working key to encrypt the message data to be encrypted and calculates the MAC value;

[0024] Calling the encryption machine to calculate the MAC value of the encrypted message data based on the MAC calculation key MACKEY generated by the protection key MACKEYENKEY;

[0025] Verify whether the MAC value in the received message is the same as the calculated MAC value. If not, reject the request; otherwise, call the encryption machine and decrypt the message encryption and decryption key MSGKEY generated based on the protection key MSGKEYENKEY to obtain a plaintext message, and then generate a response message;

[0026] When applied to the request side, it includes:

[0027] Receive encrypted message data containing response information sent by the responding end, wherein the encrypted message data is obtained after the responding end calls the encryption machine and uses the terminal working key to encrypt the message data containing the response information and calculates the MAC value;

[0028] Calling the password keyboard to calculate the MAC value of the encrypted message data based on the MAC calculation key MACKEY generated by the protection key MACKEYENKEY;

[0029] Verify whether the MAC value in the received encrypted message is the same as the calculated MAC value. If not, reject the request; otherwise, call the password keyboard and decrypt the message encryption and decryption key MSGKEY generated based on the protection key MSGKEYENKEY to obtain a plaintext message, and then execute the response;

[0030] Among them, the encryption key and MAC calculation process of the encryption process correspond one-to-one to the decryption key and MAC calculation process of the decryption process, and the decryption and / or MAC calculation process on the request end is implemented using the JS soft algorithm.

[0031] Further optionally, the key settings for the encryption / decryption process and the MAC calculation process are as follows:

[0032] Encryption / decryption process: using the protection key MSGKEYENKEY to generate the message encryption / decryption key MSGKEY and using the message encryption / decryption key MSGKEY to encrypt or decrypt;

[0033] MCA value calculation process: using the protection key MACKEYENKEY to generate a MAC calculation key MACKEY and using the MAC calculation key MACKEY to calculate a MAC value.

[0034] For example, the encryption process and MAC value calculation process are:

[0035] The protection key MSGKEYENKEY is used to generate a message encryption and decryption key MSGKEY, and the message encryption and decryption key MSGKEY is used to encrypt the message data to obtain a ciphertext; the protection key MACKEYENKEY is used to generate a MAC calculation key MACKEY, and the MAC calculation key MACKEY is used to calculate the MAC value of the ciphertext.

[0036] The decryption process and MAC value calculation process are as follows:

[0037] The protection key MSGKEYENKEY is used to generate a message encryption and decryption key MSGKEY, and the message encryption and decryption key MSGKEY is used to decrypt the encrypted message data to obtain a plaintext message; the protection key MACKEYENKEY is used to generate a MAC calculation key MACKEY, and the MAC calculation key MACKEY is used to calculate the MAC value of the encrypted message data.

[0038] Optionally, the process of encrypting the message data using the message encryption and decryption key MSGKEY to obtain ciphertext is expressed as:

[0039] f encC (v,msg,alg)=f jsEnc (f eppEncMsgKey (v,alg),f hex (msg),alg)

[0040] In the formula, f encC (v, msg, alg) represents the encrypted ciphertext; f eppEncMsgKey (v, alg) represents the generated message encryption and decryption key MSGKEY; v is the initial vector (for example, when applied to self-service equipment, its value is the serial number of the self-service terminal equipment), and it is expanded in hexadecimal; f hex (msg) indicates that the encrypted message data is to be expanded in hexadecimal. alg indicates the algorithm type, which specifies whether the encryption and decryption algorithm uses the international algorithm or the national secret algorithm. jsEnc Indicates the use of the key MSGKEY to f hex (msg) performs JS soft encryption using the algorithm specified by alg;

[0041] The process of calculating the MAC value of the ciphertext using the MAC calculation key MACKEY is expressed as:

[0042] f macC (v,encMsg,alg)=f jsMac (f eppEncMacKey (v,alg),encMsg,alg)

[0043] In the formula, f macC (v,encMsg,alg) represents the calculated MAC value of the ciphertext, f eppEncMacKey (v, alg) represents the MAC calculation key MACKEY generated during the encryption process, encMsg represents the ciphertext, f jsMac Indicates that the key MACKEY is used to perform JSMAC calculation on the ciphertext encMsg using the algorithm specified by alg. After receiving the ciphertext, the responder uses the MAC calculation key MACKEY to calculate the MAC value of the message, and the verification process is expressed as follows:

[0044] f macChckP (v,encMsg,macData,alg)=f cmp (f hsmMac (f hsmEncMacKey (v,alg),encMsg,alg),macData)

[0045] In the formula, v is the initial vector, alg is the MAC calculation algorithm type, and f hsmEncMacKey (v, alg) is the MAC calculation key MACKEY generated during the decryption process, and macData is the MAC value in the message received from the requester;

[0046] The process of decrypting the plaintext message using the message encryption and decryption key MSGKEY is expressed as follows:

[0047] f decP (v,encMsg,alg)=f hsmDec (f hsmEncMsgKey (v,alg),encMsg,alg)

[0048] Among them, the parameter v is the initial vector, which is consistent with the initial vector used in the encryption process of the front-end application system, and is used to generate the message encryption key MSGKEY, whose value is the self-service terminal number; encMsg is the ciphertext; alg is the decryption algorithm type, whose value is SM4 or 3DES;

[0049] f hsmEncMsgKey (v,alg): indicates that the message decryption key MSGKEY is generated by this method.

[0050] Optionally, the method is applied to a self-service device, and when the requesting end is a front-end application system, the responding end is a back-end front-end system, and the message data to be encrypted in the front-end application system is message data containing customer information; the message data to be encrypted in the back-end front-end system is response message data returned to the front-end application system after business logic processing.

[0051] In a third aspect, the present invention provides an encryption and decryption method, which comprises the following steps:

[0052] The front-end application system sends a key application request to the back-end front-end system;

[0053] The back-end front-end system calls the encryption machine to generate a terminal working key and feeds it back to the front-end application system; wherein the terminal working key includes: a protection key MACKEYENKEY and a protection key MSGKEYENKEY;

[0054] The front-end application system imports the terminal working key into the password keyboard;

[0055] The front-end application system obtains message data containing sensitive data;

[0056] The front-end application system calls the password keyboard, uses the protection key MACKEYENKEY and the protection key MSGKEYENKEY to encrypt the message data containing sensitive data and calculate the MAC value, and then sends the MAC value and ciphertext to the back-end front-end system in the form of a message;

[0057] The back-end front-end system receives the message sent by the front-end application system;

[0058] The back-end front-end system calls the encryption machine and uses the protection key MACKEYENKEY to calculate the MAC value of the message;

[0059] The back-end front-end system verifies whether the MAC value in the received message is the same as the calculated MAC value. If not, the request is rejected; otherwise, the encryption machine is called and the protection key MSGKEYENKEY is used to decrypt the plaintext message, and then subsequent business logic processing is performed.

[0060] Furthermore, the terminal working keys are all encrypted using a terminal master key, and the terminal master key is output by connecting the channel business management system to an encryption machine to print a terminal master key envelope for the self-service device.

[0061] Furthermore, it also includes:

[0062] The back-end front-end system obtains the message data containing the response information;

[0063] The back-end front-end system calls the encryption machine, uses the protection key MACKEYENKEY and the protection key MSGKEYENKEY to encrypt the message data containing the response information and calculate the MAC value, and then sends the MAC value and the ciphertext to the front-end application system in the form of a message;

[0064] The front-end application system receives the encrypted message data containing the response information sent by the responding end;

[0065] The front-end application system password keyboard calculates the MAC value of the encrypted message data using the protection key MACKEYENKEY;

[0066] The front-end application system verifies whether the MAC value in the received encrypted message is the same as the calculated MAC value. If not, the request is rejected; otherwise, the front-end application system calls the password keyboard and uses the protection key MSGKEYENKEY to decrypt the plaintext message, and then executes the response.

[0067] In a fourth aspect, the present invention provides a system for applying the message encryption method, which at least includes a requesting end, and the requesting end performs message encryption according to the message encryption method, and the requesting end includes:

[0068] The terminal sign-in module is used to send a key application request to the responding end, and then the requesting end obtains the terminal working key sent by the responding end;

[0069] A business module, used to obtain message data to be encrypted;

[0070] A key management module, used to import the terminal working key into the password keyboard;

[0071] The password keyboard device JS module is used to call the password keyboard, and use the protection key MACKEYENKEY and the protection key MSGKEYENKEY to encrypt the message data containing sensitive data and calculate the MAC value;

[0072] The communication module is used to send the MAC value and the ciphertext to the responding end in the form of a message.

[0073] In a fifth aspect, the present invention provides a system for applying the message decryption method, which at least includes a requesting end, and the requesting end performs message decryption according to the message decryption method, and the requesting end includes:

[0074] The terminal sign-in module is used to send a key application request to the responding end, and then the requesting end obtains the terminal working key sent by the responding end;

[0075] A key management module, used to import the terminal working key into the password keyboard;

[0076] The communication module is used to receive the encrypted message data containing the response information sent by the responder;

[0077] The JS module of the password keyboard device is used to call the password keyboard and use the protection key MACKEYENKEY to calculate the MAC value of the encrypted message data; verify whether the MAC value in the received encrypted message is the same as the calculated MAC value, if not, reject the request; otherwise, call the password keyboard and use the protection key MSGKEYENKEY to decrypt to obtain the plaintext message.

[0078] In a sixth aspect, the present invention provides a system for applying the message encryption method, which at least includes a responding end, and the responding end performs message encryption according to the message encryption method, and the responding end includes:

[0079] The terminal key management module is used to respond to the key application request of the requesting end and call the encryption machine to generate the terminal working key;

[0080] The communication module is used to establish a communication connection with the requesting end to realize data transmission;

[0081] The encryption machine communication module is used to call the encryption machine, use the protection key MACKEYENKEY and the protection key MSGKEYENKEY to encrypt the message data containing the response information and calculate the MAC value, and send the MAC value and ciphertext to the request end in the form of a message through the communication module.

[0082] In a seventh aspect, the present invention provides a system applying the message decryption method, which at least includes a responding end, and the responding end performs message encryption according to the message decryption method, and the responding end includes:

[0083] The terminal key management module is used to respond to the key application request of the requesting end and call the encryption machine to generate the terminal working key;

[0084] The communication module is used to establish a communication connection with the requesting end to realize data transmission;

[0085] The encryption machine communication module is used to call the encryption machine and use the protection key MACKEYENKEY to calculate the MAC value of the encrypted message data; verify whether the MAC value in the received message is the same as the calculated MAC value, if not the same, reject the request; otherwise, call the encryption machine and use the protection key MSGKEYENKEY to decrypt to obtain the plaintext message, and then generate the response information.

[0086] In an eighth aspect, the present invention provides a system based on the encryption and decryption method, which includes a front-end application system and a back-end front-end system;

[0087] Among them, the front-end application system includes:

[0088] The terminal sign-in module is used to send a key application request to the back-end front-end system, and then the front-end application system obtains the terminal working key sent by the back-end system;

[0089] A business module, used to obtain message data to be encrypted;

[0090] A key management module, used to import the terminal working key into the password keyboard;

[0091] The password keyboard device JS module calls the password keyboard, and uses the protection key MACKEYENKEY and the protection key MSGKEYENKEY to encrypt the message data containing sensitive data and calculate the MAC value;

[0092] The front-end communication module is used to send the MAC value and ciphertext to the back-end system in the form of a message;

[0093] Among them, the back-end front-end system includes:

[0094] The terminal key management module is used to respond to the key application request of the front-end application system and call the encryption machine to generate the terminal working key;

[0095] Channel access module, used to establish communication connection with the front-end application system to realize data transmission;

[0096] The encryption machine communication module is used to call the encryption machine and use the protection key MACKEYENKEY to calculate the MAC value of the encrypted message data; verify whether the MAC value in the received message is the same as the calculated MAC value, if not, reject the request; otherwise, call the encryption machine and use the protection key MSGKEYENKEY to decrypt to obtain the plaintext message,

[0097] Finally, subsequent business logic processing is performed to generate response information.

[0098] In a thirteenth aspect, the present invention provides a readable storage medium storing a computer program, wherein the computer program is called by a processor to implement:

[0099] The invention relates to steps of a message encryption method or steps of a message decryption method or steps of a message encryption and decryption method.

[0100] Beneficial Effects

[0101] 1. The present invention provides a message encryption and decryption method and system thereof, which utilizes the protection key MACKEYENKEY and the protection key MSGKEYENKEY in the terminal working key to encrypt the message data, wherein integrity verification can be achieved through encryption and MAC value calculation and MAC value verification, thereby ensuring data confidentiality while also ensuring data integrity to a certain extent.

[0102] 2. A message encryption and decryption method and system of the present invention can meet the needs of self-service equipment whose password keyboard connection mode is a serial port connection. BRIEF DESCRIPTION OF THE DRAWINGS

[0103] Figure 1 It is a schematic diagram of the framework of a front-end and back-end communication message encryption and decryption system provided by the present invention;

[0104] Figure 2 It is a flow chart of a method for encrypting and decrypting messages corresponding to online verification transactions in a self-service device provided by the present invention. DETAILED DESCRIPTION

[0105] A message encryption and decryption method provided by the present invention is applied to the requesting end and the responding end of establishing a communication connection, wherein the requesting end requests a key from the responding end, and transmits sensitive data (such as customer information, confidential information, etc.) to the responding end, and the responding end verifies whether the information has been tampered with. If not, it responds to the request and transmits the data to the requesting end. Therefore, the present invention regards the communication between the requesting end and the responding end as a two-way transmission, which is divided into: from the requesting end to the responding end; from the responding end to the requesting end. Among them, on each type of transmission path, the information at one end is encrypted and then transmitted to the other end, and the other end first verifies the MAC value and then decrypts it. The following will be described by taking the self-service device as an example. The present invention is based on the security problems existing in the transmission of message data between the front and back ends of the bank self-service device and the encryption and decryption performance problems existing when the password keyboard connection method is a serial port connection, which triggers relevant research. The present invention will be further described in conjunction with the embodiments below.

[0106] Embodiment 1:

[0107] This embodiment takes a self-service device as an example. The system of the self-service device is divided into: a front-end application system, a back-end front-end system, and a channel business management system. Based on this system distribution, this embodiment provides a message encryption and decryption method, which is applied to the self-service device, including the following steps:

[0108] Step 1: The system administrator connects to the encryption machine through the channel business management system to print the terminal master key envelope for a self-service device terminal, outputs the terminal master key envelope, and stores the terminal master key returned by the encryption machine interface (encrypted by the encryption machine's local master key) into the database terminal key table. The terminal master key is used to encrypt the terminal working key.

[0109] Step 2: Import the terminal master key into the password keyboard through the front-end application system for decryption of the key when the terminal working key is subsequently imported (the decryption action is completed inside the password keyboard).

[0110] Step 3: The front-end application system starts to enter the terminal sign-in module of the front-end application system, and the terminal sign-in module applies for a key from the back-end front-end system.

[0111] Step 4: After the back-end front-end system receives the key application request from the front-end application system, it calls the encryption machine to generate the terminal working key (the terminal working key includes: customer password encryption key PINKEY (the customer password is encrypted separately, and the customer password plain text cannot be exposed at any time.), MAC calculation key MACKEY protection key MACKEYENKEY, message encryption and decryption key MSGKEY protection key MSGKEYENKEY, all encrypted using the terminal master key) and returns it to the front-end application system, and at the same time saves the terminal working key to the encryption machine's database for subsequent encryption and decryption and MAC calculation.

[0112] Step 5: After the front-end application system receives the terminal working key returned by the back-end front-end system, it imports the terminal key into the password keyboard.

[0113] Step 6: The customer conducts self-service financial services on the self-service device terminal, performs system interactions such as identity card reading or scanning, on-site photography, and then collects customer information.

[0114] Step 7: The front-end application system uses the collected customer information as the message data to be encrypted. The front-end application system calls the key keyboard and uses the MSGKEY generated by the protection key MSGKEYENKEY to encrypt the message data to obtain the ciphertext, and calls the key keyboard to use the MACKEY generated by MACKEYENKEY to calculate the MAC value of the encrypted ciphertext data, and places it in the communication message header field. The ciphertext is sent together as the message body.

[0115] Step 8: The back-end front-end system receives the encrypted message sent by the front-end application system (including ID card head portrait photo data, on-site photo data, and other collected customer information), and first performs a message integrity check: the encryption machine is called to use the MAC key encryption key MACKEYENKEY stored in the database to generate the MAC key MACKEY to calculate the MAC of the message, and then compare it with the MAC in the message header to see if it is consistent. If it is inconsistent, the request is rejected. Otherwise, the encryption machine is called to use the encryption key MSGKEYENKEY of the message encryption key stored in the database to generate the message encryption key MSGKEY to decrypt the encrypted message. After obtaining the plaintext message, subsequent business logic processing is performed.

[0116] Step nine: The back-end front-end system generates a response message, calls the encryption machine, and uses the message encryption key MSGKEY generated by the encryption key MSGKEYENKEY of the message encryption key stored in the database to encrypt the message, and calls the encryption machine to use the MAC key MACKEY generated by the MAC key encryption key MACKEYENKEY stored in the database to calculate the MAC check value for the obtained ciphertext, places the MAC check value in the message header, and returns the ciphertext as the message body to the front-end application system.

[0117] Step 10: The front-end application system receives the response message returned by the back-end front-end system, and first performs MAC verification on the ciphertext message data: call the password keyboard and use the MACKEY generated by MACKEYENKEY to calculate the MAC verification value of the ciphertext message data, and then compare it with the MAC in the message header to see if it is consistent. If it is inconsistent, a friendly prompt is given and the current business process ends, otherwise proceed to the next step.

[0118] Step 11: The front-end application system calls the key keyboard and uses MSGKEYENKEY to generate MSGKEY to decrypt the ciphertext message data. After obtaining the plaintext, it is handed over to the subsequent processing flow of the business module of the front-end application system for further processing.

[0119] It should be noted that this embodiment takes a self-service device as an example and sets its architecture including a front-end application system, a back-end front-end system, and a channel business management system for description. In other feasible embodiments, the implementation process of the above method can be partially adjusted, and the local adjustment is not limited to the adjustment of the step sequence and the deletion of steps. On the basis of not departing from the concept of the present invention, it belongs to the protection scope of the present invention.

[0120] Embodiment 2:

[0121] This embodiment provides a message encryption method, which is applied to a front-end application system and includes the following steps:

[0122] 1-1: Send a key application request to the responder, then obtain the terminal working key sent by the responder and import it into the PIN keyboard.

[0123] This embodiment is described from the perspective of the front-end application system. It should be understood that the terminal working key obtained in this embodiment is obtained by referring to the relevant statements in Example 1. In other feasible embodiments, if there are other ways to obtain it, it is also feasible.

[0124] 1-2: Acquire message data containing sensitive data In this embodiment, the sensitive data is customer information, that is, the message data to be encrypted is message data containing customer information, such as identity card information, photos, and the like.

[0125] 1-3: Call the password keyboard, use the protection key MACKEYENKEY and the protection key MSGKEYENKEY to encrypt the message data containing sensitive data and calculate the MAC value, and then send the MAC value and ciphertext to the back-end front-end system in the form of a message, so that the back-end front-end system can use the terminal working key to verify and decrypt the MAC value.

[0126] Specifically: call the key keyboard and use the MSGKEY generated by the protection key MSGKEYENKEY to encrypt the message data to obtain the ciphertext, and call the key keyboard to use the MACKEY generated by MACKEYENKEY to calculate the MAC value of the encrypted ciphertext data, place it in the communication message header field, and send the ciphertext as the message body.

[0127] It should also be understood that this embodiment is stated from the perspective of the front-end application system. The MAC verification and decryption process involving the back-end front-end system in this embodiment can be obtained by referring to the relevant statements in Example 1. The key and MAC value generation process in the decryption process correspond one-to-one to the key and MAC value generation process in the encryption process.

[0128] Embodiment 3:

[0129] Corresponding to Embodiment 2, this embodiment provides a message decryption method, which is applied to a back-end front-end system and includes the following steps:

[0130] 2-1: The back-end front-end system receives the key application request from the front-end application system, and then calls the encryption machine to generate the terminal working key (the terminal working key includes: customer password encryption key PINKEY, MAC calculation key MACKEY protection key MACKEYENKEY, message encryption and decryption key MSGKEY protection key MSGKEYENKEY, all encrypted by the terminal master key) and returns it to the front-end application system, and saves the terminal working key to the encryption machine's database for subsequent encryption and decryption and MAC calculation.

[0131] 2-2: Receive the encrypted message data sent by the requesting end; wherein, the encrypted message data is obtained after the requesting end calls the password keyboard and uses the terminal working key to encrypt the message data to be encrypted and calculates the MAC value.

[0132] After the front-end application system receives the terminal working key, how to perform encryption and MAC value calculation can refer to the relevant description of Example 1. This embodiment is described from the perspective of the back-end front-end system, so the implementation process of the front-end application system is not described in detail.

[0133] 2-3: Call the encryption machine and use the protection key MACKEYENKEY to calculate the MAC value of the encrypted message data; verify whether the MAC value in the received message is the same as the calculated MAC value. If not, reject the request; otherwise, call the encryption machine and use the protection key MSGKEYENKEY to decrypt the plaintext message, and then generate a response message.

[0134] Specifically: first, perform a message integrity check: call the encryption machine to use the MAC key encryption key MACKEYENKEY stored in the database to generate the MAC key MACKEY to calculate the MAC of the message, and then compare it with the MAC in the message header to see if they are consistent. If they are inconsistent, reject the request; otherwise, call the encryption machine to use the encryption key MSGKEYENKEY of the message encryption key stored in the database to generate the message encryption key MSGKEY to decrypt the encrypted message. After obtaining the plaintext message, perform subsequent business logic processing and generate response information.

[0135] Embodiment 4:

[0136] This embodiment continues to use the back-end front-end system as an example, which is used to encrypt the generated response information and then send it to the front-end application system after encryption. This embodiment provides a message encryption method, including the following steps:

[0137] 3-1: Get the message data containing the response information.

[0138] 3-2: Call the encryption machine, use the protection key MACKEYENKEY and the protection key MSGKEYENKEY to encrypt the message data containing the response information and calculate the MAC value, and then send the MAC value and ciphertext to the requesting end in the form of a message, so that the front-end application system can use the terminal working key to verify and decrypt the MAC value, and finally execute the response.

[0139] Specifically: call the encryption machine to use the message encryption key MSGKEY generated by the encryption key MSGKEYENKEY of the message encryption key stored in the database to encrypt the message, and call the encryption machine to use the MAC key encryption key MACKEYENKEY stored in the database to generate the MAC key MACKEY to calculate the MAC check value for the obtained ciphertext, place the MAC check value in the message header, and use the ciphertext as the message body.

[0140] It should be understood that the process of how the front-end application system uses the terminal working key to verify and decrypt the MAC value can refer to the relevant statements in Example 1.

[0141] Embodiment 5:

[0142] This embodiment continues to use the front-end application system as an example to decrypt encrypted message data containing response information. This embodiment provides a message decryption method, including the following steps:

[0143] 4-1: Receive encrypted message data containing response information sent by the responding end, wherein the encrypted message data is obtained after the responding end calls the encryption machine and uses the terminal working key to encrypt the message data containing the response information and calculates the MAC value.

[0144] This embodiment is described from the perspective of the front-end application system. How the back-end front-end system uses the terminal working key to encrypt the message data containing the response information and calculate the MAC value can refer to the relevant statements in Example 1. In addition, how to obtain the terminal working key can also refer to the relevant statements in Example 1.

[0145] 4-2: Call the password keyboard and use the protection key MACKEYENKEY to calculate the MAC value of the encrypted message data; verify whether the MAC value in the received encrypted message is the same as the calculated MAC value, if not, reject the request; otherwise, call the password keyboard and use the protection key MSGKEYENKEY to decrypt to obtain the plaintext message, and then execute the response;

[0146] Specifically: first, perform MAC verification on the ciphertext message data: call the password keyboard and use the MACKEY generated by MACKEYENKEY to calculate the MAC verification value of the ciphertext message data, and then compare it with the MAC in the message header to see if they are consistent. If they are inconsistent, give a friendly prompt and end the current business process. Otherwise, use MSGKEYENKEY to generate MSGKEY to decrypt the ciphertext message data. After obtaining the plain text, it will be handed over to the subsequent processing flow of the business module of the front-end application system to continue processing.

[0147] It should be noted that Examples 2-5 are all stated from the perspective of the front-end application system or the back-end front-end system. Therefore, the process of obtaining the terminal working key, storing the terminal master key in the database terminal key table, and importing the terminal master key into the password keyboard can all refer to the relevant statements in Example 1.

[0148] In order to more clearly illustrate the encryption and MCA value calculation process involved in Examples 1-5, the following example is given:

[0149] Regarding message data encryption of front-end application system:

[0150] f encC (v,msg,alg)=f jsEnc (f eppEncMsgKey (v,alg),f hex (msg),alg)

[0151] Among them, the parameter v is the initial vector, which is used to generate the message encryption key MSGKEY, and its value is the number of the self-service terminal device; msg is the message to be encrypted; alg is the type of encryption algorithm, and in this embodiment, the value is SM4 or 3DES.

[0152] f eppEncMsgKey (v, alg): It means to generate the message encryption key MSGKEY through this method. This method first performs a hexadecimal expansion process on the initial vector v. If it is less than 32 characters, "00" is filled on the right, and then by calling the password keyboard, it encrypts it using the protection key MSGKEYENKEY, and the type of encryption algorithm is specified by alg. The encrypted data is returned as the message encryption key MSGKEY.

[0153] f hex (msg): It means to perform a hexadecimal expansion process on the message data msg to be encrypted.

[0154] f jsEnc (f eppEncMsgKey (v, alg), f hex (msg), alg): It means to encrypt the processed message data using the key MSGKEY and the encryption algorithm specified by alg, and the encryption mode uses ECB. Before encryption, according to the alg algorithm type, "00" is filled on the right of the message data with different lengths. If it is of the SM4 type, the total data length after filling is an integer multiple of 16. If it is of the 3DES type, the total data length after filling is an integer multiple of 8.

[0155] For example: The self-service terminal (number: 00800001), the encryption algorithm type alg is the SM4 algorithm, the message encryption key MSGKEYENKEY: 12DE1234A234A23B1234F23EE234FC34, the MAC key encryption key MSGKEYENKEY: DFD8A391375403C94FFC978DD962314A, the plaintext message data sent by the front-end application system:

[0156] {"header":{"devId":"00800001","macData":""},"body":{"picData1":"123123334323","picData2":"3452344444","name":"Li Si","idNo":"432234433132222222"}}. Its processing process:

[0157] The initial vector v=00800001, after hexadecimal expansion and padding, HEX(v)=3030383030303031000000000000000000, and the calculation results are:

[0158] MSGKEY=f eppEncMsgKey (v,alg)=6DD1CAE75F983C95C6CAA61D3373FE86

[0159] msg={"picData1":"123123334323","picData2":"3452344444","name":"Li Si","idNo":"432234433132222222"}

[0160] f hex (msg)

[0161] =7B227069634461746131223A22313233313233333334333233222C227069634461746132223A2233343532333434 343434222C226E616D65223A22C0EECBC4222C2269644E6F223A22343332323334343333313332323232323232227D

[0162] f jsEnc (f eppEncMsgKey (v,alg),f hex (msg),alg)

[0163] =1E717F9BAE72F6F4DEF98BADFF7899724943FF36101941CD3DCEBD61BFDEA17E81E0B8F0EBC83C15963A4534FCB7B3B 23532F78FC95F3E7028D38E586349383268961AB5C779F5FC8B2FCC32EA102DF44295DAF14BC8A4E39E3C9F1114027327

[0164] The message ciphertext is obtained by the above encryption method:

[0165] 1E717F9BAE72F6F4DEF98BADFF7899724943FF36101941CD3DCEBD61BFDEA17E81E0B8F0EBC83C15963A4534FCB7B3B2 3532F78FC95F3E7028D38E586349383268961AB5C779F5FC8B2FCC32EA102DF44295DAF14BC8A4E39E3C9F1114027327.

[0166] Then perform MAC calculation on the message ciphertext to meet the data integrity requirements.

[0167] Specific MAC calculation method:

[0168] f macC (v,encMsg,alg)=f jsMac (f eppEncMacKey (v,alg),encMsg,alg)

[0169] The parameter v is the initial vector used to generate the MAC key MACKEY, and its value is the self-service terminal number; encMsg is the encrypted message ciphertext data; alg is the MAC calculation algorithm type, and its value is SM4 or 3DES.

[0170] f eppEncMacKey (v,alg): indicates that the MAC key MACKEY is generated by this method. This method first processes the initial vector v, expands it into hexadecimal, and right-pads "00" if it is less than 32 characters. Then, it calls the password keyboard and encrypts it using MACKEYENKEY. The encryption algorithm type is specified by alg. The encrypted data is returned as the MAC key MACKEY.

[0171] f jsMac (f eppEncMacKey (v, alg), encMsg, alg): Perform ANSI 9.9 algorithm MAC calculation on the ciphertext data of the message using the key MACKEY and the key algorithm type specified by alg to obtain the MAC check value MACDATA of the ciphertext data of the message.

[0172] Taking the message used by the encryption method as an example, the calculation process is:

[0173] MACKEY=f eppEncMacKey (v,alg)=9DE19B709DD9F49048D5E9AB11A6D17D

[0174] The obtained MAC check value is:

[0175] f jsMac (f eppEncMacKey (v,alg),encMsg,alg)=37FA87DC6DF3C5226888BF77EFD5DD92

[0176] Finally, the message data that the front-end application system finally sends to the back-end front-end system is:

[0177] {"header":{"devId":"00800001","macData":"37FA87DC6DF3C5226888BF77EFD5DD92"},"body":"1E717F9BAE72F6F4DEF98BADFF7899724943FF36101941CD3DCEBD6 1BFDEA17E81E0B8F0EBC83C15963A4534FCB7B3B23532F78FC95F3E7028D38E586349 383268961AB5C779F5FC8B2FCC32EA102DF44295DAF14BC8A4E39E3C9F1114027327"}

[0178] First, MAC calculation is performed on the received ciphertext, and MAC verification is performed to meet data integrity requirements.

[0179] Specific MAC calculation and verification methods:

[0180] f macChckP (v,encMsg,macData,alg)=f cmp (f hsmMac (f hsmEncMacKey (v,alg),encMsg,alg),macData)

[0181] Among them, parameter v is the initial vector, which is consistent with the initial vector used in the MAC calculation process of the front-end application system, and is used to generate the MAC key MACKEY, whose value is the self-service terminal number; encMsg is the encrypted message ciphertext data; alg is the MAC calculation algorithm type, whose value is SM4 or 3DES. macData is the MAC value of the message ciphertext data sent by the front-end application system.

[0182] f hsmEncMacKey(v, alg): Generate MAC calculation key MACKEY through this method. This method first processes the initial vector v, expands it into hexadecimal, and right-pads "00" if it is less than 32 characters. Then, it calls the encryption machine and encrypts it using the protection key MACKEYENKEY. The encryption algorithm type is specified by alg. The encrypted data is returned as the MAC calculation key MACKEY.

[0183] f hsmMac (f hsmEncMacKey (v, alg), encMsg, alg): For the message ciphertext data, use the MAC calculation key MACKEY and alg to specify the key algorithm type to call the encryption machine to perform ANSI 9.9 algorithm MAC calculation to obtain the MAC check value macData of the message ciphertext data.

[0184] f cmp (f hsmMac (f hsmEncMacKey (v,alg),encMsg,alg),macData): compare the macData obtained by calling the encryption machine with the mac value macData of the message ciphertext data sent by the front-end application system. If they are equal, the verification passes, otherwise the verification fails.

[0185] For example: self-service terminal (number: 00800001), encryption algorithm type alg is SM4 algorithm, message encryption key key MSGKEYENKEY: 12DE1234A234A23B1234F23EE234FC34, MAC key encryption key MSGKEYENKEY: DFD8A391375403C94FFC978DD962314A, receive the message data sent by the front-end application system:

[0186] {"header":{"devId":"00800001","macData":"37FA87DC6DF3C5226888BF77EFD5DD92"},"body":"1E717F9BAE72F6F4DEF98BADFF7899724943FF36101941CD3DCEBD61BF DEA17E81E0B8F0EBC83C15963A4534FCB7B3B23532F78FC95F3E7028D38E58634938326 8961AB5C779F5FC8B2FCC32EA102DF44295DAF14BC8A4E39E3C9F1114027327"}, its processing process:

[0187] The initial vector v=00800001, after hexadecimal expansion and padding, HEX(v)=3030383030303031000000000000000000, and the calculation results are:

[0188] MACKEY=f hsmEncMacKey (v,alg)=9DE19B709DD9F49048D5E9AB11A6D17D

[0189] macData=37FA87DC6DF3C5226888BF77EFD5DD92

[0190] encMsg=1E717F9BAE72F6F4DEF98BADFF7899724943FF36101941CD3DCEBD61BFDEA17E81E0B8F0EBC83C15963A4534FCB7 B3B23532F78FC95F3E7028D38E586349383268961AB5C779F5FC8B2FCC32EA102DF44295DAF14BC8A4E39E3C9F1114027327

[0191] The obtained MAC check value is:

[0192] f hsmMac (f hsmEncMacKey (v,alg),encMsg,alg)=37FA87DC6DF3C5226888BF77EFD5DD92

[0193] f cmp (f hsmMac (f hsmEncMacKey (v,alg),encMsg,alg),macData), verification passed.

[0194] Specific decryption method:

[0195] f decP (v,encMsg,alg)=f hsmDec (f hsmEncMsgKey (v,alg),encMsg,alg)

[0196] Among them, the parameter v is the initial vector, which is consistent with the initial vector used in the encryption process of the front-end application system, and is used to generate the message decryption key MSGKEY, whose value is the self-service terminal number; encMsg is the ciphertext; alg is the decryption algorithm type, whose value is SM4 or 3DES.

[0197] f hsmEncMsgKey(v, alg): It represents generating the message decryption key MSGKEY through this method. This method first processes the initialization vector v, expands it in hexadecimal. If it is less than 32 characters, pad with "00" on the right, and then calls the encryption machine to encrypt it using the protection key MSGKEYENKEY. The encryption algorithm type is specified by alg. The encrypted data is returned as the message decryption key MSGKEY.

[0198] f hsmDec (f hsmEncMsgKey (v, alg), encMsg, alg): It represents decrypting the received message ciphertext data using the key MSGKEY and the encryption algorithm specified by alg, and the decryption mode uses ECB. Considering the limited data size that the encryption machine can process at one time, it is specially designed to call the encryption machine to decrypt the data to be decrypted in batches by 1024-byte blocks, splice the data obtained from each decryption to get the final message. Then perform padding character removal processing on it. Finally, perform hexadecimal to character conversion processing on it to restore the readable plaintext format data.

[0199] MSGKEY = f hsmEncMsgKey (v, alg) = 6DD1CAE75F983C95C6CAA61D3373FE86

[0200] msg = 1E717F9BAE72F6F4DEF98BADFF7899724943FF36101941CD3DCEBD61BFDEA17E81E0B8F0EBC83C15963A4534FCB7B3B23532F78FC95F3E7028D38E586349383268961AB5C779F5FC8B2FCC32EA102DF44295DAF14BC8A4E39E3C9F1114027327

[0201] f hsmDec (f hsmEncMsgKey (v, alg), encMsg, alg)

[0202] = {"picData1": "123123334323", "picData2": "3452344444", "name": "李四", "idNo": "432234433132222222"}

[0203] The plaintext of the message body obtained through the above decryption method is:

[0204] {"picData1":"123123334323","picData2":"3452344444","name":"Li Si","idNo":"432234433132222222"}

[0205] Finally, the reported clear text data sent by the front-end application system received by the back-end front-end system is as follows:

[0206] {"header":{"devId":"0080001","macData":"37FA87DC6DF3C5226888BF77EFD5DD92"},"body":{"picData1":"123123334323","picData2":"3452344444","name":"Li Si","idNo":"432234433132222222"}}

[0207] Specific encryption method:

[0208] f encP (v,msg,alg) = f hsmEnc (f hsmEncMsgKey (v,alg), f hex (msg), alg)

[0209] Among them, the parameter v is the initial vector, which is the same as the initial vector used in the encryption process of the front-end application system, and is used to generate the message encryption key MSGKEY. Its value is the self-service terminal number; msg is the message to be encrypted; alg is the encryption algorithm type, and its value is SM4 or 3DES.

[0210] f hsmEncMsgKey (v,alg): Generate the message encryption key MSGKEY through this method. This method first processes the initial vector v, expands it to hexadecimal, and if it is less than 32 characters, fill in "00" on the right, and then call the encryption machine to encrypt it with MSGKEYENKEY. The encryption algorithm type is specified by alg. Return the encrypted data as the message encryption key MSGKEY.

[0211] f hex (msg): Perform hexadecimal expansion processing on the message data msg to be encrypted.

[0212] f hsmEnc (f hsmEncMsgKey (v,alg), f hex(msg, alg): Encrypt the processed message data using the encryption algorithm specified by the key MSGKEY and alg. The encryption mode uses ECB. Before encryption, right-pad the message data with "00" in different lengths according to the alg algorithm type. If it is of the SM4 type, the total data length after padding is an integer multiple of 16. If it is of the 3DES type, the total data length after padding is an integer multiple of 8. Considering the limited data size that can be processed by the encryption machine at one time, it is specially designed to call the encryption machine in batches by dividing the padded data to be encrypted into chunks of 1024 bytes, and splice the data obtained from each encryption to get the final encrypted message.

[0213] For example: Self-service terminal (serial number: 00800001), the encryption algorithm type alg is the SM4 algorithm, the message encryption key MSGKEYENKEY: 12DE1234A234A23B1234F23EE234FC34, the MAC key encryption key MSGKEYENKEY: DFD8A391375403C94FFC978DD962314A, return the plaintext of the response message data of the front-end application system as follows:

[0214] {"header":{"devId":"00800001","macData":""},"body":{"result":"0000","name":"Li Si","idNo":"432234433132222222","custId":"12345678901234"}}. Its processing process:

[0215] The initial vector v = 00800001, after hexadecimal expansion and padding processing, HEX(v) = 30303830303030310000000000000000, and after calculation:

[0216] MSGKEY = f hsmEncMsgKey (v, alg) = 6DD1CAE75F983C95C6CAA61D3373FE86

[0217] msg = {"result":"0000","name":"Li Si","idNo":"432234433132222222","custId":"12345678901234"}

[0218] f hex (msg)

[0219] =7B22726573756C74223A2230303030222C6E616D65223A22C0EECBC4222C2269644E6F223A223433323 23334343333313332323232323232222C22637573744964223A223132333435363738393031323334227D

[0220] f hsmEnc (f hsmEncMsgKey (v,alg),f hex (msg),alg)

[0221] =A26D0A5C87218735A1A0DA569ECADA5EB106908A86384FCB328F1A38BFD8407DA1620EDD320023F5C39D5ED47C3F033 3C0702B18F5A149E077E3299271263AA5B635333C247A8F43CCCDCAA00D647A8866FB0EB9B4ED4418F93EF64824D2F07F

[0222] The message ciphertext is obtained by the above encryption method:

[0223] A26D0A5C87218735A1A0DA569ECADA5EB106908A86384FCB328F1A38BFD8407DA1620EDD320023F5C39D5ED47C3F0333 C0702B18F5A149E077E3299271263AA5B635333C247A8F43CCCDCAA00D647A8866FB0EB9B4ED4418F93EF64824D2F07F

[0224] Then perform MAC calculation on the message ciphertext to meet the data integrity requirements.

[0225] Specific MAC calculation method:

[0226] f macP (v,encMsg,alg)=f hsmMac (f hsmEncMacKey (v,alg),encMsg,alg)

[0227] Among them, the parameter v is the initial vector, which is consistent with the initial vector used in the MAC calculation process of the front-end application system, and is used to generate the MAC key MACKEY, and its value is the self-service terminal number; encMsg is the encrypted message ciphertext data; alg is the MAC calculation algorithm type, and its value is SM4 or 3DES.

[0228] f hsmEncMacKey (v,alg): Generate MACKEY through this method. This method first processes the initial vector v, expands it into hexadecimal, and pads it with "00" on the right if it is less than 32 characters. Then, it calls the encryption machine and encrypts it using MACKEYENKEY. The encryption algorithm type is specified by alg. The encrypted data is returned as the MACKEY.

[0229] f hsmMac (f hsmEncMacKey (v, alg), encMsg, alg): Use the key MACKEY and the key algorithm type specified by alg to call the encryption machine to perform ANSI 9.9 algorithm MAC calculation on the message ciphertext data to obtain the MAC check value MACDATA of the message ciphertext data.

[0230] Taking the message used by the encryption method as an example, the calculation process is:

[0231] MACKEY=f hsmEncMacKey (v,alg)=9DE19B709DD9F49048D5E9AB11A6D17D

[0232] The obtained MAC check value is:

[0233] f hsmMac (f hsmEncMacKey (v,alg),encMsg,alg)=5A575B49482D1344A76F68C6FCFDCD87

[0234] Finally, the message data that the back-end front-end system finally returns to the front-end application system is:

[0235] {"header":{"devId":"00800001","macData":"5A575B49482D1344A76F68C6FCFDCD87"},"body":"A26D0A5C87218735A1A0DA569ECADA5EB106908A86384FCB328F1A3 8BFD8407DA1620EDD320023F5C39D5ED47C3F0333C0702B18F5A149E077E329927126 3AA5B635333C247A8F43CCCDCAA00D647A8866FB0EB9B4ED4418F93EF64824D2F07F"}

[0236] First, MAC calculation is performed on the received ciphertext, and MAC verification is performed to meet data integrity requirements.

[0237] Specific MAC calculation and verification methods:

[0238] f macChckC (v,encMsg,macData,alg)=f cmp (f jsMac (f eppEncMacKey (v,alg),encMsg,alg),macData)

[0239] Among them, parameter v is the initial vector, which is consistent with the initial vector used in the MAC calculation process of the back-end front-end system, and is used to generate the MAC key MACKEY, whose value is the self-service terminal number; encMsg is the encrypted message ciphertext data; alg is the MAC calculation algorithm type, whose value is SM4 or 3DES. macData is the mac value of the message ciphertext data returned by the back-end front-end system.

[0240] f eppEncMacKey (v,alg): Generate MACKEY through this method. This method first processes the initial vector v, expands it into hexadecimal, and right-pads "00" if it is less than 32 characters. Then, it calls the password keyboard and encrypts it using MACKEYENKEY. The encryption algorithm type is specified by alg. The encrypted data is returned as the MACKEY.

[0241] f jsMac (f eppEncMacKey (v, alg), encMsg, alg): Perform ANSI 9.9 algorithm MAC calculation on the ciphertext data of the message using the key MACKEY and the key algorithm type specified by alg to obtain the MAC check value macData of the ciphertext data of the message.

[0242] f cmp (f jsMac (f eppEncMacKey (v, alg), encMsg, alg), macData): compare the obtained macData with the mac value macData of the message ciphertext data returned by the back-end front-end system. If they are equal, the verification passes, otherwise the verification fails.

[0243] For example: self-service terminal (number: 00800001), encryption algorithm type alg is SM4 algorithm, message encryption key key MSGKEYENKEY: 12DE1234A234A23B1234F23EE234FC34, MAC key encryption key MSGKEYENKEY: DFD8A391375403C94FFC978DD962314A, receive the message data returned by the back-end front-end system:

[0244] {"header":{"devId":"00800001","macData":"5A575B49482D1344A76F68C6FCFDCD87"},"body":"A26D0A5C87218735A1A0DA569ECADA5EB106908A86384FCB328F1A38BFD8407DA1620EDD320023F5C39D5ED47C3F0333C0702B18F5A149E077E3299271263AA5B635333C247A8F43CCCDCAA00D647A8866FB0EB9B4ED4418F93EF64824D2F07F"}, its processing process:

[0245] The initial vector v=00800001, after hexadecimal expansion and padding, HEX(v)=3030383030303031000000000000000000, and the calculation results are:

[0246] MACKEY=f eppEncMacKey (v,alg)=9DE19B709DD9F49048D5E9AB11A6D17D

[0247] macData=5A575B49482D1344A76F68C6FCFDCD87

[0248] encMsg=A26D0A5C87218735A1A0DA569ECADA5EB106908A86384FCB328F1A38BFD8407DA1620EDD320023F5C39D5ED47C3F 0333C0702B18F5A149E077E3299271263AA5B635333C247A8F43CCCDCAA00D647A8866FB0EB9B4ED4418F93EF64824D2F07F

[0249] The obtained MAC check value is:

[0250] f jsMac (f eppEncMacKey (v,alg),encMsg,alg)=5A575B49482D1344A76F68C6FCFDCD87

[0251] f cmp (f jsMac (f eppEncMacKey (v,alg),encMsg,alg),macData), MAC verification passed.

[0252] Specific decryption method:

[0253] f decC (v,msg,alg)=f jsDec (f eppEncMsgKey (v,alg),msg,alg)

[0254] Among them, the parameter v is the initial vector, which is consistent with the initial vector used in the encryption process of the front-end application system, and is used to generate the message encryption key MSGKEY, whose value is the self-service terminal number; msg is the message to be encrypted; alg is the encryption algorithm type, whose value is SM4 or 3DES.

[0255] f eppEncMsgKey (v, alg): Generates the message encryption key MSGKEY through this method. This method first processes the initial vector v, expands it into hexadecimal, and pads it with "00" on the right if it is less than 32 characters. Then, it calls the encryption machine and encrypts it using MSGKEYENKEY. The encryption algorithm type is specified by alg. The encrypted data is returned as the message encryption key MSGKEY.

[0256] f jsDec (f eppEncMsgKey(v,alg),msg,alg): Decrypt the received message ciphertext data using the key MSGKEY and the encryption algorithm specified by alg. The decryption mode uses ECB. De-fill the decrypted backend data. Finally, perform hexadecimal conversion to restore the readable plaintext format data.

[0257] For example: self-service terminal (number: 00800001), encryption algorithm type alg is SM4 algorithm, message encryption key key MSGKEYENKEY: 12DE1234A234A23B1234F23EE234FC34, MAC key encryption key MSGKEYENKEY: DFD8A391375403C94FFC978DD962314A, receive the message data returned by the back-end front-end system:

[0258] {"header":{"devId":"00800001","macData":"5A575B49482D1344A76F68C6FCFDCD87"},"body":"A26D0A5C87218735A1A0DA569ECADA5EB106908A86384FCB328F1A38BFD8407DA1620EDD320023F5C39D5ED47C3F0333C0702B18F5A149E077E3299271263AA5B635333C247A8F43CCCDCAA00D647A8866FB0EB9B4ED4418F93EF64824D2F07F"}, its processing process:

[0259] The initial vector v=00800001, after hexadecimal expansion and padding, HEX(v)=3030383030303031000000000000000000, and the calculation results are:

[0260] MSGKEY=f eppEncMsgKey (v,alg)=6DD1CAE75F983C95C6CAA61D3373FE86

[0261] msg = A26D0A5C87218735A1A0DA569ECADA5EB106908A86384FCB328F1A38BFD8407DA1620EDD320023F5C39D5ED47C3F0333C0702B18F5A149E077E3299271263AA5B635333C247A8F43CCCDCAA00D647A8866FB0EB9B4ED4418F93EF64824D2F07F

[0262] f jsDec (f eppEncMsgKey (v, alg), msg, alg) = {"result": "0000", "name": "李四", "idNo": "432234433132222222", "custId": "12345678901234"}

[0263] The clear text of the message body obtained by the above decryption method is:

[0264] {"result": "0000", "name": "李四", "idNo": "432234433132222222", "custId": "12345678901234"}

[0265] Finally, the clear text data of the message returned by the backend front-end system received by the front-end application system is:

[0266] {"header": {"devId": "0080001", "macData": "5A575B49482D1344A76F68C6FCFDCD87"}, "body": {"result": "0000", "name": "李四", "idNo": "432234433132222222", "custId": "12345678901234"}}】

[0267] Example 6:

[0268] Referring to Example 1, this example provides a system based on the above encryption and decryption method, which includes a front-end application system, a backend front-end system, and a channel business management system.

[0269] Among them, the front-end application system includes: a terminal check-in module, a business module, a password keyboard device JS module, a key management module, and a message communication module.

[0270] Specifically, the terminal sign-in module is used to send a key application request to the back-end front-end system, and then the front-end application system obtains the terminal working key sent by the back-end system. The business module is used to obtain the message data to be encrypted (message data containing customer information); the key management module is used to import the terminal working key into the password keyboard; the password keyboard device JS module calls the password keyboard and uses the protection key MACKEYENKEY and the protection key MSGKEYENKEY to encrypt the message data containing sensitive data and calculate the MAC value. The front-end communication module is used to send the MAC value and ciphertext to the back-end front-end system in the form of a message.

[0271] Among them, the back-end front-end system includes: terminal key management module, channel access module, and encryption machine communication module.

[0272] Specifically, the terminal key management module is used to respond to the key application request of the front-end application system to call the encryption machine to generate the terminal working key; the channel access module is used to establish a communication connection with the front-end application system to realize data transmission; the encryption machine communication module is used to call the encryption machine and use the protection key MACKEYENKEY to calculate the MAC value of the encrypted message data; verify whether the MAC value in the received message is the same as the calculated MAC value, if not, reject the request; otherwise, call the encryption machine and use the protection key MSGKEYENKEY to decrypt to obtain a plaintext message.

[0273] In this embodiment, the encryption machine communication module provides corresponding interface abstraction and can connect to encryption machines of different manufacturers. The channel access module is used to provide interface services to the front-end application system.

[0274] Considering the processing process of the message data containing the response information, the processing process of each module of the front-end application system and the back-end front-end system is as follows:

[0275] The encryption machine communication module of the back-end front-end system is used to call the encryption machine, and use the message encryption key MSGKEY generated by the encryption key MSGKEYENKEY of the message encryption key stored in the database to encrypt the message, and call the encryption machine to use the MAC key MACKEY generated by the MAC key encryption key MACKEYENKEY stored in the database to calculate the MAC check value for the obtained ciphertext, and place the MAC check value in the message header, and the ciphertext as the message body, and return it to the front-end application system through the channel access module.

[0276] After the front-end communication module of the front-end application system receives the response message, the JS module of the password keyboard device calls the password keyboard and uses the MACKEY generated by MACKEYENKEY to calculate the MAC check value for the ciphertext message data, and then compares it with the MAC in the message header to see if they are consistent. If they are inconsistent, a friendly prompt is given and the current business process is terminated. Otherwise, the key keyboard is called and the MSGKEY generated by MSGKEYENKEY is used to decrypt the ciphertext message data. After obtaining the plain text, it is handed over to the subsequent processing flow of the business module of the front-end application system for further processing.

[0277] It should be noted that, referring to the method contents of Examples 2-5 and the implementation process of each functional module of the above-mentioned front-end application system and back-end front-end system, the front-end application system and back-end front-end system of the present invention can also be used as independent subsystems, and their functional modules and the implementation process of the functional modules refer to the method contents of Examples 2-5 and the contents of the functional modules in Example 6.

[0278] The division of the functional modules of the channel business management system can refer to Figure 1 As shown, since this module is not the focus of protection of the present invention, no specific statement and restriction will be made on it. In brief: the channel business management system includes a terminal parameter management module for providing the terminal key algorithm type parameterized configuration to the front-end application system, a terminal key management module for terminal master key envelope printing and terminal master key binding provided to the back-end front-end system, and an encryption machine communication module for calling an encryption machine to print the terminal master key envelope.

[0279] Embodiment 7:

[0280] This embodiment provides a readable storage medium storing a computer program, wherein the computer program is called by a processor to implement:

[0281] The steps of a message encryption method or a message decryption method or a message encryption and decryption method of Embodiment 1-5 can be specifically referred to the contents of the aforementioned Embodiment 1-5, which will not be repeated here.

[0282] The readable storage medium is a computer-readable storage medium, which may be an internal storage unit of the controller described in any of the foregoing embodiments, such as a hard disk or memory of the controller. The readable storage medium may also be an external storage device of the controller, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the controller. Further, the readable storage medium may also include both an internal storage unit of the controller and an external storage device. The readable storage medium is used to store the computer program and other programs and data required by the controller. The readable storage medium may also be used to temporarily store data that has been output or is to be output.

[0283] Based on this understanding, the technical solution of the present invention, in essence or in other words, the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned readable storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., various media that can store program codes.

[0284] It should be emphasized that the examples described in the present invention are illustrative rather than restrictive, and therefore the present invention is not limited to the examples described in the specific embodiments. Any other embodiments derived by those skilled in the art based on the technical solution of the present invention that do not depart from the purpose and scope of the present invention, whether modified or replaced, also fall within the scope of protection of the present invention.

Claims

1. A message encryption method, characterized in that: Applied to the requester or responder to encrypt the message data containing sensitive data on the requester; Or used to encrypt the response information of the responder; When applied to the request side, it includes: Send a key application request to the responding end, and then obtain the terminal working key sent by the responding end and import it into the password keyboard; wherein the terminal working key includes: protection key MACKEYENKEY, protection key MSGKEYENKEY; Obtain message data containing sensitive data; Call the password keyboard, use the protection key MSGKEYENKEY to generate the message encryption and decryption key MSGKEY, and then encrypt the message data containing sensitive data; use the protection key MACKEYENKEY to generate the MAC calculation key MACKEY, and then calculate the MAC value based on the ciphertext; then send the MAC value and ciphertext to the responding end in the form of a message, so that the responding end can use the terminal working key to verify and decrypt the MAC value; Among them, the encryption and / or MAC calculation process on the request end is implemented using the JS soft algorithm; Or when applied to the response side, including: Get the message data containing the response information; Call the encryption machine, encrypt the message data containing the response information based on the message encryption and decryption key MSGKEY generated by the protection key MSGKEYENKEY; calculate the MAC value based on the MAC calculation key MACKEY generated by the protection key MACKEYENKEY and the ciphertext; then send the MAC value and ciphertext to the requesting end in the form of a message, so that the requesting end can use the terminal working key to verify and decrypt the MAC value, and finally execute the response; Among them, the encryption key and MAC calculation process of the encryption process correspond one to one with the decryption key and MAC calculation process of the decryption process; The process of encrypting the message data using the message encryption and decryption key MSGKEY to obtain the ciphertext is expressed as: f encC (v,msg,alg)=f jsEnc (f eppEncMsgKey (v,alg),f hex (msg),alg) In the formula, f encC (v, msg, alg) represents the encrypted ciphertext; f eppEncMsgKey (v,alg) represents the generated message encryption and decryption key MSGKEY; v is the initial vector, which is expanded into hexadecimal; f hex (msg) indicates that the encrypted message data msg is expanded in hexadecimal. alg indicates the algorithm type, which specifies whether the encryption and decryption algorithm uses the international algorithm or the national secret algorithm. jsEnc Indicates the use of the key MSGKEY to f hex (msg) performs JS soft encryption using the algorithm specified by alg; The process of calculating the MAC value of the ciphertext using the MAC calculation key MACKEY is expressed as: f macC (v,encMsg,alg)=f jsMac (f eppEncMacKey (v,alg),encMsg,alg) In the formula, f macC (v,encMsg,alg) represents the calculated MAC value of the ciphertext, f eppEncMacKey (v, alg) represents the MAC calculation key MACKEY generated during the encryption process, encMsg represents the ciphertext, f jsMac Indicates using the key MACKEY to perform JSMAC calculation on the ciphertext encMsg using the algorithm specified by alg; After receiving the ciphertext, the responder uses the MAC calculation key MACKEY to calculate the MAC value of the message, and the verification process is expressed as follows: f macChckP (v,encMsg,macData,alg)=f cmp (f hsmMac (f hsmEncMacKey (v,alg),encMsg,alg),macData) In the formula, v is the initial vector, alg is the MAC calculation algorithm type, and f hsmEncMacKey (v, alg) is the MAC calculation key MACKEY generated during the decryption process, and macData is the MAC value in the message received from the requester; f hsmMac (f hsmEncMacKey (v, alg), encMsg, alg): for the message ciphertext data, use the MAC calculation key MACKEY and alg to specify the key algorithm type to call the encryption machine to perform ANSI 9.9 algorithm MAC calculation to obtain the message ciphertext data MAC check value macData; f cmp (f hsmMac (f hsmEncMacKey (v, alg), encMsg, alg), macData): compare the macData obtained by calling the encryption machine with the mac value macData of the message ciphertext data sent by the requesting end. If they are equal, the verification passes, otherwise the verification fails; The process of decrypting the plaintext message using the message encryption and decryption key MSGKEY is expressed as follows: f decP (v,encMsg,alg)=f hsmDec (f hsmEncMsgKey (v,alg),encMsg,alg) The parameter v is the initial vector, which is consistent with the initial vector used in the encryption process of the request end, and is used to generate the message encryption key MSGKEY, whose value is the self-service terminal number; encMsg is the ciphertext; alg is the decryption algorithm type, whose value is SM4 or 3DES; f hsmEncMsgKey (v,alg): indicates that the message decryption key MSGKEY is generated by this method; f hsmDec (f hsmEncMsgKey (v,alg),encMsg,alg): indicates that the received message ciphertext data is decrypted using the key MSGKEY and the encryption algorithm specified by alg, and the decryption mode uses ECB; the data to be decrypted is divided into blocks and batches of 1024 bytes and the encryption machine is called for decryption, and the data obtained from each decryption is concatenated to obtain the final message; then the padding characters are removed; finally, the hexadecimal character conversion is performed to restore the readable plaintext format data.

2. A message decryption method, characterized in that: Applied to the requester or responder to decrypt the encrypted response information sent by the responder; Or used to decrypt encrypted message data containing sensitive data sent by the requester; When applied to the response side, it includes: Receive the key application request from the requesting end, then call the encryption machine to generate the terminal working key and feed it back to the requesting end; wherein the terminal working key includes: protection key MACKEYENKEY, protection key MSGKEYENKEY; Receive encrypted message data sent by the requesting end; wherein the encrypted message data is obtained after the requesting end calls the password keyboard and uses the terminal working key to encrypt the message data to be encrypted and calculates the MAC value; Calling the encryption machine to calculate the MAC value of the encrypted message data based on the MAC calculation key MACKEY generated by the protection key MACKEYENKEY; Verify whether the MAC value in the received message is the same as the calculated MAC value. If not, reject the request; otherwise, call the encryption machine and decrypt the message encryption and decryption key MSGKEY generated based on the protection key MSGKEYENKEY to obtain a plaintext message, and then generate a response message; When applied to the request side, it includes: Receiving encrypted message data containing response information sent by the responding end, wherein the encrypted message data is obtained after the responding end calls the encryption machine and uses the terminal working key to encrypt the message data containing the response information and calculates the MAC value; Calling the password keyboard to calculate the MAC value of the encrypted message data based on the MAC calculation key MACKEY generated by the protection key MACKEYENKEY; Verify whether the MAC value in the received encrypted message is the same as the calculated MAC value. If not, reject the request; otherwise, call the password keyboard and decrypt the message encryption and decryption key MSGKEY generated based on the protection key MSGKEYENKEY to obtain a plaintext message, and then execute the response; Among them, the encryption key and MAC calculation process of the encryption process correspond one-to-one with the decryption key and MAC calculation process of the decryption process, and the decryption and / or MAC calculation process on the request end is implemented using the JS soft algorithm; The process of encrypting the message data using the message encryption and decryption key MSGKEY to obtain the ciphertext is expressed as: f encC (v,msg,alg)=f jsEnc (f eppEncMsgKey (v,alg),f hex (msg),alg) In the formula, f encC (v, msg, alg) represents the encrypted ciphertext; f eppEncMsgKey (v,alg) represents the generated message encryption and decryption key MSGKEY; v is the initial vector, which is expanded into hexadecimal; f hex (msg) indicates that the encrypted message data msg is expanded in hexadecimal. alg indicates the algorithm type, which specifies whether the encryption and decryption algorithm uses the international algorithm or the national secret algorithm. jsEnc Indicates the use of the key MSGKEY to f hex (msg) performs JS soft encryption using the algorithm specified by alg; The process of calculating the MAC value of the ciphertext using the MAC calculation key MACKEY is expressed as: f macC (v,encMsg,alg)=f jsMac (f eppEncMacKey (v,alg),encMsg,alg) In the formula, f macC (v,encMsg,alg) represents the calculated MAC value of the ciphertext, f eppEncMacKey (v, alg) represents the MAC calculation key MACKEY generated during the encryption process, encMsg represents the ciphertext, f jsMac Indicates using the key MACKEY to perform JSMAC calculation on the ciphertext encMsg using the algorithm specified by alg; After receiving the ciphertext, the responder uses the MAC calculation key MACKEY to calculate the MAC value of the message, and the verification process is expressed as follows: f macChckP (v,encMsg,macData,alg)=f cmp (f hsmMac (f hsmEncMacKey (v,alg),encMsg,alg),macData) In the formula, v is the initial vector, alg is the MAC calculation algorithm type, and f hsmEncMacKey (v, alg) is the MAC calculation key MACKEY generated during the decryption process, and macData is the MAC value in the message received from the requester; f hsmMac (f hsmEncMacKey (v, alg), encMsg, alg): for the message ciphertext data, use the MAC calculation key MACKEY and alg to specify the key algorithm type to call the encryption machine to perform ANSI 9.9 algorithm MAC calculation to obtain the message ciphertext data MAC check value macData; f cmp (f hsmMac (f hsmEncMacKey (v, alg), encMsg, alg), macData): compare the macData obtained by calling the encryption machine with the mac value macData of the message ciphertext data sent by the requesting end. If they are equal, the verification passes, otherwise the verification fails; The process of decrypting the plaintext message using the message encryption and decryption key MSGKEY is expressed as follows: f decP (v,encMsg,alg)=f hsmDec (f hsmEncMsgKey (v,alg),encMsg,alg) The parameter v is the initial vector, which is consistent with the initial vector used in the encryption process of the request end, and is used to generate the message encryption key MSGKEY, whose value is the self-service terminal number; encMsg is the ciphertext; alg is the decryption algorithm type, whose value is SM4 or 3DES; f hsmEncMsgKey (v,alg): indicates that the message decryption key MSGKEY is generated by this method; f hsmDec (f hsmEncMsgKey (v,alg),encMsg,alg): indicates that the received message ciphertext data is decrypted using the key MSGKEY and the encryption algorithm specified by alg, and the decryption mode uses ECB; the data to be decrypted is divided into blocks and batches of 1024 bytes and the encryption machine is called for decryption, and the data obtained from each decryption is concatenated to obtain the final message; then the padding characters are removed; finally, the hexadecimal character conversion is performed to restore the readable plaintext format data.

3. The method according to any one of claims 1 or 2, characterized in that: The method is applied to a self-service device, when the request end is a front-end application system, the response end is a back-end front-end system, and the message data to be encrypted in the front-end application system is message data containing customer information; The message data to be encrypted in the back-end front-end system is the response message data returned to the front-end application system after being processed by the business logic.

4. A message encryption and decryption method, characterized in that: The following steps are involved: The front-end application system sends a key application request to the back-end front-end system; The back-end front-end system calls the encryption machine to generate a terminal working key and feeds it back to the front-end application system; wherein the terminal working key includes: a protection key MACKEYENKEY and a protection key MSGKEYENKEY; The front-end application system imports the terminal working key into the password keyboard; The front-end application system obtains message data containing sensitive data; The front-end application system calls the password keyboard, uses the protection key MSGKEYENKEY to generate the message encryption and decryption key MSGKEY, and then encrypts the message data containing sensitive data; uses the protection key MACKEYENKEY to generate the MAC calculation key MACKEY, and then calculates the MAC value based on the ciphertext; then sends the MAC value and ciphertext to the back-end front-end system in the form of a message; Among them, the encryption and / or MAC calculation process on the front-end application system is implemented using the JS soft algorithm; The back-end front-end system receives the message sent by the front-end application system; The back-end front-end system calls the encryption machine to calculate the MAC value of the message based on the MAC calculation key MACKEY generated by the protection key MACKEYENKEY; The back-end front-end system verifies whether the MAC value in the received message is the same as the calculated MAC value. If they are not the same, the request is rejected; otherwise, the encryption machine is called and the message encryption and decryption key MSGKEY generated based on the protection key MSGKEYENKEY is decrypted to obtain the plaintext message, and then subsequent business logic processing is performed; The process of encrypting the message data using the message encryption and decryption key MSGKEY to obtain the ciphertext is expressed as: f encC (v,msg,alg)=f jsEnc (f eppEncMsgKey (v,alg),f hex (msg),alg) In the formula, f encC (v, msg, alg) represents the encrypted ciphertext; f eppEncMsgKey (v,alg) represents the generated message encryption and decryption key MSGKEY; v is the initial vector, which is expanded into hexadecimal; f hex (msg) indicates that the encrypted message data msg is expanded in hexadecimal. alg indicates the algorithm type, which specifies whether the encryption and decryption algorithm uses the international algorithm or the national secret algorithm. jsEnc Indicates the use of the key MSGKEY to f hex (msg) performs JS soft encryption using the algorithm specified by alg; The process of calculating the MAC value of the ciphertext using the MAC calculation key MACKEY is expressed as: f macC (v,encMsg,alg)=f jsMac (f eppEncMacKey (v,alg),encMsg,alg) In the formula, f macC (v,encMsg,alg) represents the calculated MAC value of the ciphertext, f eppEncMacKey (v, alg) represents the MAC calculation key MACKEY generated during the encryption process, encMsg represents the ciphertext, f jsMac Indicates using the key MACKEY to perform JSMAC calculation on the ciphertext encMsg using the algorithm specified by alg; After receiving the ciphertext, the back-end front-end system uses the MAC calculation key MACKEY to calculate the MAC value of the message, and the verification process is expressed as follows: f macChckP (v,encMsg,macData,alg)=f cmp (f hsmMac (f hsmEncMacKey (v,alg),encMsg,alg),macData) In the formula, v is the initial vector, alg is the MAC calculation algorithm type, and f hsmEncMacKey (v, alg) is the MAC calculation key MACKEY generated during the decryption process, and macData is the MAC value in the message received from the front-end application system; f hsmMac (f hsmEncMacKey (v, alg), encMsg, alg): for the message ciphertext data, use the MAC calculation key MACKEY and alg to specify the key algorithm type to call the encryption machine to perform ANSI 9.9 algorithm MAC calculation to obtain the message ciphertext data MAC check value macData; f cmp (f hsmMac (f hsmEncMacKey (v, alg), encMsg, alg), macData): compare the macData obtained by calling the encryption machine with the mac value macData of the message ciphertext data sent by the front-end application system. If they are equal, the verification passes, otherwise the verification fails; The process of decrypting the plaintext message using the message encryption and decryption key MSGKEY is expressed as follows: f decP (v,encMsg,alg)=f hsmDec (f hsmEncMsgKey (v,alg),encMsg,alg) Among them, the parameter v is the initial vector, which is consistent with the initial vector used in the encryption process of the front-end application system, and is used to generate the message encryption key MSGKEY, whose value is the self-service terminal number; encMsg is the ciphertext; alg is the decryption algorithm type, whose value is SM4 or 3DES; f hsmEncMsgKey (v,alg): indicates that the message decryption key MSGKEY is generated by this method; f hsmDec (f hsmEncMsgKey (v,alg),encMsg,alg): indicates that the received message ciphertext data is decrypted using the key MSGKEY and the encryption algorithm specified by alg, and the decryption mode uses ECB; the data to be decrypted is divided into blocks and batches of 1024 bytes and the encryption machine is called for decryption, and the data obtained from each decryption is concatenated to obtain the final message; then the padding characters are removed; finally, the hexadecimal character conversion is performed to restore the readable plaintext format data.

5. The method according to claim 4, characterized in that: Also includes: The back-end front-end system obtains the message data containing the response information; The back-end front-end system calls the encryption machine, and encrypts the message data containing the response information based on the message encryption and decryption key MSGKEY generated by the protection key MSGKEYENKEY; Calculate the MAC value based on the MAC calculation key MACKEY generated by the protection key MACKEYENKEY and the ciphertext, and then send the MAC value and the ciphertext to the front-end application system in the form of a message; The front-end application system receives the encrypted message data containing the response information sent by the back-end front-end system; The front-end application system password keyboard calculates the MAC value of the encrypted message data based on the MAC calculation key MACKEY generated by the protection key MACKEYENKEY; The front-end application system verifies whether the MAC value in the received encrypted message is the same as the calculated MAC value. If they are not the same, the request is rejected. Otherwise, the front-end application system calls the password keyboard and decrypts the message encryption and decryption key MSGKEY generated based on the protection key MSGKEYENKEY to obtain the plaintext message, and then executes the response.

6. A system using the message encryption method according to claim 1, comprising at least a requesting end, characterized in that: The requesting end performs message encryption according to the method described in claim 1, and the requesting end comprises: The terminal sign-in module is used to send a key application request to the responding end, and then the requesting end obtains the terminal working key sent by the responding end; A business module, used to obtain message data to be encrypted; A key management module, used to import the terminal working key into the password keyboard; The password keyboard device JS module is used to call the password keyboard, and use the protection key MACKEYENKEY and the protection key MSGKEYENKEY to encrypt the message data containing sensitive data and calculate the MAC value; The communication module is used to send the MAC value and the ciphertext to the responding end in the form of a message.

7. A system using the message decryption method according to claim 2, comprising at least a requesting end, characterized in that: The requesting end performs message decryption according to the method of claim 2, and the requesting end comprises: The terminal sign-in module is used to send a key application request to the responding end, and then the requesting end obtains the terminal working key sent by the responding end; A key management module, used to import the terminal working key into the password keyboard; The communication module is used to receive the encrypted message data containing the response information sent by the responder; The JS module of the password keyboard device is used to call the password keyboard and use the protection key MACKEYENKEY to calculate the MAC value of the encrypted message data; verify whether the MAC value in the received encrypted message is the same as the calculated MAC value, if not, reject the request; otherwise, call the password keyboard and use the protection key MSGKEYENKEY to decrypt to obtain the plaintext message.

8. A system using the message encryption method according to claim 1, comprising at least a responding end, characterized in that: The responder encrypts the message according to the method described in claim 1, and the responder comprises: The terminal key management module is used to respond to the key application request of the requesting end and call the encryption machine to generate the terminal working key; The channel access module is used to establish a communication connection with the requesting end to realize data transmission; The encryption machine communication module is used to call the encryption machine, use the protection key MACKEYENKEY and the protection key MSGKEYENKEY to encrypt the message data containing the response information and calculate the MAC value, and send the MAC value and ciphertext to the request end in the form of a message through the communication module.

9. A system using the message decryption method according to claim 2, comprising at least a responding end, characterized in that: The responder performs message decryption according to the method of claim 2, and the responder comprises: The terminal key management module is used to respond to the key application request of the requesting end and call the encryption machine to generate the terminal working key; The communication module is used to establish a communication connection with the requesting end to realize data transmission; The encryption machine communication module is used to call the encryption machine and use the protection key MACKEYENKEY to calculate the MAC value of the encrypted message data; verify whether the MAC value in the received message is the same as the calculated MAC value, if not the same, reject the request; otherwise, call the encryption machine and use the protection key MSGKEYENKEY to decrypt to obtain the plaintext message, and then generate the response information.

10. A system based on the message encryption and decryption method according to claim 4, characterized in that: Including front-end application system and back-end front-end system; Among them, the front-end application system includes: The terminal sign-in module is used to send a key application request to the back-end front-end system, and then the front-end application system obtains the terminal working key sent by the back-end system; A business module, used to obtain message data to be encrypted; A key management module, used to import the terminal working key into the password keyboard; The password keyboard device JS module calls the password keyboard, and uses the protection key MACKEYENKEY and the protection key MSGKEYENKEY to encrypt the message data containing sensitive data and calculate the MAC value; The front-end communication module is used to send the MAC value and ciphertext to the back-end system in the form of a message; Among them, the back-end front-end system includes: The terminal key management module is used to respond to the key application request of the front-end application system and call the encryption machine to generate the terminal working key; Channel access module, used to establish communication connection with the front-end application system to realize data transmission; The encryption machine communication module is used to call the encryption machine and use the protection key MACKEYENKEY to calculate the MAC value of the encrypted message data; verify whether the MAC value in the received message is the same as the calculated MAC value, if not, reject the request; otherwise, call the encryption machine and use the protection key MSGKEYENKEY to decrypt to obtain the plaintext message, Finally, subsequent business logic processing is performed to generate response information.

11. A readable storage medium, characterized in that: A computer program is stored, which is called by a processor to implement: The steps of the method of claim 1 or claim 2 or claim 4.