File encryption method and device, storage medium, and electronic device

Through key mapping files and segmented encryption technology, the problem of long time-consuming key updates is solved, rapid key updates and encryption key leakage control are achieved, ensuring the security and efficiency of data storage.

CN112883388BActive Publication Date: 2024-09-06ZHEJIANG DAHUA TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110170182.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-02-05
Publication Date
2024-09-06
Estimated Expiration
2041-02-05

AI Technical Summary

Technical Problem

In the existing technology, it takes a long time to update the key for encrypted data, and the problem of low key update efficiency cannot be effectively solved.

Method used

Use a key mapping file, which contains the encryption key and its unique identifier, encrypt the key mapping file with a preset user key, use the new key to encrypt the mapping file when the key is updated, encrypt the data in segments, and encrypt the data in different sections. Location stores key mapping files and encrypted data to enable fast key updates and leak detection.

Benefits of technology

Quickly complete the key update when the old key is not leaked, prevent the leakage and spread of encryption keys in a timely manner, and ensure the orderliness and security of data re-encryption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112883388B
    Figure CN112883388B
Patent Text Reader

Abstract

The present invention discloses a file encryption method and device, a storage medium, and an electronic device, wherein the method comprises: creating a key mapping file, wherein the key mapping file comprises: an encryption key and a unique identifier corresponding to the encryption key, and the first encryption key in the key mapping file is used to encrypt the data to be encrypted; encrypting the key mapping file according to a preset first user key; encrypting the key mapping file according to the second user key when it is detected that the first user key needs to be updated to a second user key, that is, encrypting the key mapping file storing the encryption key and the unique identifier corresponding to the encryption key by the first user key, and encrypting the key mapping file according to the second user key when the first user key needs to be updated. The above technical solution solves the problem that the key update takes a long time when the key of the encrypted data needs to be updated in the related technology.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communications, and in particular to a file encryption method and device, a storage medium, and an electronic device. Background Art

[0002] With the rise of the Internet and smart phones, video collection has become more and more convenient, and the amount of data in various information systems is increasing, such as various selfie videos, various real-time chat videos, surveillance videos collected by network cameras, etc. In order to ensure the security of the data, it is usually chosen to encrypt the data before storing it in a storage device (such as a hard disk, USB flash drive). The encrypted and stored data requires the correct key to be entered before it can be reopened. When the amount of encrypted historical data is large, when the key is updated, the old key needs to be used to decrypt the historical encrypted data and then re-encrypt it with the new key. This technical solution consumes a lot of equipment performance and is time-consuming, and it is also necessary to do a good job of protecting the intermediate process.

[0003] In the related art, when the key for encrypting data needs to be updated, the key update takes a long time, and no effective solution has been proposed yet. Summary of the invention

[0004] The embodiments of the present invention provide a file encryption method and device, a storage medium, and an electronic device to at least solve the problem in the related art that when the key for encrypting data needs to be updated, the key update takes a long time.

[0005] According to one embodiment of the present invention, a file encryption method is provided, comprising: creating a key mapping file, wherein the key mapping file comprises: an encryption key and a unique identifier corresponding to the encryption key, a first encryption key in the key mapping file is used to encrypt data to be encrypted; encrypting the key mapping file according to a preset first user key; and encrypting the key mapping file according to the second user key when it is detected that the first user key needs to be updated to a second user key.

[0006] In an exemplary embodiment, after encrypting the key mapping file according to a preset first user key, the method further includes: determining a second encryption key from the key mapping file when it is detected that the first user key needs to be updated to a second user key and the first user key is leaked; and re-encrypting the data to be encrypted according to the second encryption key.

[0007] In an exemplary embodiment, after encrypting the key mapping file according to a preset first user key, the method further includes: encrypting the data to be encrypted according to the first encryption key to obtain encrypted data; obtaining a unique identifier corresponding to the first encryption key, and combining the unique identifier corresponding to the first encryption key and the encrypted data into encrypted data.

[0008] In an exemplary embodiment, after encrypting the key mapping file according to a preset first user key, the method further includes: segmenting the data to be encrypted according to a segmentation rule to obtain multiple segmented data; the segmentation rule includes at least one of the following: target duration, target data length; determining multiple encryption keys from the key mapping file, and encrypting the multiple data respectively by multiple encryption keys.

