Data encryption and decryption method and device, electronic equipment and storage medium
By storing different types of keys in the preset storage space and encrypting and decrypting processing according to the generation time, the problem of low security caused by reuse of keys in the prior art is solved, and higher data encryption and decryption security is achieved.
Patent Information
- Application Number
- CN202411573554.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-06
- Publication Date
- 2025-02-28
AI Technical Summary
In the prior art, the same key is used for the encryption and decryption processing of different data, resulting in low security of the data encryption and decryption processing.
By storing different types of keys (first type, second type and third type keys) in the preset storage space and encrypting and decrypting the data according to the generation time, it is ensured that the data at different generation time is processed using different keys.
Improve the security of data encryption and decryption processing, and reduce the risk of data leakage and unauthorized access by using different keys to process data at different generation moments.
Smart Images

Figure CN119538282A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a data encryption and decryption method, device, electronic device and storage medium. Background Art
[0002] The basic process of data encryption is to process the original plaintext data according to a certain algorithm to make it unreadable "ciphertext". In this way, the purpose of protecting data from being stolen or read by illegal persons is achieved. The reverse process of encryption is decryption, which is the process of converting the unreadable "ciphertext" into the original data.
[0003] In the related art, the same key is usually used to encrypt and decrypt different data, which results in low security of data encryption and decryption. Summary of the invention
[0004] In view of this, in order to solve some or all of the above-mentioned technical problems, the embodiments of the present application provide a data encryption and decryption method, device, electronic device and storage medium.
[0005] In a first aspect, an embodiment of the present application provides a data encryption and decryption method, the method comprising:
[0006] Obtain target data to be processed;
[0007] Determine whether a target key for encrypting and decrypting the target data is currently stored in a preset storage space, wherein a first type of key and a second type of key are stored in the preset storage space, the first type of key corresponds to a first time period, the second type of key corresponds to a second time period, the end time of the first time period is the start time of the second time period, the first type of key is used to encrypt and decrypt data whose generation time belongs to the first time period, and the second type of key is used to encrypt and decrypt data whose generation time belongs to the second time period;
[0008] In the case where the target key is currently stored in the preset storage space, the target data is encrypted and decrypted using the target key.
[0009] In a possible implementation manner, a third type of key is further stored in the preset storage space; and
[0010] The keys in the preset storage space are processed using the following steps:
[0011] Determine whether the current moment belongs to the most recently determined target time period; wherein the most recently determined target time period is: the second time period corresponding to the most recently determined second type of key;
[0012] In the case that the current moment does not belong to the most recently determined target time period, the first type of key stored in the preset storage space is updated to the second type of key in the preset storage space, and the second type of key stored in the preset storage space is updated to the third type of key in the preset storage space, wherein the third type of key corresponds to a third time period, and the start time of the third time period is the end time of the second time period;
[0013] The most recently determined target time period is updated to the updated second time period corresponding to the second type of key.
[0014] In a possible implementation manner, before the first type of key stored in the preset storage space is updated to the second type of key in the preset storage space, the key in the preset storage space is further processed by the following steps:
[0015] The key of the first type currently stored in the preset storage space is deleted.
[0016] In a possible implementation manner, the first time period, the second time period, and the third time period are equal in length.
[0017] In a possible implementation manner, after the second type of key stored in the preset storage space is updated to the third type of key in the preset storage space, the key in the preset storage space is further processed by the following steps:
[0018] The third type of key is updated to a newly generated key.
[0019] In a possible implementation manner, after the target data is encrypted and decrypted using the target key, the method further includes:
[0020] Determine a decryption result of decrypting the target data using the target key;
[0021] determining whether the decryption result indicates a decryption failure; and
[0022] The step is performed when the decryption result indicates that the decryption fails.
[0023] In a possible implementation manner, the step is performed when the current moment does not belong to the most recently determined target time period.
[0024] In a possible implementation manner, when the target key is not currently stored in the preset storage space, the target data is in a state where it cannot be decrypted.
[0025] In a second aspect, an embodiment of the present application provides a data encryption and decryption device, the device comprising:
[0026] An acquisition unit, used for acquiring target data to be processed;
[0027] A first determining unit, configured to determine whether a target key for encrypting and decrypting the target data is currently stored in a preset storage space, wherein a first type of key and a second type of key are stored in the preset storage space, the first type of key corresponds to a first time period, the second type of key corresponds to a second time period, the end time of the first time period is the start time of the second time period, the first type of key is used to encrypt and decrypt data whose generation time belongs to the first time period, and the second type of key is used to encrypt and decrypt data whose generation time belongs to the second time period;
[0028] The encryption and decryption unit is used to encrypt and decrypt the target data using the target key when the target key is currently stored in the preset storage space.
[0029] In a possible implementation manner, a third type of key is further stored in the preset storage space; and
[0030] The keys in the preset storage space are processed using the following steps:
[0031] Determine whether the current moment belongs to the most recently determined target time period; wherein the most recently determined target time period is: the second time period corresponding to the most recently determined second type of key;
[0032] In the case that the current moment does not belong to the most recently determined target time period, the first type of key stored in the preset storage space is updated to the second type of key in the preset storage space, and the second type of key stored in the preset storage space is updated to the third type of key in the preset storage space, wherein the third type of key corresponds to a third time period, and the start time of the third time period is the end time of the second time period;
[0033] The most recently determined target time period is updated to the updated second time period corresponding to the second type of key.
[0034] In a possible implementation manner, before the first type of key stored in the preset storage space is updated to the second type of key in the preset storage space, the key in the preset storage space is further processed by the following steps:
[0035] The key of the first type currently stored in the preset storage space is deleted.
[0036] In a possible implementation manner, the first time period, the second time period, and the third time period are equal in length.
[0037] In a possible implementation manner, after the second type of key stored in the preset storage space is updated to the third type of key in the preset storage space, the key in the preset storage space is further processed by the following steps:
[0038] The third type of key is updated to a newly generated key.
[0039] In a possible implementation manner, after the target data is encrypted and decrypted using the target key, the device further includes:
[0040] A second determining unit, used to determine a decryption result of decrypting the target data using the target key;
[0041] A third determining unit, configured to determine whether the decryption result indicates a decryption failure; and
[0042] The step is performed when the decryption result indicates that the decryption fails.
[0043] In a possible implementation manner, the step is performed when the current moment does not belong to the most recently determined target time period.
[0044] In a possible implementation manner, when the target key is not currently stored in the preset storage space, the target data is in a state where it cannot be decrypted.
[0045] In a third aspect, an embodiment of the present application provides an electronic device, including:
[0046] Memory for storing computer programs;
[0047] The processor is used to execute the computer program stored in the memory, and when the computer program is executed, the method of any embodiment of the data encryption and decryption method of the first aspect of the present application is implemented.
[0048] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the method of any embodiment of the data encryption and decryption method of the first aspect described above is implemented.
[0049] In a fifth aspect, an embodiment of the present application provides a computer program product, which includes a computer-readable code. When the computer-readable code is executed on a device, the processor in the device implements a method as in any embodiment of the data encryption and decryption method of the first aspect mentioned above.
[0050] The data encryption and decryption method provided by the embodiment of the present application can obtain the target data to be processed, and then determine whether the target key for encrypting and decrypting the target data is currently stored in the preset storage space, wherein the preset storage space stores a first type of key and a second type of key, the first type of key corresponds to a first time period, the second type of key corresponds to a second time period, the end time of the first time period is the start time of the second time period, the first type of key is used to encrypt and decrypt data belonging to the first time period at the time of generation, and the second type of key is used to encrypt and decrypt data belonging to the second time period at the time of generation, and then, in the case where the target key is currently stored in the preset storage space, the target key is used to encrypt and decrypt the target data. Thus, data at different generation times can be encrypted and decrypted by using different types of keys stored in the preset storage space, so that the security of data encryption and decryption can be improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0052] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0053] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.
[0054] Figure 1 A flowchart of a data encryption and decryption method provided in an embodiment of the present application;
[0055] Figure 2 A schematic diagram of a processing flow of a key in a preset storage space involved in a data encryption and decryption method provided in an embodiment of the present application;
[0056] Figure 3 A flowchart of another data encryption and decryption method provided in an embodiment of the present application;
[0057] Figure 4 A schematic diagram of the structure of a data encryption and decryption device provided in an embodiment of the present application;
[0058] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0059] Various exemplary embodiments of the present application will now be described in detail with reference to the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present application, rather than all of the embodiments. It should be noted that unless otherwise specifically stated, the relative arrangement of the components and steps, the numerical expressions and the numerical values described in these embodiments do not limit the scope of the present application.
[0060] Those skilled in the art will understand that the terms "first" and "second" in the embodiments of the present application are only used to distinguish between different steps, devices, modules and other objects, and do not represent any specific technical meanings, nor do they indicate the logical order between them.
[0061] It should also be understood that in this embodiment, “plurality” may refer to two or more than two, and “at least one” may refer to one, two or more than two.
[0062] It should also be understood that any component, data or structure mentioned in the embodiments of the present application can generally be understood as one or more, unless explicitly limited or otherwise indicated in the context.
[0063] In addition, the term "and / or" in this application is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this application generally indicates that the associated objects before and after are in an "or" relationship.
[0064] It should also be understood that the description of the various embodiments in this application focuses on the differences between the various embodiments, and the same or similar aspects thereof can be referenced to each other, and for the sake of brevity, they will not be described one by one.
[0065] The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the present application, its application, or uses.
[0066] Technologies, methods, and equipment known to ordinary technicians in the relevant art may not be discussed in detail, but where appropriate, the above-mentioned technologies, methods, and equipment should be considered as part of the specification.
[0067] It should be noted that like reference numerals and letters refer to similar items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.
[0068] It should be noted that, in the absence of conflict, the embodiments in this application and the features in the embodiments can be combined with each other. To facilitate the understanding of the embodiments of the present application, the present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments. Obviously, the described embodiments are part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0069] In order to solve the technical problem of how to improve the security of data encryption and decryption processing in the prior art, the present application provides a data encryption and decryption method, device, electronic device and storage medium, which can improve the security of data encryption and decryption processing.
[0070] Figure 1 A flow chart of a data encryption and decryption method provided for an embodiment of the present application. The method can be applied to one or more electronic devices such as smart phones, laptops, desktop computers, portable computers, servers, etc. In addition, the execution subject of the method can be hardware or software. When the above-mentioned execution subject is hardware, the execution subject can be one or more of the above-mentioned electronic devices. For example, a single electronic device can execute the method, or multiple electronic devices can cooperate with each other to execute the method. When the above-mentioned execution subject is software, the method can be implemented as multiple software or software modules, or as a single software or software module. It is not specifically limited here.
[0071] like Figure 1 As shown, the method specifically includes:
[0072] Step 101, obtaining target data to be processed.
[0073] In this embodiment, the target data may be any data to be encrypted or decrypted. As an example, the target data may include but is not limited to user information, product information, etc.
[0074] In addition, each target data may correspond to a generation time. The generation time corresponding to the target data may indicate the time when the target data is generated.
[0075] Step 102: determine whether a target key for encrypting and decrypting the target data is currently stored in a preset storage space.
[0076] In this embodiment, the preset storage space stores a first type of key and a second type of key, the first type of key corresponds to a first time period, the second type of key corresponds to a second time period, the end time of the first time period is the start time of the second time period, the first type of key is used to encrypt and decrypt data that belongs to the first time period at the time of generation, and the second type of key is used to encrypt and decrypt data that belongs to the second time period at the time of generation.
[0077] The preset storage space may be a predetermined storage space. At least two types of keys may be stored in the preset storage space. For example, a first type of key, a second type of key, and a third type of key may be stored in the preset storage space. For another example, a first type of key and a second type of key may also be stored in the preset storage space.
[0078] When an asymmetric encryption method is used to encrypt and decrypt data (such as target data), the above-mentioned key (including the target key) may include a public key used for encryption and a private key used for decryption. When a symmetric encryption method is used to encrypt and decrypt data (such as target data), the above-mentioned key may be used for encryption and decryption of data (such as target data).
[0079] The encryption and decryption processing may include at least one of encryption processing and decryption processing.
[0080] The first type, the second type, and the third type may represent three different types. For example, the first time period corresponding to the first type of key, the second time period corresponding to the second type of key, and the third time period corresponding to the third type of key may be different. For another example, the first type of key, the second type of key, and the third type of key may be different.
[0081] The first time period, the second time period, and the third time period may be fixed time periods or time periods that change according to a preset strategy. For example, the first time period may be from 00:00:00 on September 1, 2024 to 23:59:59 on September 30, 2024. The second time period may be from 00:00:00 on October 1, 2024 to 23:59:59 on October 31, 2024. The third time period may be from 00:00:00 on November 1, 2024 to 23:59:59 on November 30, 2024. For another example, the second time period may be a time period that includes the current moment and has a preset duration (e.g., 7 days). In this example, the end time of the first time period is the start time of the second time period, the end time of the second time period is the start time of the third time period, and the first time period, the second time period, and the third time period may change with the change of the current moment. For example, when the current time changes, the first time period, the second time period, and the third time period may change accordingly; or, when the duration of the last change of the first time period (or the second time period or the third time period) is greater than or equal to the preset duration (for example, 7 days), the first time period (or the second time period or the third time period) may change again.
[0082] In addition, the durations of the first period, the second period, and the third period may be the same or different. The first period may be understood as the validity period of the first type of key, the second period may be understood as the validity period of the second type of key, and the third period may be understood as the validity period of the third type of key.
[0083] The target key may be a key used to perform encryption and decryption processing on the target data.
[0084] In practice, various methods may be used to determine whether a target key for encrypting and decrypting the target data is currently stored in the preset storage space.
[0085] As an example, the generation time of the target data can be determined first. After that, determine whether there is a time period containing the generation time of the above target data in the time period corresponding to the key currently stored in the preset storage space (for example, the first time period corresponding to the first type of key, the second time period corresponding to the second type of key). If so, it can be determined that the preset storage space currently stores a target key for encrypting and decrypting the target data. In this case, the key corresponding to the time period containing the generation time of the above target data can be used as the target key. If not, it can be determined that the preset storage space does not currently store the target key for encrypting and decrypting the target data.
[0086] As another example, it is also possible to determine whether a target key for encrypting and decrypting the target data is currently stored in the preset storage space by comparing whether the duration between the target data generation time and the current time is greater than or equal to a predetermined duration threshold. If the duration between the target data generation time and the current time is greater than or equal to a predetermined duration threshold, it can be determined that the target key for encrypting and decrypting the target data is not currently stored in the preset storage space. If the duration between the target data generation time and the current time is less than a predetermined duration threshold, it can be determined that a target key for encrypting and decrypting the target data is currently stored in the preset storage space. Further, the target key in the preset storage space can be determined based on the duration between the target data generation time and the current time, the duration of the first time period, the duration of the second time period, and the duration of the third time period.
[0087] In addition, the key in the preset storage space can be determined in a variety of ways.
[0088] As an example, when there are only Y (Y may be an integer greater than or equal to 2) types of keys in the preset storage space, the keys in the preset storage space may be determined by the following steps:
[0089] In the first step, a key is generated using the Nth preset key generation algorithm in the preset key generation algorithm sequence. The number of preset key generation algorithms included in the preset key generation algorithm sequence is M, and M is a positive integer greater than or equal to 2. For example, M may be greater than the number Y of key types in the preset storage space, and the value of N is [1, M], and the initial value of N is 1.
[0090] The preset key generation algorithms in the preset key generation algorithm sequence are different from each other. For example, the preset key generation algorithm sequence may include the following key generation algorithms: a symmetric key generation algorithm, an asymmetric key generation algorithm, a cryptographic algorithm parameter generation algorithm, and a cryptographic derivation algorithm. In addition, the preset key generation algorithms in the preset key generation algorithm sequence may generate keys based on timestamps to ensure that the keys generated each time are different.
[0091] In the second step, the key generated in the first step is used as a key of the Xth type, where X is the remainder when N is divided by Y. For example, if the remainder when N is divided by Y is 1, then the key generated in the first step can be used as a key of the first type; if the remainder when N is divided by Y is 2, then the key generated in the first step can be used as a key of the second type, and so on.
[0092] Third, if N is less than M, N is incremented by 1; if N is equal to M, N is updated to 1.
[0093] For each type of key, only the most recently generated key of that type is saved. For example, if a key of the first type (referred to as key A) has been generated, then when a key of the first type (referred to as key B) is generated again, key A needs to be deleted from the preset storage space and key B needs to be stored in the preset storage space.
[0094] Step 103: When the target key is currently stored in the preset storage space, the target data is encrypted and decrypted using the target key.
[0095] In this embodiment, after the target key is determined, the target key may be used to perform encryption or decryption processing on the target data.
[0096] In some optional implementations of this embodiment, when the target key is not currently stored in the preset storage space, the target data is in a state where it cannot be decrypted.
[0097] It can be understood that in the above-mentioned optional implementation method, when the target key is not currently stored in the preset storage space, since the key for decrypting the target data cannot be obtained, the target data is in an undecryptable state. In other words, the above-mentioned optional implementation method can achieve expiration processing of the target data by deleting or storing the key in the preset storage space, thereby further improving data security.
[0098] It should be noted that, in the absence of conflict, the technical features recorded in different optional implementations may be included in the same embodiment, and for the sake of brevity, they are not repeated here.
[0099] The data encryption and decryption method provided by the embodiment of the present application can obtain the target data to be processed, and then determine whether the target key for encrypting and decrypting the target data is currently stored in the preset storage space, wherein the preset storage space stores a first type of key and a second type of key, the first type of key corresponds to a first time period, the second type of key corresponds to a second time period, the end time of the first time period is the start time of the second time period, the first type of key is used to encrypt and decrypt data belonging to the first time period at the time of generation, and the second type of key is used to encrypt and decrypt data belonging to the second time period at the time of generation, and then, in the case where the target key is currently stored in the preset storage space, the target key is used to encrypt and decrypt the target data. Thus, data at different generation times can be encrypted and decrypted by using different types of keys stored in the preset storage space, so that the security of data encryption and decryption can be improved.
[0100] Figure 2 A schematic diagram of a processing flow of a key in a preset storage space involved in a data encryption and decryption method provided in an embodiment of the present application. Figure 2 As shown, the key in the preset storage space is processed in the following steps:
[0101] Step 201, determining whether the current moment belongs to the most recently determined target time period; wherein the most recently determined target time period is: the second time period corresponding to the most recently determined second type of key.
[0102] In this embodiment, the method for determining the second time period corresponding to the second type of key in the preset storage space can refer to the above description and will not be repeated here.
[0103] In this embodiment, a third type of key is also stored in the preset storage space.
[0104] Step 202, when the current moment does not belong to the most recently determined target time period, the first type of key stored in the preset storage space is updated to the second type of key in the preset storage space, and the second type of key stored in the preset storage space is updated to the third type of key in the preset storage space.
[0105] In this embodiment, the generation method of the second type of key and the third type of key in the preset storage space can refer to the above description and will not be repeated here.
[0106] In addition, the third type of key corresponds to a third time period, and the start time of the third time period is the end time of the second time period.
[0107] Step 203: Update the most recently determined target time period to the updated second time period corresponding to the second type of key.
[0108] In this embodiment, the method for determining the second time period corresponding to the updated second type of key can refer to the above description and will not be repeated here.
[0109] As an example, assume that before executing step 201, the preset storage space stores a first type of key 1, a second type of key 2, and a third type of key 3. The first time period corresponding to the first type of key 1 is time period 1, the second time period corresponding to the second type of key 2 is time period 2, and the third time period corresponding to the third type of key 3 is time period 3.
[0110] Then, when the current moment does not belong to the most recently determined target time period (i.e., time period 2), the first type of key stored in the preset storage space can be updated to the second type of key 2 in the preset storage space, and the second type of key stored in the preset storage space can be updated to the third type of key 3 in the preset storage space.
[0111] Thus, the preset storage space stores the first type of key 2 and the second type of key 3. The first time period corresponding to the first type of key 2 is time period 2, and the second time period corresponding to the second type of key 3 is time period 3.
[0112] Afterwards, the most recently determined target time period may be updated to the updated second time period corresponding to the second type of key 2 , that is, time period 3 .
[0113] Here, key 1 can be deleted or marked.
[0114] In some optional implementations of this embodiment, before the first type of key stored in the preset storage space is updated to the second type of key in the preset storage space, the key in the preset storage space may also be processed by the following steps:
[0115] The key of the first type currently stored in the preset storage space is deleted.
[0116] Here, the above-mentioned key 1 can be deleted.
[0117] It can be understood that in the above optional implementation method, after deleting the first type of key currently stored in the preset storage space, it can be ensured that the data generated in the time period corresponding to the first type of key cannot be decrypted, that is, the above data is in an undecryptable state, thereby further improving data security.
[0118] In some optional implementations of this embodiment, the first time period, the second time period, and the third time period are equal in length.
[0119] It can be understood that in the above optional implementation, since the duration of the first time period, the second time period and the third time period is equal, the first type of key, the second type of key and the third type of key can expire at the same time. In this way, the first type of key, the second type of key and the third type of key can be updated synchronously. Therefore, only three keys of three types can be stored, thereby reducing the occupancy of storage resources.
[0120] In some optional implementations of this embodiment, after the second type of key stored in the preset storage space is updated to the third type of key in the preset storage space, the key in the preset storage space is further processed by the following steps:
[0121] The third type of key is updated to a newly generated key.
[0122] Here, key 4 may be generated first, so that key 4 is used as the third type of key. Key 4 may correspond to time period 4.
[0123] That is, the preset storage space stores a first type of key 2, a second type of key 3, and a third type of key 4. The first time period corresponding to the first type of key 2 is time period 2, the second time period corresponding to the second type of key 3 is time period 3, and the third time period corresponding to the third type of key 4 is time period 4.
[0124] It can be understood that in the above optional implementation, by updating the third type of key, when it is determined next time that the current moment does not belong to the most recently determined target time period, key update and data encryption and decryption processing can be implemented more timely.
[0125] In some optional implementations of this embodiment, after the target data is encrypted and decrypted using the target key, the following steps may also be performed:
[0126] The first step is to determine the decryption result of decrypting the target data using the target key.
[0127] The second step is to determine whether the decryption result indicates a decryption failure.
[0128] On this basis, the steps are performed when the decryption result indicates that the decryption fails. In other words, the following steps can be performed when the decryption result indicates that the decryption fails:
[0129] Step 1: determine whether the current moment belongs to the most recently determined target time period; wherein the most recently determined target time period is: the second time period corresponding to the most recently determined second type of key.
[0130] Step 2: When the current moment does not belong to the most recently determined target time period, the first type of key stored in the preset storage space is updated to the second type of key in the preset storage space, and the second type of key stored in the preset storage space is updated to the third type of key in the preset storage space, wherein the third type of key corresponds to a third time period, and the start time of the third time period is the end time of the second time period.
[0131] Step three: updating the most recently determined target time period to the updated second time period corresponding to the second type of key.
[0132] Here, the specific implementation methods of the above steps 1 to 3 can refer to the above description and will not be repeated here.
[0133] It can be understood that in the above optional implementation method, the key can be updated when the target key cannot decrypt the target data. Thus, the key can be replaced in time when the characters in the target key are disordered or lost, so as to reduce the probability of abnormalities in data encryption and decryption processing.
[0134] In some optional implementations of this embodiment, the step is performed when the current moment does not belong to the most recently determined target time period.
[0135] In other words, when the current time does not belong to the most recently determined target time period, the following steps may be performed:
[0136] Step 1: determine whether the current moment belongs to the most recently determined target time period; wherein the most recently determined target time period is: the second time period corresponding to the most recently determined second type of key.
[0137] Step 2: When the current moment does not belong to the most recently determined target time period, the first type of key stored in the preset storage space is updated to the second type of key in the preset storage space, and the second type of key stored in the preset storage space is updated to the third type of key in the preset storage space, wherein the third type of key corresponds to a third time period, and the start time of the third time period is the end time of the second time period.
[0138] Step three: updating the most recently determined target time period to the updated second time period corresponding to the second type of key.
[0139] Here, the specific implementation methods of the above steps 1 to 3 can refer to the above description and will not be repeated here.
[0140] It can be understood that in the above optional implementation, the key can be updated as the current time changes, thereby further improving data security by regularly and timely updating the key.
[0141] It should be noted that, in addition to the above contents, this embodiment may also include Figure 1 The corresponding technical features described in the corresponding embodiments are realized Figure 1 For details, please refer to the technical effect of the data encryption and decryption method shown. Figure 1For the sake of brevity, the relevant description is not repeated here.
[0142] The embodiment of the present application can update the key in a timely manner when the current time does not belong to the most recently determined target time period, thereby further improving data security.
[0143] The following is an illustrative description of the embodiments of the present application, but it should be noted that the embodiments of the present application may have the features described below, but the following description does not constitute a limitation on the scope of protection of the embodiments of the present application.
[0145] See also Figure 3 , Figure 3 A flowchart of another data encryption and decryption method provided in an embodiment of the present application.
[0146] This solution requires the use of three keys to process data in three different time periods: "past", "present", and "future" (i.e., the target data mentioned above). According to actual needs, the validity period of the three keys (i.e., the first period, the second period, and the third period mentioned above) can be 30 days per month, 7 days per week, 1 day per day, or even hours, minutes, and seconds in extreme cases.
[0147] Regardless of the validity period, the validity periods of the three are consistent, that is, the first period, the second period, and the third period are equal in length. If it is 1 day, then when one of them expires, the validity periods of the other two expire in sequence, and when the "current KEY" (that is, the second type of key mentioned above) expires, the "past KEY" (that is, the first type of key mentioned above) is directly deleted. The "current KEY" becomes the "past KEY", and so on.
[0148] The trigger condition for deleting the past KEY is: when the past KEY is used for decryption, the data cannot be decrypted normally, indicating that the KEY (that is, the first type of key, the second type of key, and the third type of key mentioned above) has expired, and it should be switched to the current KEY immediately to ensure normal operation.
[0149] Among the three keys (KEY) mentioned above, the current key KEY can only encrypt and decrypt data in the current period (that is, the second period mentioned above). Suppose: the validity period of the current KEY is from 2024-09-01 00:00:00 to 2024-09-30 23:59:59, then this KEY can only process data generated during this period, and cannot process data generated earlier or later.
[0150] In addition, the KEY can be generated based on the timestamp. As the current time changes, the generated KEY will also change to ensure that the key will not be repeated.
[0151] The above-mentioned end data can be data generated during the validity period that needs to be encrypted, for example: data generated from 2024-09-01 00:00:00 to 2024-09-30 23:59:59
[0152] Although there are three keys, only two ("past" and "present") are in working state. "Future KEY" (that is, the third type of key mentioned above) is for reserve use. Once the "past KEY" becomes invalid, the "present KEY" becomes the "past KEY", and the "future KEY" becomes the "present" KEY, and a reserve "future KEY" is generated at the same time.
[0153] KEY is a set of two keys, for example, it can be based on asymmetric encryption, that is, a public key KEY used for encryption and a private key KEY used for decryption. For example, "in the past" KEY is a set of public key and private key, and the same is true for the other two.
[0154] During the validity period, the "present" public key KEY is responsible for encrypting data, and the data that needs to be decrypted uses the private key KEY. When the validity period expires, the "present" KEY no longer participates in data encryption and becomes the "past KEY". The "future KEY" is officially used to encrypt and decrypt data.
[0155] During the validity period, the "past KEY" mainly decrypts past data, making it convenient for users to view the data encrypted by the KEY. Older data cannot be viewed because it is encrypted by other deleted "past KEYs", achieving the effect of expiration. Although the data is still there, it can no longer be decrypted.
[0156] After the validity period expires, the "past KEY" is directly deleted and no longer retained.
[0157] Since the KEY also had an expiration date in the past, if it was 30 days, then the data before that (60 days) was encrypted by another KEY and it cannot be decrypted.
[0158] During the validity period, wait for one of the "present KEY" and "past KEY" to expire, automatically become the "present KEY", and generate a new "future KEY" at the same time.
[0159] At this point, since the past "past KEY" has been deleted, although the data is still there, there is no decryption key, and the data expiration processing is implemented.
[0160] It should be noted that, in addition to the contents recorded above, this embodiment may also include the technical features described in the above embodiments, so as to achieve the technical effects of the data encryption and decryption method shown above. Please refer to the above description for details. For the sake of brevity, it will not be repeated here.
[0161] The data encryption and decryption method provided in the embodiment of the present application can solve the problem of long-term existence of leaked personal information. It solves the possibility of long-term data personal information being used here. It can strengthen the protection of personal information security. It can also effectively reduce the possibility of these leaked personal information being used, and prevent them from being used again by criminals to carry out various fraudulent activities. Data encryption processing is implemented based on the time encryption key, which has achieved the effect of data expiration, effectively reducing the possibility of these leaked personal information being used.
[0162] Figure 4 A schematic diagram of the structure of a data encryption and decryption device provided in an embodiment of the present application.
[0163] Specifically include:
[0164] An acquisition unit 401 is used to acquire target data to be processed;
[0165] A first determining unit 402 is used to determine whether a target key for encrypting and decrypting the target data is currently stored in a preset storage space, wherein a first type of key and a second type of key are stored in the preset storage space, the first type of key corresponds to a first time period, the second type of key corresponds to a second time period, the end time of the first time period is the start time of the second time period, the first type of key is used to encrypt and decrypt data whose generation time belongs to the first time period, and the second type of key is used to encrypt and decrypt data whose generation time belongs to the second time period;
[0166] The encryption and decryption unit 403 is configured to, when the target key is currently stored in the preset storage space, perform encryption and decryption processing on the target data using the target key.
[0167] In a possible implementation manner, a third type of key is further stored in the preset storage space; and
[0168] The keys in the preset storage space are processed using the following steps:
[0169] Determine whether the current moment belongs to the most recently determined target time period; wherein the most recently determined target time period is: the second time period corresponding to the most recently determined second type of key;
[0170] In the case that the current moment does not belong to the most recently determined target time period, the first type of key stored in the preset storage space is updated to the second type of key in the preset storage space, and the second type of key stored in the preset storage space is updated to the third type of key in the preset storage space, wherein the third type of key corresponds to a third time period, and the start time of the third time period is the end time of the second time period;
[0171] The most recently determined target time period is updated to the updated second time period corresponding to the second type of key.
[0172] In a possible implementation manner, before the first type of key stored in the preset storage space is updated to the second type of key in the preset storage space, the key in the preset storage space is further processed by the following steps:
[0173] The key of the first type currently stored in the preset storage space is deleted.
[0174] In a possible implementation manner, the first time period, the second time period, and the third time period are equal in length.
[0175] In a possible implementation manner, after the second type of key stored in the preset storage space is updated to the third type of key in the preset storage space, the key in the preset storage space is further processed by the following steps:
[0176] The third type of key is updated to a newly generated key.
[0177] In a possible implementation manner, after the target data is encrypted and decrypted using the target key, the device further includes:
[0178] A second determining unit (not shown in the figure) is used to determine a decryption result of decrypting the target data using the target key;
[0179] A third determining unit (not shown in the figure) is used to determine whether the decryption result indicates a decryption failure; and
[0180] The step is performed when the decryption result indicates that the decryption fails.
[0181] In a possible implementation manner, the step is performed when the current moment does not belong to the most recently determined target time period.
[0182] In a possible implementation manner, when the target key is not currently stored in the preset storage space, the target data is in a state where it cannot be decrypted.
[0183] The data encryption and decryption device provided in this embodiment can be as follows Figure 4 The data encryption and decryption device shown in can execute all the steps of the data encryption and decryption methods described above, thereby achieving the technical effects of the data encryption and decryption methods described above. Please refer to the above related description for details. For the sake of brevity, it will not be repeated here.
[0184] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application, Figure 5 The electronic device 500 shown includes: at least one processor 501, a memory 502, at least one network interface 504 and other user interfaces 503. The various components in the electronic device 500 are coupled together via a bus system 505. It is understood that the bus system 505 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 505 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, the bus system 505 is not shown in FIG. Figure 5 Various buses are labeled as bus system 505 .
[0185] The user interface 503 may include a display, a keyboard, or a pointing device (eg, a mouse, a trackball, a touch pad, or a touch screen).
[0186] It can be understood that the memory 502 in the embodiment of the present application can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM) and direct RAM bus random access memory (DRRAM). The memory 502 described herein is intended to include, but is not limited to, these and any other suitable types of memory.
[0187] In some implementations, the memory 502 stores the following elements, executable units or data structures, or a subset thereof, or an extended set thereof: an operating system 5021 and an application program 5022 .
[0188] Among them, the operating system 5021 includes various system programs, such as a framework layer, a core library layer, a driver layer, etc., which are used to implement various basic services and process hardware-based tasks. The application 5022 includes various application programs, such as a media player (Media Player), a browser (Browser), etc., which are used to implement various application services. The program for implementing the method of the embodiment of the present application can be included in the application 5022.
[0189] In this embodiment, by calling the program or instruction stored in the memory 502, specifically, the program or instruction stored in the application 5022, the processor 501 is used to execute the method steps provided by each method embodiment, for example, including:
[0190] Obtain target data to be processed;
[0191] Determine whether a target key for encrypting and decrypting the target data is currently stored in a preset storage space, wherein a first type of key and a second type of key are stored in the preset storage space, the first type of key corresponds to a first time period, the second type of key corresponds to a second time period, the end time of the first time period is the start time of the second time period, the first type of key is used to encrypt and decrypt data whose generation time belongs to the first time period, and the second type of key is used to encrypt and decrypt data whose generation time belongs to the second time period;
[0192] In the case where the target key is currently stored in the preset storage space, the target data is encrypted and decrypted using the target key.
[0193] The method disclosed in the above embodiment of the present application can be applied to the processor 501, or implemented by the processor 501. The processor 501 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 501. The above processor 501 can be a general processor, a digital signal processor (Digital Signal Processor, DSP), an application specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field programmable gate array (Field Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiment of the present application can be directly embodied as a hardware decoding processor to execute, or the hardware and software units in the decoding processor can be executed. The software unit can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 502, and the processor 501 reads the information in the memory 502 and completes the steps of the above method in combination with its hardware.
[0194] It is understood that the embodiments described herein may be implemented in hardware, software, firmware, middleware, microcode, or a combination thereof. For hardware implementation, the processing unit may be implemented in one or more application specific integrated circuits (ASIC), digital signal processors (DSP), digital signal processing devices (DSPDevice, DSPD), programmable logic devices (PLD), field programmable gate arrays (FPGA), general purpose processors, controllers, microcontrollers, microprocessors, other electronic units for performing the above functions of the present application, or a combination thereof.
[0195] For software implementation, the technology described above in this article can be implemented by a unit that performs the functions described above in this article. The software code can be stored in a memory and executed by a processor. The memory can be implemented in the processor or outside the processor.
[0196] The electronic device provided in this embodiment may be Figure 5 The electronic device shown in can execute all the steps of the above-mentioned data encryption and decryption methods, thereby achieving the technical effects of the above-mentioned data encryption and decryption methods. Please refer to the above related description for details. For the sake of brevity, it will not be repeated here.
[0197] The embodiment of the present application also provides a storage medium (computer-readable storage medium). The storage medium here stores one or more programs. The storage medium may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a read-only memory, a flash memory, a hard disk or a solid-state drive; the memory may also include a combination of the above-mentioned types of memory.
[0198] When one or more programs in the storage medium can be executed by one or more processors, the data encryption and decryption method executed on the electronic device side can be implemented.
[0199] The processor is used to execute the data encryption and decryption program stored in the memory to implement the following steps of the data encryption and decryption method performed on the electronic device side:
[0200] Obtain target data to be processed;
[0201] Determine whether a target key for encrypting and decrypting the target data is currently stored in a preset storage space, wherein a first type of key and a second type of key are stored in the preset storage space, the first type of key corresponds to a first time period, the second type of key corresponds to a second time period, the end time of the first time period is the start time of the second time period, the first type of key is used to encrypt and decrypt data whose generation time belongs to the first time period, and the second type of key is used to encrypt and decrypt data whose generation time belongs to the second time period;
[0202] In the case where the target key is currently stored in the preset storage space, the target data is encrypted and decrypted using the target key.
[0203] The professionals should also be further aware that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented with electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0204] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0205] It should be understood that the terms used herein are only for the purpose of describing specific example embodiments and are not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms "one", "an" and "said" as used herein may also be meant to include plural forms. The terms "include", "comprise", "contain", and "have" are inclusive, and therefore specify the existence of stated features, steps, operations, elements and / or parts, but do not exclude the existence or addition of one or more other features, steps, operations, elements, parts, and / or combinations thereof. The method steps, processes, and operations described herein are not interpreted as necessarily requiring them to be performed in the specific order described or illustrated, unless the execution order is clearly indicated. It should also be understood that additional or alternative steps may be used.
[0206] The above description is only a specific implementation of the present application, so that those skilled in the art can understand or implement the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest range consistent with the principles and novel features applied for herein.
Claims
1. An encryption and decryption method, characterized in that: The method comprises: Obtain target data to be processed; Determine whether a target key for encrypting and decrypting the target data is currently stored in a preset storage space, wherein a first type of key and a second type of key are stored in the preset storage space, the first type of key corresponds to a first time period, the second type of key corresponds to a second time period, the end time of the first time period is the start time of the second time period, the first type of key is used to encrypt and decrypt data whose generation time belongs to the first time period, and the second type of key is used to encrypt and decrypt data whose generation time belongs to the second time period; In the case where the target key is currently stored in the preset storage space, the target data is encrypted and decrypted using the target key.
2. The method according to claim 1, characterized in that The preset storage space also stores a third type of key; and The keys in the preset storage space are processed using the following steps: Determine whether the current moment belongs to the most recently determined target time period; wherein the most recently determined target time period is: the second time period corresponding to the most recently determined second type of key; In the case that the current moment does not belong to the most recently determined target time period, the first type of key stored in the preset storage space is updated to the second type of key in the preset storage space, and the second type of key stored in the preset storage space is updated to the third type of key in the preset storage space, wherein the third type of key corresponds to a third time period, and the start time of the third time period is the end time of the second time period; The most recently determined target time period is updated to the updated second time period corresponding to the second type of key.
3. The method according to claim 2, characterized in that Before the first type of key stored in the preset storage space is updated to the second type of key in the preset storage space, the key in the preset storage space is further processed by the following steps: The key of the first type currently stored in the preset storage space is deleted.
4. The method according to claim 2, characterized in that: The first time period, the second time period and the third time period are equal in length.
5. The method according to claim 2, characterized in that: After the second type of key stored in the preset storage space is updated to the third type of key in the preset storage space, the key in the preset storage space is further processed by the following steps: The third type of key is updated to a newly generated key.
6. The method according to any one of claims 2 to 5, characterized in that: After the target data is encrypted and decrypted using the target key, the method further includes: Determine a decryption result of decrypting the target data using the target key; determining whether the decryption result indicates a decryption failure; and The step is performed when the decryption result indicates that the decryption fails.
7. The method according to any one of claims 2 to 5, characterized in that: The step is performed when the current time does not belong to the most recently determined target time period.
8. The method according to any one of claims 1 to 5, characterized in that: In the case that the target key is not currently stored in the preset storage space, the target data is in a state where it cannot be decrypted.
9. An encryption and decryption device, characterized in that: The device comprises: An acquisition unit, used for acquiring target data to be processed; A first determining unit, configured to determine whether a target key for encrypting and decrypting the target data is currently stored in a preset storage space, wherein a first type of key and a second type of key are stored in the preset storage space, the first type of key corresponds to a first time period, the second type of key corresponds to a second time period, the end time of the first time period is the start time of the second time period, the first type of key is used to encrypt and decrypt data whose generation time belongs to the first time period, and the second type of key is used to encrypt and decrypt data whose generation time belongs to the second time period; The encryption and decryption unit is used to use the target key to encrypt and decrypt the target data when the target key is currently stored in the preset storage space.
10. An electronic device, characterized in that: include: Memory for storing computer programs; A processor is used to execute the computer program stored in the memory, and when the computer program is executed, the data encryption and decryption method of any one of claims 1 to 8 is implemented.
11. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the data encryption and decryption method of any one of claims 1 to 8 is implemented.
Citation Information
Patent Citations
Communication encryption method, electronic equipment and readable storage medium
CN111355575A
Communication key processing method and device, nonvolatile storage medium and processor
CN114338141A
Encrypted data communication method and device, equipment and storage medium
CN118611961A