A method and device for encryption
By using the first random key and the second random key calculated by the client and server to generate the data key, the dynamically changing key is used to encrypt and decrypt the data, solving the solid key leakage in the prior art results in the solid key data security risks improve the security of data transmission.
Patent Information
- Application Number
- CN202011224746.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-05
- Publication Date
- 2024-12-10
- Estimated Expiration
- 2040-11-05
AI Technical Summary
In the prior art, the fixed key used by the client after logging into the server encrypts and decrypts data in the session. If the key is leaked, the entire session data will be deciphered, which poses a data security risk.
In the data transmission between the client and the server, the first random key and the second random key calculated according to the timestamp are used to generate the data key. The dynamically changing key is used to encrypt and decrypt the data, ensuring that each data transmission uses different uses key.
The data is encrypted and decrypted through dynamically changing keys, which improves the security of data and applications and prevents the risk of session data being deciphered by key leakage.
Smart Images

Figure CN113761550B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to an encryption method and device. Background Art
[0002] In Internet applications, data security has become a factor that must be considered. Usually, data encryption is used to interact with data between the client and server of the application. Usually, after the client logs in to the server, the server dynamically generates a key and sends it to the client for the client to use in data interaction in the current session.
[0003] In the process of implementing the present invention, the inventors discovered that the prior art has at least the following problems:
[0004] After the client logs in to the server, the server dynamically generates a key for the client to use in the current session. This causes the application to use a fixed key to encrypt or decrypt data during the entire session. If the current session is intercepted and the key is leaked, there is a risk that all interactive data in the entire session will be deciphered, thereby posing a data security issue. Summary of the Invention
[0005] In view of this, an embodiment of the present invention provides an encryption method and device. In a single session, when a client performs a login operation and the login is successful, the server sends a first random key to the client. During data transmission between the client and the server, the client or server obtains the timestamp corresponding to the current time of the sent or received data, and calculates a second random key based on the timestamp. The first random key and the second random key are used to generate a data key, and the client or server uses the data key to encrypt or decrypt data. By using the technical means of generating a data key and encrypting and decrypting data, a dynamically changing key can be used to encrypt and decrypt transmitted data in a single session, thereby improving the security of data and applications.
[0006] To achieve the above-mentioned purpose, according to one aspect of an embodiment of the present invention, an encryption method is provided, which is characterized in that, when applied to a client, it includes: performing a login operation, receiving a first random key sent by a server; obtaining time synchronization information of the server, obtaining the current time according to the time synchronization information, and generating a second random key based on the current time; generating a data key based on the first random key and the second random key; and encrypting and decrypting data according to the data key.
[0007] Optionally, the encryption method is characterized in that:
[0008] Generating a second random key based on the current time includes:
[0009] Obtain a timestamp of the current time; round the timestamp to a set value to obtain a first value, and generate the second random key based on the first value.
[0010] Optionally, the encryption method is characterized in that:
[0011] Based on the first value, generate at least two temporary values; perform an XOR operation on the at least two temporary values to obtain a second value;
[0012] Performing a bit expansion operation on the second value to obtain a third value, and generating the second random key according to the third value and a set number of bits.
[0013] Optionally, the encryption method is characterized in that:
[0014] Execute a login operation, receive a login identifier corresponding to the login operation sent by the service end; when the login identifier indicates that the session has ended, resend the login request.
[0015] To achieve the above-mentioned purpose, according to the second aspect of an embodiment of the present invention, an encryption method is provided, which is characterized in that it is applied to a server and includes: receiving a login request from a client, sending a feedback message corresponding to the login request, and when the feedback message indicates success, sending a first random key corresponding to the login request; obtaining the current time, and generating a second random key based on the current time; generating a data key based on the first random key and the second random key; and encrypting and decrypting data according to the data key.
[0016] Optionally, the encryption method is characterized in that:
[0017] Generating a second random key based on the current time includes: obtaining a timestamp of the current time; rounding the timestamp to a set value to obtain a first value, and generating a second random key based on the first value.
[0018] Optionally, the encryption method is characterized in that:
[0019] Based on the first value, generate at least two temporary values; perform an XOR operation on the at least two temporary values to obtain a second value;
[0020] Performing a bit expansion operation on the second value to obtain a third value, and generating the second random key according to the third value and a set number of bits.
[0021] To achieve the above object, according to a third aspect of an embodiment of the present invention, an encryption device is provided, characterized in that it is applied to a client and includes: a first random key acquisition module, a second random key calculation module and an encryption data processing module; wherein,
[0022] The module for obtaining a first random key is configured to perform a login operation and receive a first random key sent by the server;
[0023] The module for calculating the second random key is configured to obtain time synchronization information of the server, obtain the current time according to the time synchronization information, and generate the second random key based on the current time;
[0024] The encrypted data processing module is used to generate a data key based on the first random key and the second random key; and encrypt and decrypt data according to the data key.
[0025] Optionally, the encryption device is characterized in that
[0026] Generating a second random key based on the current time includes:
[0027] Obtain a timestamp of the current time; round the timestamp to a set value to obtain a first value, and generate the second random key based on the first value.
[0028] Optionally, the encryption device is characterized in that
[0029] Based on the first value, generate at least two temporary values; perform an XOR operation on the at least two temporary values to obtain a second value;
[0030] Performing a bit expansion operation on the second value to obtain a third value, and generating the second random key according to the third value and a set number of bits.
[0031] Optionally, the encryption device is characterized in that
[0032] Execute a login operation, receive a login identifier corresponding to the login operation sent by the service end; when the login identifier indicates that the session has ended, resend the login request.
[0033] To achieve the above-mentioned purpose, according to a fourth aspect of an embodiment of the present invention, an encryption device is provided, characterized in that it is applied to a server and comprises: a first random key sending module, a second random key calculating module and an encryption data processing module; wherein,
[0034] The first random key sending module is configured to receive a login request from a client, send a feedback message corresponding to the login request, and when the feedback message indicates success, send the first random key corresponding to the login request;
[0035] The second random key calculation module is used to obtain the current time and generate the second random key based on the current time;
[0036] The encrypted data processing module is used to generate a data key based on the first random key and the second random key; and encrypt and decrypt data according to the data key.
[0037] Optionally, the encryption device is characterized in that
[0038] Generating a second random key based on the current time includes: obtaining a timestamp of the current time; rounding the timestamp to a set value to obtain a first value, and generating a second random key based on the first value.
[0039] Optionally, the encryption device is characterized in that
[0040] Based on the first value, generate at least two temporary values; perform an XOR operation on the at least two temporary values to obtain a second value;
[0041] Performing a bit expansion operation on the second value to obtain a third value, and generating the second random key according to the third value and a set number of bits.
[0042] To achieve the above-mentioned purpose, according to the fifth aspect of an embodiment of the present invention, an encrypted electronic device is provided, characterized in that it includes: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement any of the methods described in the above-mentioned encryption methods.
[0043] To achieve the above-mentioned purpose, according to the sixth aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored, characterized in that when the program is executed by a processor, any of the encryption methods described above is implemented.
[0044] One embodiment of the above invention has the following advantages or beneficial effects: During a session, when a client performs a login operation and the login is successful, the server sends a first random key to the client. During data transmission between the client and the server, the client or server obtains the timestamp corresponding to the current time of the sent or received data, calculates a second random key based on the timestamp, and uses the first and second random keys to generate a data key. The client or server then encrypts or decrypts data using the data key. By generating a data key and encrypting and decrypting data, dynamically changing keys can be used to encrypt and decrypt transmitted data within a session, thereby improving the security of data and applications.
[0045] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] The accompanying drawings are provided for a better understanding of the present invention and are not intended to limit the present invention.
[0047] Figure 1 This is a flow chart of a client encryption method provided by one embodiment of the present invention;
[0048] Figure 2 This is a flow chart of a server-side encryption method provided by one embodiment of the present invention;
[0049] Figure 3 This is a schematic diagram of a process flow of interaction between a client and a server provided by an embodiment of the present invention;
[0050] Figure 4 1 is a schematic diagram of a process for generating a second random key provided by an embodiment of the present invention;
[0051] Figure 5 This is a schematic structural diagram of an encryption device applied to a client provided by an embodiment of the present invention;
[0052] Figure 6 This is a schematic structural diagram of an encryption device applied to a server provided by an embodiment of the present invention;
[0053] Figure 7 is an exemplary system architecture diagram in which embodiments of the present invention may be applied;
[0054] Figure 8 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0055] The following description of exemplary embodiments of the present invention is made in conjunction with the accompanying drawings, in which various details of the embodiments of the present invention are included to facilitate understanding. These details should be considered as merely exemplary. Therefore, it should be appreciated by those skilled in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for the sake of clarity and conciseness, descriptions of well-known functions and structures are omitted in the following description.
[0056] like Figure 1 As shown, an embodiment of the present invention provides an encryption method, which may include the following steps:
[0057] Step S101: Execute a login operation and receive a first random key sent by a server.
[0058] Specifically, a login operation is performed, i.e., the client sends a login request to the server. When the login is successful, the server generates a first random key and sends it to the client. The client receives the first random key sent by the server. The first random key can be a string of a set length, for example, an 8-byte random string consisting of 0-9 and az (for example, 1azc78nv is the first random key). The first random key is sent to the client together with a feedback message indicating a successful login in response to the login request. It is understood that if the feedback message of the login request indicates a failure, the first random key for the client is not generated.
[0059] Furthermore, the client receives a login identifier (e.g., labeled as tokenID) sent together with a feedback message indicating a successful login. The login identifier is used to indicate the time range from the start to the end of the session. When the session ends, the tokenID (login identifier) can be set to an expired or invalid state. When the login identifier expires or becomes invalid, the client needs to resend the login request; that is, perform the login operation, receive the login identifier corresponding to the login operation sent by the server; when the login identifier indicates that the session has ended, resend the login request; wherein, a session refers to a communication process between the client and the server, including information and data exchange. Usually, a unique identifier is set for a session to identify this session, which is the login identifier described above. It can be understood that the client receives a first random key generated by the server for each session; that is, the first random key is valid in a session.
[0060] Step S102: Obtain time synchronization information of the server, obtain the current time according to the time synchronization information, and generate a second random key based on the current time.
[0061] Specifically, the time synchronization information of the server is obtained. Preferably, the time synchronization information is the time zone information. For example, the time zone information of the server is obtained and the local time zone of the client is set to the time zone information of the server. For example, the time zone information of the server is GMT+8, where GMT refers to Greenwich Mean Time; GMT+8 time zone is Beijing Time in the Eastern Time Zone 8. It can be understood that by setting the local time zone of the client to the time synchronization information of the server (such as time zone information), the time of the client and the server that interact with data is synchronized.
[0062] Furthermore, when sending or receiving data, the current time is obtained according to the time synchronization information; further, a timestamp (e.g., Unix timestamp) of the current time is obtained; for example, the timestamp of the current time is obtained; the timestamp indicates the number of seconds that have elapsed since January 1, 1970 (midnight UTC / GMT) to the current time (excluding leap seconds). An hour is represented by a Unix timestamp format of 3600 seconds; a day is represented by a timestamp of 86400 seconds, excluding leap seconds; for example, at a certain moment, the timestamp of the current time obtained is 1593322562. Furthermore, the timestamp is rounded to a set value to obtain a first value, and the second random key is generated based on the first value; preferably, the timestamp is rounded to 60, because the Unix timestamp is the number of seconds since January 1, 1970, and rounding to 60 is to calculate the number of minutes since January 1, 1970. It can be understood that the valid time range of the timestamp can be set to the minute level through the above calculation, thereby changing the time range of the timestamp expiration from seconds to minutes; for example: 1593322562 is rounded to 60 to obtain an integer 26555376 (that is, the first value); further, the specific steps of calculating the second random key based on the first value are the same as those in the preceding example. Figure 4 Steps S403 to S407 are shown to be the same and will not be described again here.
[0063] Step S103: Generate a data key based on the first random key and the second random key; encrypt and decrypt data according to the data key.
[0064] Specifically, a data key is generated based on the first random key described in step S101 and the second random key described in step S102. There are at least the following methods for generating the data key based on the first random key and the second random key:
[0065] Method 1: The first random key comes first, and the second random key comes second. The two are combined to generate the data key. For example, the first random key is 1azc78nv; the calculated second random key is 443714226298966517082241; the generated data key is 1azc78nv443714226298966517082241.
[0066] The second method: The second random key comes first and the first random key comes second, and the two are combined to generate the data key. For example: the first random key is 1azc78nv; the calculated second random key is 443714226298966517082241; the generated data key is 4437142262989665170822411azc78nv.
[0067] The third method: insert the first random key with fewer bits into the position set by the second random key to generate a data key; alternatively, insert the second random key into the position set by the first random key to generate a data key; for example: the first random key is 1azc78nv; the calculated second random key is 443714226298966517082241; the generated data key is 4437142261azc78nv298966517082241.
[0068] The present invention does not limit the specific method of generating the data key based on the first random key and the second random key; further, the data is encrypted and decrypted using the data key. It can be understood that the sent data is encrypted to form encrypted data, and the encrypted data is sent to the server; at the same time, the received data is decrypted using the data key; in a session, the data key is generated based on the timestamp, so for the client, the data key used to encrypt or decrypt data is different in different time ranges.
[0069] like Figure 2 As shown, an embodiment of the present invention provides an encryption method, which may include the following steps:
[0070] Step S201: receiving a login request from a client, sending a feedback message corresponding to the login request, and when the feedback message indicates success, sending a first random key corresponding to the login request.
[0071] Specifically, the server receives a login request from the client and, based on the client's login request, sends a feedback message corresponding to the login request. If the feedback message indicates success, the server sends a first random key corresponding to the login request; the first random key is a string of a set length. The description of the first random key is consistent with step S101 and is not repeated here.
[0072] Step S202: Acquire the current time, and generate a second random key based on the current time.
[0073] Specifically, when receiving data from the client or sending data to the client, obtain the timestamp of the current time; round the timestamp to the set value to obtain a first value, and generate a second random key based on the first value; obtain the current time of the server, calculate the second random key based on the timestamp of the current time, and generate a data key based on the first random key and the second random key; the description of generating the second random key is consistent with step S 102 and will not be repeated here.
[0074] Step S203: Generate a data key based on the first random key and the second random key; encrypt and decrypt data according to the data key.
[0075] Specifically, the description of generating the data key based on the first random key and the second random key is consistent with step S 103 and will not be repeated here; further, the data is encrypted and decrypted using the data key. It can be understood that the sent data is encrypted to form encrypted data, and the encrypted data is sent to the server; at the same time, the received data is decrypted using the data key.
[0076] like Figure 3 As shown, an embodiment of the present invention provides a method for transmitting encrypted data between a client and a server, and the method may include the following steps:
[0077] Step S301: The client sends a login request.
[0078] Step S302: The server receives the login request and sends a first random key to the client.
[0079] Specifically, the description of step S301-step S302 is: for the client, perform the login operation and receive the first random key sent by the server; for the server, receive the client's login request, send a feedback message corresponding to the login request, and when the feedback message indicates success, send the first random key corresponding to the login request.
[0080] Step S303: The client obtains the time synchronization information (for example, time zone information) of the server, sets the local time zone to the time zone information, and obtains the current time based on the time zone information when sending or receiving data; calculates the second random key based on the timestamp of the current time; generates a data key based on the first random key and the second random key, and encrypts data A based on the data key.
[0081] Step S304: Send the encrypted data A to the server.
[0082] Step S305: The server receives data, obtains the current time, calculates a second random key based on the timestamp of the current time; generates a data key based on the first random key and the second random key; and decrypts data A based on the data key.
[0083] Specifically, steps S303 to S305 describe an example process in which the client encrypts and sends data A, and the server receives and decrypts data A.
[0084] Step S306: The server obtains the current time, calculates a second random key based on the timestamp of the current time, generates a data key based on the first random key and the second random key, and encrypts data B based on the data key.
[0085] Step S307: Send the encrypted data B to the client.
[0086] Step S308: The client receives data, obtains the current time, calculates a second random key based on the current time; generates a data key based on the first random key and the second random key; and decrypts data B based on the data key.
[0087] Specifically, steps S306 to S308 describe an example process in which the server encrypts and sends data B, and the client receives and decrypts data B.
[0088] Furthermore, steps S301-S308 describe the process of data encryption and data interaction between the client and the server in a session; it is understandable that in a session, there may be zero to multiple running processes described in steps S303-S305, or (and) the processes of steps S306-S308 to complete the business of a session; usually the time difference between sending and receiving the same data is in milliseconds; when the difference between the timestamp of the sent data and the timestamp of the received data exceeds the set threshold, a scenario of data decryption failure may occur. When decryption failure occurs, the data sender (client or server) can be notified to resend the data (including the step of calculating the second random key based on the new timestamp) to the receiver (server or client).
[0089] like Figure 4 As shown, an embodiment of the present invention provides a method for calculating a second random key. The exemplary process of this method is described using the process of a client as an example. The method may include the following steps:
[0090] Step S401: Execute a login operation and receive a first random key sent by the server.
[0091] Step S402: Obtain the time synchronization information (eg, time zone information) of the server, and obtain the timestamp of the current time based on the time zone.
[0092] Specifically, the detailed description of the first random key, the time synchronization information, and the timestamp of the current time is consistent with that of step S101 to step S102, and will not be repeated here.
[0093] Step S403: rounding the timestamp of the current time to the set value to obtain a first value.
[0094] Specifically, for example: the timestamp obtained through step S402 is 1593322562, in seconds; further, the timestamp of the current time is rounded to the set value, for example: 60 (that is, the set value) is rounded to obtain 26555376 (that is, the first value); it can be understood that in this embodiment, the set value is preferably set to 60 (1 minute is 60 seconds) to convert the timestamp in seconds into a timestamp in minutes, wherein the set value can be a positive integer greater than or equal to 1, and the present invention does not limit the specific value of the set value.
[0095] Step S404: generating at least two temporary values based on the first value; performing an XOR operation on the at least two temporary values to obtain a second value.
[0096] Specifically, this step is still explained by taking the first numerical value of step S403 as an example. Based on the first numerical value, at least two temporary numerical values are generated. In this embodiment, the generation of two temporary numerical values is taken as an example. For example, the first numerical value is 26555376, and the first six digits are taken to obtain a temporary numerical value of 265553, and the last six digits are taken to obtain a temporary numerical value of 555376; that is, at least two (taking two as an example) temporary numerical values are generated based on 26555376; further, an XOR operation is performed based on the at least two temporary data generated to obtain a second numerical value; for example, an XOR operation is performed based on 265553 and 555376 to obtain 816161, which is the second numerical value; according to the XOR operation in this step, the computational complexity is increased, the computational regularity is reduced, and the difficulty of deciphering the key is increased, thereby improving the security of the data.
[0097] Step S405: performing a bit expansion operation based on the second value to obtain a third value.
[0098] Specifically, a bit expansion operation is performed based on the second value to obtain a third value; wherein the bit expansion operation is an operation method for expanding the number of bits of the second value, and the specific method of the bit expansion operation can be based on the second value to perform exponential operation, product operation, bit value addition, etc., and the bit expansion operation is used to increase the complexity of the second random key; the second value of step S404 is still used as an example for explanation, for example: the second value is 816161, and a bit expansion operation is performed based on 816161. Preferably, an exponential operation is performed based on 816161, for example, calculating its fourth power is calculating 816161. 4 The result is 443714226298966517082241 (i.e., the third value). It is understandable that the number of digits of the value is expanded through the calculation in this step. Optionally, the second value can be expanded, or the second value can be multiplied by the first data and / or the temporary value in step S404.
[0099] Step S406: Generate a second random key according to the third value and the set number of bits.
[0100] Specifically, according to the third value obtained in step S405 and the set number of bits, a second random key is generated; wherein the set number of bits is a positive integer, for example, preferably, 24 is set as the set number of bits, for example, 24 bytes; further, it is determined whether the third value is greater than or equal to 24 bytes, if it is greater than or equal to 24 bytes, the first 24 bytes are taken, and if it is less than 24 bytes, it is necessary to fill in the 24 bytes. It can be understood that when 24 is set as the set number of bits, combined with the example of the first random key (set to 8 bytes), a 32-byte key is generated (for example, in accordance with AES (Advanced Encryption Standard)). Standard) standard 32 bytes, that is, a 256-bit key), so if the third value is greater than or equal to 24 bytes, the first 24 bytes are sufficient; if the third value is less than 24 bytes, a string can be generated based on letters or numbers and added to the end, front, or other positions to make up 24 bytes; for example, if the third value is 12345678901234567890123456, then 123456789012345678901234 is taken as the second random key; if the third value is 123456789012345678, after using letters to make up, 123456789012345678abcdef is used as the second random key, that is, the second random key is generated according to the third value and the set number of bits.
[0101] Step S407: Generate a data key based on the first random key and the second random key.
[0102] Specifically, based on the first random key and the second random key, a data key is generated; assuming that the obtained first random key is 1azc78nv; the calculated second random key is 443714226298966517082241; the method for generating the data key can use a method of combining the first random key and the second random key, for example: the combined key is: 1azc78nv443714226298966517082241; other methods can also be used to combine or calculate the first random key and the second random key to generate the data key; the specific description of the method for generating the data key is consistent with step S 103, and will not be repeated here; the data key is further used for further data encryption.
[0103] The present invention does not limit the number of bits of the first random key and the second random key, the specific method of calculating the second random key based on the timestamp, and the specific method of generating the data key based on the first random key and the second random key.
[0104] like Figure 5 As shown, an embodiment of the present invention provides an encryption device 500, comprising: a first random key acquisition module 501, a second random key calculation module 502 and an encryption data processing module 503; wherein,
[0105] The first random key acquisition module 501 is used to perform a login operation and receive a first random key sent by the server;
[0106] The second random key calculation module 502 is configured to obtain time synchronization information of the server, obtain the current time according to the time synchronization information, and generate a second random key based on the current time;
[0107] The encrypted data processing module 503 is configured to generate a data key based on the first random key and the second random key; and encrypt and decrypt data according to the data key.
[0108] Optionally, the module 502 for calculating the second random key is configured to obtain a timestamp of the current time; round the timestamp to a set value to obtain a first value; and generate the second random key based on the first value.
[0109] Optionally, the module 502 for calculating the second random key is used to generate at least two temporary values based on the first value; perform an XOR operation based on the at least two temporary values to obtain a second value; perform a bit expansion operation based on the second value to obtain a third value, and generate the second random key based on the third value and a set number of bits.
[0110] Optionally, the module for obtaining a first random key 501 is configured to perform a login operation, receive a login identifier corresponding to the login operation sent by the server, and resend a login request when the login identifier indicates that the session has ended.
[0111] like Figure 6 As shown, an embodiment of the present invention provides an encryption device 600, comprising: a first random key sending module 601, a second random key calculation module 602 and an encrypted data processing module 603; wherein,
[0112] The sending first random key module 601 is used to receive a login request from a client, send a feedback message corresponding to the login request, and when the feedback message indicates success, send the first random key corresponding to the login request;
[0113] The second random key calculation module 602 is used to obtain the current time and generate a second random key based on the current time;
[0114] The encrypted data processing module 603 is used to generate a data key based on the first random key and the second random key; encrypt and decrypt data according to the data key
[0115] Optionally, the module 602 for calculating the second random key is used to generate a second random key based on the current time, including: obtaining a timestamp of the current time; rounding the timestamp to a set value to obtain a first value, and generating a second random key based on the first value.
[0116] Optionally, the module 602 for calculating the second random key is used to generate at least two temporary values based on the first value; perform an XOR operation on the at least two temporary values to obtain a second value; perform a bit expansion operation on the second value to obtain a third value, and generate the second random key based on the third value and a set number of bits.
[0117] An embodiment of the present invention also provides an encrypted electronic device, comprising: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method provided in any of the above embodiments.
[0118] An embodiment of the present invention further provides a computer-readable medium having a computer program stored thereon, and when the program is executed by a processor, the method provided in any of the above embodiments is implemented.
[0119] Figure 7 An exemplary system architecture 700 is shown to which the encryption method or encryption apparatus according to an embodiment of the present invention can be applied.
[0120] like Figure 7 As shown, system architecture 700 may include terminal devices 701, 702, 703, a network 704, and a server 705. Network 704 is used to provide a medium for communication links between terminal devices 701, 702, 703 and server 705. Network 704 may include various connection types, such as wired or wireless communication links or fiber optic cables.
[0121] Users can use terminal devices 701, 702, and 703 to interact with server 705 via network 704 to receive or send messages, etc. Various client applications can be installed on terminal devices 701, 702, and 703, such as e-commerce client applications, web browser applications, search applications, instant messaging tools, and email clients.
[0122] The terminal devices 701 , 702 , and 703 may be various electronic devices having a display screen and supporting various client applications, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers.
[0123] Server 705 can be a server that provides various services, such as a background management server that supports client applications used by users on terminal devices 701, 702, and 703. The background management server can process the received client login request and feedback a successful login message and a first random key to the terminal device; the client and server can also generate data keys to encrypt and decrypt the transmitted data.
[0124] It should be noted that the encryption method provided in the embodiment of the present invention is generally executed by the terminal device 701 , 702 , 703 or the server 705 . Accordingly, the encryption device is generally provided in the terminal device 701 , 702 , 703 or the server 705 .
[0125] It should be understood that Figure 7 The number of terminal devices, networks and servers in the embodiment is merely illustrative. Any number of terminal devices, networks and servers may be provided as required.
[0126] Reference below Figure 8 , which shows a schematic structural diagram of a computer system 800 of a terminal device suitable for implementing an embodiment of the present invention. Figure 8 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0127] like Figure 8As shown, the computer system 800 includes a central processing unit (CPU) 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage unit 808 into a random access memory (RAM) 803. Various programs and data required for the operation of the system 800 are also stored in the RAM 803. The CPU 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0128] The following components are connected to the I / O interface 805: an input section 806 including a keyboard, a mouse, and the like; an output section 807 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), and a speaker; a storage section 808 including a hard disk; and a communication section 809 including a network interface card such as a LAN card or a modem. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to the I / O interface 805 as needed. A removable medium 811, such as a magnetic disk, an optical disk, a magneto-optical disk, or a semiconductor memory, is installed in the drive 810 as needed, so that computer programs read therefrom can be installed into the storage section 808 as needed.
[0129] In particular, according to the embodiments disclosed in the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments disclosed in the present invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program comprising program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 809, and / or installed from a removable medium 811. When the computer program is executed by the central processing unit (CPU) 801, the above-mentioned functions defined in the system of the present invention are performed.
[0130] It should be noted that the computer-readable medium described in the present invention can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of computer-readable storage media can include, but are not limited to, an electrical connection having one or more conductors, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. This propagated data signal can take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device. Program code embodied on a computer-readable medium may be transmitted using any suitable medium, including but not limited to wireless, wireline, optical fiber cable, RF, or any suitable combination thereof.
[0131] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present invention. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the above-mentioned module, program segment, or a part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0132] The modules and / or units involved in the embodiments of the present invention may be implemented in software or in hardware. The modules and / or units described may also be provided in a processor. For example, they may be described as follows: a processor includes a module for obtaining a first random key, a module for calculating a second random key, and a module for processing encrypted data. In some cases, the names of these modules do not constitute a limitation on the module itself. For example, a module for calculating a second random key may also be described as a "module for obtaining a timestamp of the current time and calculating a second random key." Another example: a processor includes a module for sending a first random key, a module for calculating a second random key, and a module for processing encrypted data. In some cases, the names of these modules do not constitute a limitation on the module itself. For example, a module for calculating a second random key may also be described as a "module for obtaining a timestamp of the current time and calculating a second random key."
[0133] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently and not be assembled into the device. The above computer-readable medium carries one or more programs. When the above one or more programs are executed by a device, the device includes: the client performs a login operation and receives a first random key sent by the server; obtains the time synchronization information of the server, obtains the current time according to the time synchronization information, and generates a second random key based on the current time; generates a data key based on the first random key and the second random key; encrypts and decrypts data according to the data key; the server receives the login request of the client, sends a feedback message corresponding to the login request, and when the feedback message indicates success, sends the first random key corresponding to the login request; obtains the current time, generates a second random key based on the current time; generates a data key based on the first random key and the second random key; encrypts and decrypts data according to the data key.
[0134] This method allows for a client to log in successfully within a session. The server then sends a first random key to the client. During data transmission between the client and server, the client or server obtains the timestamp of the current time corresponding to the data being sent or received, calculates a second random key based on the timestamp, and uses the first and second random keys to generate a data key. The client or server then uses the data key to encrypt or decrypt data. By generating a data key and encrypting and decrypting data, dynamically changing keys can be used to encrypt and decrypt transmitted data within a session, improving data and application security.
[0135] The above specific embodiments do not limit the scope of protection of the present invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention are intended to be included within the scope of protection of the present invention.
Claims
1. An encryption method, characterized in that: Applied to the client, including: Perform a login operation and receive a first random key sent by the server; wherein the first random key is sent by the server together with a feedback message indicating successful login in response to the login request; the first random key is valid within a time range from the beginning to the end of a session associated with the login; Obtaining time synchronization information of the server, obtaining the current time according to the time synchronization information, and generating a second random key based on the current time; wherein there are multiple second random keys in one session; A data key is generated based on the first random key and the second random key; and data is encrypted and decrypted according to the data key.
2. The method according to claim 1, characterized in that Generating a second random key based on the current time includes: Obtain a timestamp of the current time; round the timestamp to a set value to obtain a first value, and generate the second random key based on the first value.
3. The method according to claim 2, characterized in that Based on the first value, generate at least two temporary values; based on the at least two temporary values, perform an XOR operation to obtain a second value; A third value is obtained by performing a bit expansion operation based on the second value, and the second random key is generated according to the third value and a set number of bits.
4. The method according to claim 1, characterized in that: Execute a login operation, receive a login identifier corresponding to the login operation sent by the service end; when the login identifier indicates that the session is over, resend the login request.
5. An encryption method, characterized in that: Applied to the server, including: Receive a login request from a client, send a feedback message corresponding to the login request, and when the feedback message indicates success, send a first random key corresponding to the login request; the first random key is valid within a time range from the start to the end of a session associated with the login; Acquire the current time, and generate a second random key based on the current time; wherein there are multiple second random keys in one session; A data key is generated based on the first random key and the second random key; and data is encrypted and decrypted according to the data key.
6. The method according to claim 5, characterized in that Generating a second random key based on the current time includes: Get the timestamp of the current time; The timestamp is rounded to a set value to obtain a first value, and a second random key is generated based on the first value.
7. The method according to claim 6, characterized in that Based on the first value, generate at least two temporary values; based on the at least two temporary values, perform an XOR operation to obtain a second value; A third value is obtained by performing a bit expansion operation based on the second value, and the second random key is generated according to the third value and a set number of bits.
8. An encryption device, characterized in that: include: Obtaining a first random key module, calculating a second random key module and processing an encrypted data module; wherein, The module for obtaining the first random key is used to perform a login operation and receive a first random key sent by the server; The module for calculating the second random key is used to obtain the time synchronization information of the server, obtain the current time according to the time synchronization information, and generate the second random key based on the current time; The encrypted data processing module is used to generate a data key based on the first random key and the second random key; The data is encrypted and decrypted according to the data key.
9. An encryption device, characterized in that: include: Sending a first random key module, calculating a second random key module and processing an encrypted data module; wherein, The first random key sending module is used to receive a login request from a client, send a message corresponding to the login request, and when the message indicates success, send a first random key corresponding to the login request; The module for calculating the second random key is used to obtain the current time and generate the second random key based on the current time; The encrypted data processing module is used to generate a data key based on the first random key and the second random key; and encrypt and decrypt data according to the data key.
10. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method as claimed in any one of claims 1-4 or 5-7.
11. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 4 or 5 to 7 is implemented.