[0009] In an exemplary embodiment, after encrypting the multiple data respectively using multiple encryption keys, the method further includes: obtaining multiple unique identifiers corresponding to the multiple encryption keys respectively, and multiple target data obtained by encrypting the multiple data respectively using the multiple encryption keys; and combining the multiple unique identifiers with the multiple target data corresponding to the multiple unique identifiers respectively.

[0010] In an exemplary embodiment, after combining the unique identifier corresponding to the first encryption key and the encrypted data into encrypted data, the method further includes: sending the encrypted data to a data recipient to instruct the data recipient to determine the first encryption key based on the unique identifier corresponding to the first encryption key carried in the encrypted data, and decrypt the encrypted data based on the first encryption key.

[0011] In an exemplary embodiment, the key mapping file is stored in a first preset location, and the encrypted data is stored in a second preset location.

[0012] According to another embodiment of the present invention, a file encryption device is also provided, including a creation module for creating a key mapping file, wherein the key mapping file includes: an encryption key and a unique identifier corresponding to the encryption key, and the first encryption key in the key mapping file is used to encrypt the data to be encrypted; an encryption module for encrypting the key mapping file according to a preset first user key; and a detection module for encrypting the key mapping file according to the second user key when it is detected that the first user key needs to be updated to a second user key.

[0013] According to yet another embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the steps of any one of the above method embodiments when run.

[0014] According to yet another embodiment of the present invention, there is provided an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.

[0015] Through the present invention, a key mapping file is created, wherein the key mapping file includes: an encryption key and a unique identifier corresponding to the encryption key, the first encryption key in the key mapping file is used to encrypt the data to be encrypted; the key mapping file is encrypted according to the preset first user key; when it is detected that the first user key needs to be updated to the second user key, the key mapping file is encrypted according to the second user key, that is, the key mapping file storing the encryption key and the unique identifier corresponding to the encryption key is encrypted by the first user key, and when the first user key needs to be updated, the key mapping file is encrypted according to the second user key. The above technical solution solves the problem that the key update takes a long time when the key of the encrypted data needs to be updated in the related technology, thereby ensuring that the user key can be updated quickly when the old user key is not leaked; even if the old user key has been leaked, the spread of the encryption key leakage problem can be prevented in time, and the data re-encryption can be completed in an orderly manner. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:

[0017] Figure 1 It is a hardware structure block diagram of a computer terminal of a file encryption method according to an embodiment of the present invention;

[0018] Figure 2 is a flow chart of a file encryption method according to an embodiment of the present invention;

[0019] Figure 3 A data encryption flow chart of a file encryption method according to an optional embodiment of the present invention;

[0020] Figure 4 A data decryption flow chart of a file encryption method according to an optional embodiment of the present invention;

[0021] Figure 5A flowchart of updating a user key in a file encryption method according to an optional embodiment of the present invention;

[0022] Figure 6 It is a structural block diagram of a file encryption device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0023] The present invention will be described in detail below with reference to the accompanying drawings and in combination with embodiments. It should be noted that the embodiments and features in the embodiments of the present application can be combined with each other without conflict.

[0024] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.

[0025] The method embodiments provided in the embodiments of the present application can be executed in a computer terminal or a similar computing device. Taking running on a computer terminal as an example, Figure 1 FIG. 1 is a hardware structure block diagram of a computer terminal of a file encryption method according to an embodiment of the present invention. Figure 1 As shown, the computer terminal may include one or more ( Figure 1 Only one is shown in the figure) processor 102 (processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data. In an exemplary embodiment, the computer terminal may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above-mentioned computer terminal. Figure 1 More or fewer components as shown, or with Figure 1 Equivalent functions or comparisons shown Figure 1 A different configuration with more features is shown.

[0026] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the file encryption method of the computer terminal in the embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the computer terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0027] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of a computer terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0028] In this embodiment, a file encryption method is provided, which is applied to the above-mentioned computer terminal. Figure 2 is a flowchart of a file encryption method according to an embodiment of the present invention, the process comprising the following steps:

[0029] Step S202, creating a key mapping file, wherein the key mapping file includes: an encryption key and a unique identifier corresponding to the encryption key, and the first encryption key in the key mapping file is used to encrypt the data to be encrypted;

[0030] Step S204, encrypting the key mapping file according to a preset first user key;

[0031] Step S206: When it is detected that the first user key needs to be updated to a second user key, the key mapping file is encrypted according to the second user key.

[0032] Through the present invention, a key mapping file is created, wherein the key mapping file includes: an encryption key and a unique identifier corresponding to the encryption key, the first encryption key in the key mapping file is used to encrypt the data to be encrypted; the key mapping file is encrypted according to the preset first user key; when it is detected that the first user key needs to be updated to the second user key, the key mapping file is encrypted according to the second user key, that is, the key mapping file storing the encryption key and the unique identifier corresponding to the encryption key is encrypted by the first user key, and when the first user key needs to be updated, the key mapping file is encrypted according to the second user key. The above technical solution solves the problem that the key update takes a long time when the key of the encrypted data needs to be updated in the related technology, thereby ensuring that the user key can be updated quickly when the old user key is not leaked; even if the old user key has been leaked, the spread of the encryption key leakage problem can be prevented in time, and the data re-encryption can be completed in an orderly manner.

[0033] It should be noted that in the above step S202, the encryption key is generated by using a random number generation algorithm, and a unique identifier is assigned to it, and the encryption key and the unique identifier corresponding to the encryption key are stored in a key mapping file.

[0034] In an optional embodiment, after the key mapping file is encrypted according to a preset first user key, when it is detected that the first user key needs to be updated to a second user key and the first user key is leaked, a second encryption key is determined from the key mapping file; and the data to be encrypted is re-encrypted according to the second encryption key.

[0035] Specifically, when it is detected that the first user key needs to be updated to the second user key, the key mapping file is obtained, and the key mapping file is decrypted with the first user key, and the key mapping file is re-encrypted with the second user key. If it is determined that the first user key is leaked, the data to be encrypted that was encrypted with the first encryption key is re-encrypted according to the second encryption key, wherein the second encryption key is also saved in the key mapping file, and the key mapping file re-encrypted with the second user key and the re-encrypted data to be encrypted are saved.

[0036] In an exemplary embodiment, after the key mapping file is encrypted according to a preset first user key, the data to be encrypted is encrypted according to the first encryption key to obtain encrypted data; the unique identifier corresponding to the first encryption key is obtained, and the unique identifier corresponding to the first encryption key and the encrypted data are combined into encrypted data.

[0037] That is to say, the data to be encrypted is encrypted according to the first encryption key to obtain the encrypted data, the unique identifier corresponding to the first encryption key is determined in the key mapping file, and the unique identifier corresponding to the first encryption key is placed at the very front of the encrypted data to form the encrypted data. The embodiment of the present invention does not limit the placement position of the unique identifier corresponding to the encryption key. The unique identifier corresponding to the encryption key is only for obtaining the encryption key in the key mapping file through the unique identifier.

[0038] In an optional embodiment, after the key mapping file is encrypted according to a preset first user key, the data to be encrypted is segmented according to a segmentation rule to obtain multiple segmented data; the segmentation rule includes at least one of the following: target duration, target data length; multiple encryption keys are determined from the key mapping file, and the multiple data are encrypted respectively by multiple encryption keys.

[0039] That is to say, if the data to be encrypted needs to be segmented, the data to be encrypted can be segmented, for example, the data to be encrypted can be segmented according to the target duration, or the data to be encrypted can be segmented according to the target data length. According to the type of data to be encrypted, segmentation according to the target duration or segmentation according to the target data length is selected. After the data to be encrypted is segmented, multiple data are obtained, and then multiple encryption keys are determined from the key mapping file. First, one of the data to be encrypted is encrypted using an encryption key. After one data is completed, the next data is re-encrypted until the encryption of multiple data is completed, thereby completing the encryption of all the data to be encrypted. After the encryption of all the data to be encrypted is completed, the next data to be encrypted is re-encrypted until the encryption of all the data to be encrypted is completed, thereby completing the encryption of multiple data.

[0040] For example, determine the segmentation rules of the data to be encrypted, and choose to segment according to the target duration or according to the target data length according to the type of data to be encrypted. If the data to be encrypted is audio and video data, you can choose to segment according to the audio and video duration, or you can choose to segment according to the data length (such as one segment every 30 minutes, or one segment every 100MB); if the data to be encrypted is other types of data (such as pure binary data), you can choose to segment according to the data length (such as one segment every 50MB). It should be noted that the above numbers are only for understanding the numerical values ​​selected by the technical solution of the embodiment of the present invention, and can be any possible numerical values ​​during actual operation.

[0041] In an exemplary embodiment, after encrypting the multiple data respectively by using multiple encryption keys, multiple unique identifiers corresponding to the multiple encryption keys and multiple target data obtained by encrypting the multiple data respectively by using the multiple encryption keys are obtained; the multiple unique identifiers are respectively combined with the multiple target data corresponding to the multiple unique identifiers.

[0042] In other words, after encrypting multiple data, multiple unique identifiers corresponding to the multiple encryption keys are determined in the key mapping file, and the multiple unique identifiers are combined with multiple target data obtained by encrypting the multiple data using the multiple encryption keys to obtain multiple encrypted data.

[0043] In an exemplary embodiment, after the unique identifier corresponding to the first encryption key and the encrypted data are combined into encrypted data, the encrypted data is sent to a data recipient to instruct the data recipient to determine the first encryption key based on the unique identifier corresponding to the first encryption key carried in the encrypted data, and decrypt the encrypted data based on the first encryption key.

[0044] Specifically, after the data to be encrypted are combined into encrypted data through the first encryption key and the unique identifier corresponding to the first encryption key, the data recipient obtains the key mapping file and the encrypted data, the data recipient decrypts the key mapping file according to the user key, reads the encrypted data, and obtains the unique identifier corresponding to the first encryption key from the encrypted data, obtains the corresponding first encryption key from the decrypted key mapping file according to the unique identifier, and decrypts the encrypted data according to the first encryption key.

[0045] Furthermore, the data to be encrypted is segmented according to the segmentation rule, and after the multiple data are encrypted respectively by multiple encryption keys, the data receiver obtains the key mapping file and multiple encrypted data, and the data receiver decrypts the key mapping file according to the user key, reads one of the multiple encrypted data, and obtains the unique identifier from the encrypted data, obtains the corresponding encryption key from the decrypted key mapping file according to the unique identifier, and decrypts the encrypted data according to the encryption key. Whether the multiple encrypted data have been decrypted, if the decryption is not completed, continue and obtain the unique identifier from the next encrypted data, obtain the corresponding encryption key from the decrypted key mapping file according to the unique identifier, and decrypt the next encrypted data according to the encryption key, until all encrypted data are decrypted.

[0046] In an exemplary embodiment, the key mapping file is stored in a first preset location, and the encrypted data is stored in a second preset location.

[0047] In order to further improve the security of file storage, the key mapping file and the encrypted data are stored in different locations. For example, the encrypted storage of video files is implemented on a network camera. The key mapping file is encrypted by the user key and stored in the flash memory of the network camera, and the encrypted data is stored in the memory card (SD card) of the network camera.

[0048] In order to better understand the process of the above-mentioned file encryption method, the above-mentioned file encryption method process is described below in combination with an optional embodiment, but it is not used to limit the technical solution of the embodiment of the present invention.

[0049] Figure 3 is a data encryption flow chart of a file encryption method according to an optional embodiment of the present invention, such as Figure 3 As shown, the data encryption process of the file encryption method can be implemented by the following steps:

[0050] Step S301: Enable encryption;

[0051] Step S302: selecting encrypted data segmentation rules;

[0052] For example, according to the type of data to be encrypted, you can choose to segment by duration or by data length. If the data to be encrypted is audio or video data, you can choose to segment by duration, or by data length (such as one segment every 30 minutes, or one segment every 100MB); if the data to be encrypted is other types of data (such as pure binary data), you can choose to segment by data length.

[0053] Step S303: Setting a user key (UK) (equivalent to the user key in the above embodiment);

[0054] Step S304: Create a data encryption key mapping (KeyMap) file (equivalent to the key mapping file in the above embodiment). The KeyMap file is encrypted by UK and stored. The KeyMap file stores the key (DEK) used to encrypt data (equivalent to the encryption key in the above embodiment) and the number (KID) of the DEK (equivalent to the unique identifier corresponding to the encryption key in the above embodiment);

[0055] Step S305: A random number generation algorithm is used to randomly generate a DEK, and a unique KID is assigned to it, and inserted into the KeyMap file in pairs;

[0056] Step S306: Start encrypting data using the DEK generated in step S304, and put the corresponding KID into the header of the file;

[0057] Step S307: read the data, encrypt it with DEK, and write the encrypted data to the memory;

[0058] Step S308: Determine whether the data to be encrypted meets the selected segmentation rule. If so, execute step S309. If not, continue to execute step S307.

[0059] Step S309: close the file of the data to be encrypted;

[0060] Step S310: Determine whether there is still data to be encrypted; if there is still data to be encrypted, execute steps S305-S306; if there is no data to be encrypted, execute step S311;

[0061] Step S311: End.

[0062] Figure 4 FIG. 1 is a flow chart of data decryption in a file encryption method according to an optional embodiment of the present invention. Figure 4 As shown, the data decryption process of the file encryption method can be achieved by the following steps:

[0063] Step S401: Load the KeyMap file and decrypt it with UK;

[0064] Step S402: Read the data encryption file and extract the KID from the header;

[0065] Step S403: Get the DEK from the decrypted KeyMap according to the KID;

[0066] Step S404: decrypt the remaining data in step S402 using the DEK;

[0067] Step S405: Determine whether the data in the file has been decrypted. If the decryption is completed, execute step S406. If the decryption is not completed, continue to execute step S404.

[0068] Step S406: End.

[0069] Figure 5 FIG. 1 is a flowchart of updating a user key in a file encryption method according to an optional embodiment of the present invention. Figure 5 As shown, the process of updating the user key of the file encryption method can be implemented by the following steps:

[0070] Step S501: Load the KeyMap file and decrypt it with the old UK;

[0071] Step S502: re-encrypt the KeyMap with the new UK and write it into the storage device;

[0072] Step S503: Determine whether the old UK is leaked. If the old UK is leaked, execute step S504. If the old UK is not leaked, execute step S507.

[0073] Step S504: monitor system resource usage;

[0074] Step S505: Determine whether there are any spare system resources. If so, execute step S506; if not, execute step S504;

[0075] Step S506: randomly regenerate the DEK and re-encrypt the encrypted historical data;

[0076] Step S507: End.

[0077] In an exemplary embodiment, based on the technical solution of the present invention, encrypted storage of video files is performed on an Internet Protocol Camera (IPC).

[0078] Step 1: On the IPC web management page, the interface for setting the video segment duration, setting the user key, and changing the user key is provided to set the video segment duration, user key, and change the user key;

[0079] Step 2: Create a KeyMap file and encrypt it with UK and store it in the flash memory of the IPC;

[0080] Step 3: Randomly generate DEK and KID and save them to the KeyMap file.

[0081] Step 4: Encrypt the audio and video data continuously collected by the IPC according to the DEK generated in step 3, and store the encrypted data in the storage card (SD card) of the IPC.

[0082] In another exemplary embodiment, based on the technical solution of the present invention, data encryption is performed on an open platform using a data encryption function.

[0083] It should be noted that an open platform is a platform that provides applications developed by users that can be installed and run on hardware devices.

[0084] Step 1: In the API (Application Program Interface) of the open platform, add interfaces for enabling encryption, setting user keys, and changing user keys to enable encryption, set user keys, and change user keys;

[0085] Step 2: Create a KeyMap file and encrypt the KeyMap file using UK and store it in the first storage;

[0086] Step 3: Randomly generate DEK and KID, and save the randomly generated DEK and KID to the KeyMap file;

[0087] Step 4: Encrypt the data to be encrypted according to the DEK generated in step 3. The data to be encrypted may be data generated by a user application and need to be stored (such as result data after video analysis, image data captured from the video), and store the encrypted data in a second memory.

[0088] Through the technical solution of the present invention, users are supported to set user keys of KeyMap files, update keys of KeyMap files, and encrypt and protect KeyMap files through KeyMap files using user keys; the encryption keys in the KeyMap files are used to encrypt data to be encrypted, and the encrypted data are stored in a segmented manner, and the encryption keys used for each segment of the file are different. When the user key is updated, it is only necessary to re-encrypt the KeyMap file to quickly complete the update of the user key. Even if the key of a single file is leaked, it will not affect other encrypted files. Since the encrypted KeyMap file and the encrypted data file are two independent files, they are stored separately in different storage devices, thereby ensuring the security of the encrypted KeyMap file and the encrypted data file, and storing the encrypted data in segments.

[0089] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.

[0090] In this embodiment, a file encryption device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.

[0091] Figure 6 is a structural block diagram of a file encryption device according to an embodiment of the present invention; Figure 6 As shown, including:

[0092] A creation module 62, configured to create a key mapping file, wherein the key mapping file includes: an encryption key and a unique identifier corresponding to the encryption key, and a first encryption key in the key mapping file is used to encrypt data to be encrypted;

[0093] An encryption module 64, configured to encrypt the key mapping file according to a preset first user key;

[0094] The detection module 66 is configured to encrypt the key mapping file according to the second user key when it is detected that the first user key needs to be updated to the second user key.

[0095] Through the present invention, a key mapping file is created, wherein the key mapping file includes: an encryption key and a unique identifier corresponding to the encryption key, the first encryption key in the key mapping file is used to encrypt the data to be encrypted; the key mapping file is encrypted according to the preset first user key; when it is detected that the first user key needs to be updated to the second user key, the key mapping file is encrypted according to the second user key, that is, the key mapping file storing the encryption key and the unique identifier corresponding to the encryption key is encrypted by the first user key, and when the first user key needs to be updated, the key mapping file is encrypted according to the second user key. The above technical solution solves the problem that the key update takes a long time when the key of the encrypted data needs to be updated in the related technology, thereby ensuring that the user key can be updated quickly when the old user key is not leaked; even if the old user key has been leaked, the spread of the encryption key leakage problem can be prevented in time, and the data re-encryption can be completed in an orderly manner.

[0096] It should be noted that the encryption key is generated using a random number generation algorithm, and a unique identifier is assigned to it, and the encryption key and the unique identifier corresponding to the encryption key are stored in a key mapping file.

[0097] In an optional embodiment, the detection module is also used to encrypt the key mapping file according to a preset first user key, and then, when it is detected that the first user key needs to be updated to a second user key and the first user key is leaked, determine a second encryption key from the key mapping file; and re-encrypt the data to be encrypted according to the second encryption key.

[0098] Specifically, when it is detected that the first user key needs to be updated to the second user key, the key mapping file is obtained, and the key mapping file is decrypted with the first user key, and the key mapping file is re-encrypted with the second user key. If it is determined that the first user key is leaked, the data to be encrypted that was encrypted with the first encryption key is re-encrypted according to the second encryption key, wherein the second encryption key is also saved in the key mapping file, and the key mapping file re-encrypted with the second user key and the re-encrypted data to be encrypted are saved.

[0099] In an exemplary embodiment, the encryption module is also used to encrypt the key mapping file according to a preset first user key, and then encrypt the data to be encrypted according to the first encryption key to obtain encrypted data; obtain the unique identifier corresponding to the first encryption key, and combine the unique identifier corresponding to the first encryption key and the encrypted data into encrypted data.

[0100] That is to say, the data to be encrypted is encrypted according to the first encryption key to obtain the encrypted data, the unique identifier corresponding to the first encryption key is determined in the key mapping file, and the unique identifier corresponding to the first encryption key is placed at the very front of the encrypted data to form the encrypted data. The embodiment of the present invention does not limit the placement position of the unique identifier corresponding to the encryption key. The unique identifier corresponding to the encryption key is only for obtaining the encryption key in the key mapping file through the unique identifier.

[0101] In an optional embodiment, the encryption module is also used to, after encrypting the key mapping file according to a preset first user key, segment the data to be encrypted according to a segmentation rule to obtain multiple segmented data; the segmentation rule includes at least one of the following: target duration, target data length; determine multiple encryption keys from the key mapping file, and encrypt the multiple data respectively using multiple encryption keys.

[0102] That is to say, if the data to be encrypted needs to be segmented, the data to be encrypted can be segmented, for example, the data to be encrypted can be segmented according to the target duration, or the data to be encrypted can be segmented according to the target data length. According to the type of data to be encrypted, segmentation according to the target duration or segmentation according to the target data length is selected. After the data to be encrypted is segmented, multiple data are obtained, and then multiple encryption keys are determined from the key mapping file. First, one of the data to be encrypted is encrypted using an encryption key. After one data is completed, the next data is re-encrypted until the encryption of multiple data is completed, thereby completing the encryption of all the data to be encrypted. After the encryption of all the data to be encrypted is completed, the next data to be encrypted is re-encrypted until the encryption of all the data to be encrypted is completed, thereby completing the encryption of multiple data.

[0103] For example, determine the segmentation rules of the data to be encrypted, and choose to segment according to the target duration or according to the target data length according to the type of data to be encrypted. If the data to be encrypted is audio and video data, you can choose to segment according to the audio and video duration, or you can choose to segment according to the data length (such as one segment every 30 minutes, or one segment every 100MB); if the data to be encrypted is other types of data (such as pure binary data), you can choose to segment according to the data length (such as one segment every 50MB). It should be noted that the above numbers are only for understanding the numerical values ​​selected by the technical solution of the embodiment of the present invention, and can be any possible numerical values ​​during actual operation.

[0104] In an exemplary embodiment, the encryption module is also used to obtain multiple unique identifiers corresponding to the multiple encryption keys and multiple target data obtained by encrypting the multiple data respectively by the multiple encryption keys after encrypting the multiple data respectively by the multiple encryption keys; and combine the multiple unique identifiers with the multiple target data corresponding to the multiple unique identifiers.

[0105] In other words, after encrypting multiple data, multiple unique identifiers corresponding to the multiple encryption keys are determined in the key mapping file, and the multiple unique identifiers are combined with multiple target data obtained by encrypting the multiple data using the multiple encryption keys to obtain multiple encrypted data.

[0106] In an exemplary embodiment, the encryption module is also used to combine the unique identifier corresponding to the first encryption key and the encrypted data into encrypted data, and then send the encrypted data to a data recipient to instruct the data recipient to determine the first encryption key based on the unique identifier corresponding to the first encryption key carried in the encrypted data, and decrypt the encrypted data based on the first encryption key.

[0107] Specifically, after the data to be encrypted are combined into encrypted data through the first encryption key and the unique identifier corresponding to the first encryption key, the data recipient obtains the key mapping file and the encrypted data, the data recipient decrypts the key mapping file according to the user key, reads the encrypted data, and obtains the unique identifier corresponding to the first encryption key from the encrypted data, obtains the corresponding first encryption key from the decrypted key mapping file according to the unique identifier, and decrypts the encrypted data according to the first encryption key.

[0108] Furthermore, the data to be encrypted is segmented according to the segmentation rule, and after the multiple data are encrypted respectively by multiple encryption keys, the data receiver obtains the key mapping file and multiple encrypted data, and the data receiver decrypts the key mapping file according to the user key, reads one of the multiple encrypted data, and obtains the unique identifier from the encrypted data, obtains the corresponding encryption key from the decrypted key mapping file according to the unique identifier, and decrypts the encrypted data according to the encryption key. Whether the multiple encrypted data have been decrypted, if the decryption is not completed, continue and obtain the unique identifier from the next encrypted data, obtain the corresponding encryption key from the decrypted key mapping file according to the unique identifier, and decrypt the next encrypted data according to the encryption key, until all encrypted data are decrypted.

[0109] In an exemplary embodiment, the above-mentioned device further includes a storage module, which is used to store the key mapping file in a first preset location, and store the encrypted data in a second preset location.

[0110] In order to further improve the security of file storage, the key mapping file and the encrypted data are stored in different locations. For example, the encrypted storage of video files is implemented on a network camera. The key mapping file is encrypted by the user key and stored in the flash memory of the network camera, and the encrypted data is stored in the memory card (SD card) of the network camera.

[0111] An embodiment of the present invention further provides a storage medium, which includes a stored program, wherein the program executes any of the above methods when it is run.

[0112] In an exemplary embodiment, in this embodiment, the above storage medium may be configured to store a computer program for performing the following steps:

[0113] S1, creating a key mapping file, wherein the key mapping file includes: an encryption key and a unique identifier corresponding to the encryption key, and the first encryption key in the key mapping file is used to encrypt data to be encrypted;

[0114] S2, encrypting the key mapping file according to a preset first user key;

[0115] S3: When it is detected that the first user key needs to be updated to a second user key, encrypt the key mapping file according to the second user key.

[0116] In an exemplary embodiment, in this embodiment, the above-mentioned storage medium may include but is not limited to: a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and other media that can store computer programs.

[0117] An embodiment of the present invention further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.

[0118] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.

[0119] In an exemplary embodiment, in this embodiment, the processor may be configured to perform the following steps through a computer program:

[0120] S1, creating a key mapping file, wherein the key mapping file includes: an encryption key and a unique identifier corresponding to the encryption key, and the first encryption key in the key mapping file is used to encrypt data to be encrypted;

[0121] S2, encrypting the key mapping file according to a preset first user key;

[0122] S3: When it is detected that the first user key needs to be updated to a second user key, encrypt the key mapping file according to the second user key.

[0123] In an exemplary embodiment, the specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementation modes, and this embodiment will not be described in detail here.

[0124] Obviously, those skilled in the art should understand that the above modules or steps of the present invention can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices. In an exemplary embodiment, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order than here, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. In this way, the present invention is not limited to any specific combination of hardware and software.

[0125] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A file encryption method, characterized in that: include: Creating a key mapping file, wherein the key mapping file includes: an encryption key and a unique identifier corresponding to the encryption key, and a first encryption key in the key mapping file is used to encrypt data to be encrypted; Encrypting the key mapping file according to a preset first user key; In the case where it is detected that the first user key needs to be updated to a second user key, encrypting the key mapping file according to the second user key; Among them, after encrypting the key mapping file according to the preset first user key, the method also includes: when it is detected that the first user key needs to be updated to the second user key and the first user key is leaked, determining the second encryption key from the key mapping file; and re-encrypting the data to be encrypted according to the second encryption key.

2. The method according to claim 1, characterized in that After encrypting the key mapping file according to the preset first user key, the method further includes: Encrypting the data to be encrypted according to the first encryption key to obtain encrypted data; A unique identifier corresponding to the first encryption key is obtained, and the unique identifier corresponding to the first encryption key and the encrypted data are combined into encrypted data.

3. The method according to claim 1, characterized in that After encrypting the key mapping file according to the preset first user key, the method further includes: The data to be encrypted is segmented according to a segmentation rule to obtain a plurality of segmented data; the segmentation rule includes at least one of the following: target duration, target data length; A plurality of encryption keys are determined from the key mapping file, and the plurality of data are encrypted respectively by the plurality of encryption keys.

4. The method according to claim 3, characterized in that After encrypting the plurality of data respectively by using a plurality of encryption keys, the method further comprises: Acquire multiple unique identifiers corresponding to the multiple encryption keys, and multiple target data obtained by encrypting the multiple data using the multiple encryption keys respectively; The multiple unique identifiers are respectively combined with the multiple target data corresponding to the multiple unique identifiers.

5. The method according to claim 2, characterized in that: After combining the unique identifier corresponding to the first encryption key and the encrypted data into encrypted data, the method further includes: The encrypted data is sent to a data recipient to instruct the data recipient to determine the first encryption key according to a unique identifier corresponding to the first encryption key carried in the encrypted data, and to decrypt the encrypted data according to the first encryption key.

6. The method according to claim 2, characterized in that The key mapping file is stored in a first preset location, and the encrypted data is stored in a second preset location.

7. A file encryption device, characterized in that: include: A creation module, used to create a key mapping file, wherein the key mapping file includes: an encryption key and a unique identifier corresponding to the encryption key, and the first encryption key in the key mapping file is used to encrypt the data to be encrypted; An encryption module, used for encrypting the key mapping file according to a preset first user key; a detection module, configured to encrypt the key mapping file according to the second user key when detecting that the first user key needs to be updated to a second user key; Among them, the detection module is also used to encrypt the key mapping file according to the preset first user key, and then, when it is detected that the first user key needs to be updated to the second user key and the first user key is leaked, determine the second encryption key from the key mapping file; and re-encrypt the data to be encrypted according to the second encryption key.

8. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein the program executes the method described in any one of claims 1 to 6 when executed.

9. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to execute the method according to any one of claims 1 to 6 through the computer program.