Source file processing method and device, storage medium and electronic device

The Electron development application source files are encrypted by generating encryption keys and modifying directory tables, which solves the problem that the source code of the Electron application is easily copied, and an effective protection mechanism and transparent decryption process are realized.

CN116089973BActive Publication Date: 2025-09-05BEIJING ANTIY NETWORK SAFETY TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211728357.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-29
Publication Date
2025-09-05
Estimated Expiration
2042-12-29

AI Technical Summary

Technical Problem

The existing technology cannot effectively encrypt the application source code developed by Electron, resulting in it being easily copied and analyzed, and lacking a protection mechanism.

Method used

The target source file is encrypted by generating an encryption key, and the directory table is modified to indicate the storage address. At the same time, the file header structure is filled with random numbers and encryption protection keys, ensuring that the encrypted file is difficult to crack.

Benefits of technology

It realizes effective encryption protection for the source code of Electron development application, prevents unauthorized copying and analysis, and ensures that files are transparently decrypted during Electron operation, without user perception.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116089973B_ABST
    Figure CN116089973B_ABST
Patent Text Reader

Abstract

This application discloses a method and apparatus for processing source files, a storage medium, and an electronic device. The method comprises: obtaining an encryption password input by a target object, generating an encryption key based on the encryption password; encrypting a target source file based on the encryption key; writing the encrypted target source file to a data storage area, and modifying a directory table generated based on the target source file based on the encrypted target source file, wherein the directory table is used to at least indicate the storage address of the encrypted target source file in the data storage area. The above technical solution solves the problem that the existing technology cannot accurately encrypt the target source file, and thus cannot provide subsequent access to the encrypted target source file.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computers, and in particular to a method and device for processing source files, a storage medium, and an electronic device. Background Art

[0002] Currently, applications developed based on Electron have the advantages of being cross-platform, quick to get started, and low barriers to entry, and are increasingly being accepted by the market. However, there is also a major disadvantage in developing applications based on Electron, namely the lack of an effective protection mechanism for the source code. The source code of applications developed with Electron can be easily copied, transplanted, and analyzed.

[0003] Regarding the problems in related technologies, the existing technologies cannot accurately encrypt the target source files and thus cannot provide subsequent access to the encrypted target source files, and no effective solutions have been proposed yet. Summary of the Invention

[0004] The embodiments of the present application provide a source file processing method and device, a storage medium, and an electronic device to at least solve the problems in the related art, such as the inability of the existing technology to accurately encrypt the target source file and thus the inability to provide subsequent acquisition of the encrypted target source file.

[0005] According to one embodiment of the present application, a method for processing a source file is provided, including: obtaining an encryption password input by a target object, generating an encryption key based on the encryption password; encrypting a target source file based on the encryption key; writing the encrypted target source file to a data storage area, and modifying a directory table generated based on the target source file based on the encrypted target source file, wherein the directory table is at least used to indicate the storage address of the encrypted target source file in the data storage area.

[0006] In an exemplary embodiment, before encrypting the target source file according to the encryption key, the method also includes: obtaining a file header structure of a processing package of the source file, wherein the processing package of the source file is a file corresponding to the data storage area; filling the file header structure according to a random number and the encryption key, wherein the random number is used to generate an encryption protection key, and the encryption protection key is used to generate the encryption key.

[0007] In an exemplary embodiment, before modifying the directory table generated according to the target source file based on the encrypted target source file, the method further includes: traversing multiple target source files to obtain the number of multiple target source files and the file types of multiple target source files; determining the total number of directories in the directory table based on the number, and constructing a directory structure of the directory table based on the file type, wherein the total number of directories corresponds to the number; and generating the directory table based on the total number of directories and the directory structure.

[0008] In an exemplary embodiment, after modifying the directory table generated according to the encrypted target source file, the method further includes: encrypting the filled file header structure and the filled directory table according to the encryption protection key, so as to at least encrypt the encryption key in the filled file header structure and encrypt the storage address in the directory table.

[0009] In an exemplary embodiment, after modifying the directory table generated according to the encrypted target source file, the method further includes: obtaining a decryption password input by the target object, and obtaining the encryption protection key and the encryption key according to the decryption password; decrypting the encrypted directory table according to the encryption protection key to obtain a decrypted directory table; when the target object requests access to the first source file, obtaining the target storage address of the first source file according to the decrypted directory table; and decrypting the encrypted first source file in the data storage area according to the target storage address and the encryption key.

[0010] In an exemplary embodiment, decrypting the encrypted first source file in the data storage area according to the target storage address and the encryption key includes: obtaining the encrypted first source file from the data storage area according to the target storage address; and decrypting the encrypted first source file according to the encryption key.

[0011] In an exemplary embodiment, obtaining the encryption protection key and the encryption key according to the decryption password includes: obtaining the random number in the file header structure; obtaining the encryption protection key according to the random number and the decryption password through a key derivation algorithm; and decrypting the file header structure according to the encryption protection key to obtain the encryption key.

[0012] In an exemplary embodiment, generating an encryption key based on the encryption password includes: obtaining a random number generated by a random algorithm; generating an encryption protection key from the random number and the encryption password according to a key derivation algorithm; and generating an encryption key based on the encryption protection key and the random number.

[0013] According to another embodiment of the present application, a source file processing device is also provided, including: an acquisition module, used to obtain an encryption password input by a target object, and generate an encryption key based on the encryption password; an encryption module, used to encrypt the target source file based on the encryption key; a writing module, used to write the encrypted target source file to a data storage area, and modify a directory table generated based on the target source file based on the encrypted target source file, wherein the directory table is at least used to indicate the storage address of the encrypted target source file in the data storage area.

[0014] According to another aspect of the embodiments of the present application, a computer-readable storage medium is provided, in which a computer program is stored. The computer program is configured to execute the above-mentioned source file processing method when running.

[0015] In an embodiment of the present application, an encryption password input by a target object is obtained, and an encryption key is generated according to the encryption password; the target source file is encrypted according to the encryption key; the encrypted target source file is written to a data storage area, and a directory table generated according to the target source file is modified according to the encrypted target source file, wherein the directory table is at least used to indicate the storage address of the encrypted target source file in the data storage area. In short, the target source file is encrypted according to the encryption key and written to the data storage area, and a modified directory table for indicating the storage address of the encrypted target source file is obtained at the same time. The above technical solution solves the problem that the existing technology cannot accurately encrypt the target source file, and thus cannot provide subsequent access to the encrypted target source file, thereby comprehensively solving the problem of protecting the source file. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0017] Figure 1 This is a hardware structure block diagram of a computer terminal for a source file processing method according to an embodiment of the present application;

[0018] Figure 2 is a flowchart of a method for processing a source file according to an embodiment of the present application;

[0019] Figure 3 1 is a schematic diagram of the Electron software structure before modification according to the source file processing method of an embodiment of the present application;

[0020] Figure 41 is a schematic diagram of the modified Electron software structure according to the source file processing method of the embodiment of the present application;

[0021] Figure 5 APP.SANTIY is a schematic diagram of the overall structure of the source file processing method according to an embodiment of the present application;

[0022] Figure 6 APP.SANTIY file header structure diagram according to the source file processing method of the embodiment of the present application;

[0023] Figure 7 1 is a schematic diagram of the structure of the APP.SANTIY directory table according to the source file processing method of an embodiment of the present application;

[0024] Figure 8 This is a structural block diagram of an optional source file processing device according to an embodiment of the present application. DETAILED DESCRIPTION

[0025] In order to enable those skilled in the art to better understand the present invention, the following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of this application.

[0026] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in a sequence other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0027] The method embodiments provided in the embodiments of the present application can be executed in a computer terminal or similar computing device. Taking running on a computer terminal as an example, Figure 1 This is a hardware structure block diagram of a computer terminal for a source file processing method according to an embodiment of the present application. Figure 1 As shown, the computer terminal may include one or more ( Figure 1Only one is shown) a processor 102 (the processor 102 may include but is not limited to a microprocessor MCU or a programmable logic device FPGA and other processing devices) 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 will 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. For example, the computer terminal may also include Figure 1 More or fewer components than shown, or with Figure 1 Equivalent functions or comparisons shown Figure 1 Shown are different configurations with more functionality.

[0028] 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 source file processing method in the embodiment of the present application. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, implementing the above-mentioned 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 instances, the memory 104 may further include a memory remotely located 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.

[0029] The transmission device 106 is used to receive or transmit data via a network. A specific example of the aforementioned network may include a wireless network provided by a computer terminal's communications provider. In one embodiment, the transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices via a base station to enable communication with the Internet. In another embodiment, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

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

[0031] Step S202: Obtain the encryption password input by the target object, and generate an encryption key based on the encryption password;

[0032] Step S204, encrypting the target source file according to the encryption key;

[0033] Step S206, writing the encrypted target source file into the data storage area, and modifying the directory table generated according to the target source file according to the encrypted target source file, wherein the directory table is at least used to indicate the storage address of the encrypted target source file in the data storage area.

[0034] Through the above steps, the encryption password input by the target object is obtained, and an encryption key is generated based on the encryption password; the target source file is encrypted based on the encryption key; the encrypted target source file is written to the data storage area, and the directory table generated based on the target source file is modified based on the encrypted target source file, wherein the directory table is at least used to indicate the storage address of the encrypted target source file in the data storage area. In short, the target source file is encrypted based on the encryption key and written to the data storage area, and a modified directory table for indicating the storage address of the encrypted target source file is obtained. The above technical solution solves the problems of the existing technology that cannot accurately encrypt the target source file and thus cannot provide subsequent access to the encrypted target source file, thereby comprehensively solving the problem of protecting the source file.

[0035] Optionally, before encrypting the target source file according to the encryption key, the method further includes: obtaining a file header structure of a processing package of the source file, wherein the processing package of the source file is a file corresponding to the data storage area; filling the file header structure according to a random number and the encryption key, wherein the random number is used to generate an encryption protection key, and the encryption protection key is used to generate the encryption key.

[0036] Specifically, the processing package structure of the source file is as follows Figure 5 As shown, it includes a file header, a directory table, and a data area (equivalent to the data storage area in the embodiment of the present application). In the optional embodiment of the present application, a random number can be generated according to a random number generation algorithm, and an encryption protection key can be generated according to the random number combined with the encryption password input by the target object (ie, the user) through the PKCS#5 key derivation algorithm, and then an encryption key is generated according to the encryption protection key. After the encryption key is generated, the encryption key and the random number are filled into the file header structure. Further, the file header structure is as follows Figure 6 As shown, after the filling is completed, the Magic number, version information, signature information and encryption key in the file header structure are encrypted and protected according to the encryption protection key and written into the processing package of the source file. It should be noted that the secure random number filled in the file header structure is not encrypted.

[0037] Optionally, before modifying the directory table generated according to the target source file based on the encrypted target source file, the method also includes: traversing multiple target source files to obtain the number of multiple target source files and the file types of multiple target source files; determining the total number of directories in the directory table based on the number, and constructing a directory structure of the directory table based on the file type, wherein the total number of directories corresponds to the number; and generating the directory table based on the total number of directories and the directory structure.

[0038] It should be noted that before encrypting the source file, it is also necessary to generate a directory table to indicate the storage address of the encrypted source file in the data storage. The directory table is saved in records, and the size of a record is 1024 bytes. Specifically, traverse the unencrypted source files, determine the size of the unencrypted source files, and generate records (i.e. directories) of 1024 bytes each. When a record cannot be saved, the next record will continue to be saved, and so on. At the same time, determine the file type of the unencrypted source file and construct the directory table structure. Generate a directory table based on the directory table structure and the total number of records, and record the total number of records (i.e. the total number of directories) in the first entry of the directory table. The directory table structure is as follows: Figure 7 As shown, from Figure 7 It can be seen that the first entry in the directory table is used to record the total number of directory entries. In other words, the recording of the actual source file size can be selected starting from the second entry in the directory table.

[0039] Optionally, after modifying the directory table generated according to the encrypted target source file, the method further includes: encrypting the filled file header structure and the filled directory table according to the encryption protection key, so as to at least encrypt the encryption key in the filled file header structure and encrypt the storage address in the directory table.

[0040] As described in the aforementioned optional embodiment, the populated file header structure is encrypted using the encryption protection key and written into the source file processing package. Furthermore, while the target source file is encrypted using the encryption key and written into the data storage area within the source file processing package, the generated directory table is modified based on the storage address of the encrypted target source file within the data storage area. The modified directory table is then encrypted using the encryption protection key and written into the source file processing package.

[0041] Optionally, after modifying the directory table generated according to the encrypted target source file, the method further includes: obtaining a decryption password input by the target object, and obtaining the encryption protection key and the encryption key according to the decryption password; decrypting the encrypted directory table according to the encryption protection key to obtain a decrypted directory table; when the target object requests access to the first source file, obtaining the target storage address of the first source file according to the decrypted directory table; and decrypting the encrypted first source file in the data storage area according to the target storage address and the encryption key.

[0042] It can be understood that the decryption password and the encryption password are the same password, so the encryption protection key and encryption key generated according to the encryption password, and the encryption protection key and decryption key decrypted according to the decryption password also correspond to the same key.

[0043] Optionally, decrypting the encrypted first source file in the data storage area according to the target storage address and the encryption key includes: obtaining the encrypted first source file from the data storage area according to the target storage address; and decrypting the encrypted first source file according to the encryption key.

[0044] It is understandable that the first source file can be all encrypted target source files, several encrypted target source files, or a specific target source file, depending on the needs of the target object, that is, it can be determined according to the operation of the target object. Figure 4 As shown, the target object operates an encrypted file system based on Chrome or Nodejs, and then can find the decrypted directory table through the encrypted file system, and then can determine the location of the first source file in the data storage area, and then read and decrypt the first source file.

[0045] Optionally, obtaining the encryption protection key and the encryption key according to the decryption password includes: obtaining the random number in the file header structure; obtaining the encryption protection key according to the random number and the decryption password through a key derivation algorithm; and decrypting the file header structure according to the encryption protection key to obtain the encryption key.

[0046] That is, when the program is run, the specific decryption process is as follows: after obtaining the decryption password, the random number in the file header structure of the source file's processing package is obtained. Then, based on the random number and the decryption password, the encryption protection key is calculated using the PKCS#5 key derivation algorithm. Furthermore, the file header structure is decrypted using the encryption protection key. For example, the file header structure can be 1024 bytes, of which the last 512 bytes are the random number and the first 512 bytes contain the rest of the file header structure. In other words, the encryption protection key actually encrypts and decrypts the first 512 bytes. After decrypting the first 512 bytes, the encryption key and magic number can be obtained. The magic number can be used to verify whether it is the desired encrypted source file processing package.

[0047] Optionally, generating an encryption key based on the encryption password includes: obtaining a random number generated by a random algorithm; generating an encryption protection key from the random number and the encryption password according to a key derivation algorithm; and generating an encryption key based on the encryption protection key and the random number.

[0048] For example, the random algorithm can generate a random number of 512 bytes in length. The encryption protection key can be obtained using the PKCS#5 key derivation algorithm based on the random number and the encryption password. The encryption key can then be determined by dividing the encryption protection key with the random number and taking the remainder. The specific determination method is not limited in this optional embodiment. However, it should be noted that once the encryption key is determined, it remains unchanged and is inserted into the file header structure, encrypted and protected by the encryption protection key. The encryption protection key is not stored and can only be calculated using the PKCS#5 key derivation algorithm using the user's input password and the random number. This provides better protection for the source file.

[0049] In order to better understand the process of the above-mentioned source file processing method, the implementation method flow of the above-mentioned source file processing is described below in combination with the optional embodiment of the present application, but it is not used to limit the technical solution of the optional embodiment of the present application.

[0050] In an optional embodiment of the present application, a method for processing source files is provided, by embedding the encrypted file system designed in the optional embodiment of the present application into the running file of Electron, replacing the original Electron file system based on ASAR, specifically, by using the encryption key generated according to the encryption password to encrypt the target source file to obtain the encrypted source code package APP.SANTIY, and replacing the file system and APP.ASAR in the original Electron running file with the encrypted file system and APP.SANTIY, and after the replacement, the running file using Electron needs to obtain the encryption key again according to the decryption password, thereby making the encrypted target source file not easy to be cracked, thereby comprehensively solving the problem of protecting Electron's source code (i.e., the target source file in the above embodiment).

[0051] Specifically, the Electron software structure diagram before modification is as follows Figure 3 As shown, including Chrome, Nodejs, file system, APP.ASAR; the modified Electron software structure diagram is as follows Figure 4 As shown, it includes Chrome, Node.js, an encrypted file system, and APP.SANTIY. The difference between the modified Electron software structure and the encrypted file system is that the modified Electron executable program is added, and the source code package APP.SANTIY is encrypted by the encryption tool, which also includes the encryption tool.

[0052] The overall design concept of this optional embodiment is as follows: the user runs the encryption tool and enters an encryption password. The encryption tool generates an encryption key based on the user's input encryption password using the PKCS#5 key derivation algorithm. The encryption key is used to encrypt the source code, and the encrypted source code is written to the APP.SANTIY package. Finally, APP.SANTIY is released together with the modified Electron. When the program runs, the user is asked to enter a decryption key. After the user enters the decryption key, Electron loads the encrypted file system. The encrypted file system reads the relevant parameters in APP.SANTIY and calculates the decryption key using the PKCS#5 key derivation algorithm. It then reads the encrypted source code from the APP.SANTIY package according to the file path requested by the user, decrypts it, and returns it to the user.

[0053] It should be noted that Figure 5 APP.SANTIY is a schematic diagram of the overall structure of the source file processing method according to an optional embodiment of the present application, such as Figure 5 As shown, APP.SANTIY includes a file header, a directory table, and a data area (equivalent to the data storage area in the above embodiment), wherein the file header structure is as follows Figure 6 As shown, it includes Magic number (identifier of this Electron program), version information, encryption key, signature information, and secure random number. The schematic diagram of the directory table is as follows Figure 7 shown.

[0054] Furthermore, encrypting the source code through the encryption tool includes: the encryption tool needs to traverse the source code twice when encrypting the user source code. The first traversal determines the size of the directory table, and the second traversal encrypts each specific file and writes it into the APP.SANTIY file, and writes the specific offset of the file (that is, the storage address of the encrypted target source file in the data area) into the directory table until the encryption of the last file is completed.

[0055] It should be noted that the directory table is saved by record. The size of a record is 1024 bytes. When a record cannot be saved, the next record is saved.

[0056] Furthermore, the first traversal steps are as follows:

[0057] Step 1: After the user enters the encryption password, the encryption protection key is generated using the entered encryption password and the generated 512-byte random number through the PKCS#5 algorithm. At the same time, the encryption key is generated using the random number generation algorithm based on the encryption protection key and the random number.

[0058] Step 2: Follow the steps below: Figure 6 The file header structure shown is filled with data, and the filled file structure is encrypted using the encryption protection key and written into the APP.SANTIY file. It should be noted that the random number in the file header structure is not encrypted.

[0059] Step 3: Traverse the source file directory by depth or breadth, and proceed as follows for each record traversed: Figure 7 In the directory table structure shown, if a record cannot be stored, the next record in the file continues to be saved, and the specific offset of the file in the file record is not recorded in the first traversal.

[0060] Step 4: After all directories are traversed, the total number of records obtained is recorded in the first record of the directory table.

[0061] Furthermore, the second traversal steps are as follows:

[0062] Step 1: Reload the directory table and calculate the starting offset of the data area.

[0063] Step 2: Read the source file and encrypt it into the data area. At the same time, find the corresponding directory record and modify the file offset record and size of the corresponding record (that is, record the storage address and file size of the encrypted target source file in the data storage area).

[0064] Step 3: Finally, encrypt the directory table according to the encryption protection key and write it into the APP.SANTIY file.

[0065] It is understandable that modifications to Electron mainly require the implementation of standard file system interfaces. Unmodified Electron, such as Figure 3 As shown in the figure, after startup, the normal file system is loaded, and all user access to files will be converted into access to ASAR files. After implementing the encrypted file system, replacing the previous ASAR access logic can realize the decryption of APP.SANTIY. The modified structure is as follows Figure 4 shown.

[0066] Then, when the modified Electron program needs to be used, the specific decryption process is as follows:

[0067] Step 1: After the program is started, the encrypted file system is loaded and the program will ask the user to enter the decryption password.

[0068] Step 2: Get the random number in the file header structure, and then obtain the encryption protection key based on the decryption password and the PKCS#5 key derivation algorithm. Specifically, read the first 1024 bytes of the APP.SANTIY file, and calculate the encryption protection password by combining the random number with the decryption password entered by the user.

[0069] Step 3: Decrypt the first 512 bytes of the APP.SANTIY file according to the encryption password and verify the Magic number to see if it is in the legal APP.SANTIY format.

[0070] It should be noted that the first 512 bytes contain the magic number, version information, encryption key, and signature information in the file header structure. The first 512 bytes and the secure random number together make up the first 1024 bytes.

[0071] Step 4: Extract the encryption key from the first 512 decrypted bytes.

[0072] Step 5: Decrypt the entire directory area using the encryption protection key and create a related cache storage directory table in memory.

[0073] Step 6: When the user accesses the encrypted source file, the method for reading the encrypted file is used. In this method, the specific offset address and size of the file are found in the directory table according to the file path, and the file is read and decrypted and returned.

[0074] According to the above implementation methods, the optional embodiments of the present application have the following advantages: 1) All codes of user applications including resource files are encrypted using a standard, and all encryptions are written into APP.SANTIY according to the format. When viewed with any other editing software, they are all garbled, thereby achieving the protection of user source code; 2) An encrypted file system is embedded in Electron, and the reading of files is transparently decrypted during the running of the program, and the user is unaware of it; 3) The encryption keys are all derived using the PKCS#5 key method, and the system will not save the master key, so it is difficult to crack even if the entire application is obtained.

[0075] It should be noted that for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that this application is not limited by the order of the actions described, because according to this application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by this application.

[0076] According to another aspect of the embodiment of the present application, a source file processing device for implementing the above-mentioned source file processing method is also provided. Figure 8 As shown, Figure 8 1 is a block diagram of an optional source file processing device according to an embodiment of the present application, the device comprising:

[0077] An acquisition module 82 is configured to acquire an encryption password input by a target object and generate an encryption key based on the encryption password;

[0078] An encryption module 84 is used to encrypt the target source file according to the encryption key;

[0079] The writing module 86 is used to write the encrypted target source file into the data storage area, and modify the directory table generated according to the encrypted target source file, wherein the directory table is at least used to indicate the storage address of the encrypted target source file in the data storage area.

[0080] Through the above-mentioned device, the encryption password input by the target object is obtained, and an encryption key is generated based on the encryption password; the target source file is encrypted based on the encryption key; the encrypted target source file is written to the data storage area, and the directory table generated based on the target source file is modified based on the encrypted target source file, wherein the directory table is at least used to indicate the storage address of the encrypted target source file in the data storage area. In short, the target source file is encrypted based on the encryption key and written to the data storage area, and a modified directory table for indicating the storage address of the encrypted target source file is obtained. The above-mentioned technical solution solves the problems of the existing technology's inability to accurately encrypt the target source file and, therefore, the inability to provide subsequent access to the encrypted target source file, thereby comprehensively solving the problem of protecting the source file.

[0081] Optionally, the encryption module 84 is also used to obtain the file header structure of the processing package of the source file before encrypting the target source file according to the encryption key, wherein the processing package of the source file is the file corresponding to the data storage area; fill the file header structure according to the random number and the encryption key, wherein the random number is used to generate an encryption protection key, and the encryption protection key is used to generate the encryption key.

[0082] Specifically, the processing package structure of the source file is as follows Figure 5 As shown, it includes a file header, a directory table, and a data area (equivalent to the data storage area in the embodiment of the present application). In the optional embodiment of the present application, a random number can be generated according to a random number generation algorithm, and an encryption protection key can be generated according to the random number combined with the encryption password input by the target object (ie, the user) through the PKCS#5 key derivation algorithm, and then an encryption key is generated according to the encryption protection key. After the encryption key is generated, the encryption key and the random number are filled into the file header structure. Further, the file header structure is as follows Figure 6 As shown, after the filling is completed, the Magic number, version information, signature information and encryption key in the file header structure are encrypted and protected according to the encryption protection key and written into the processing package of the source file. It should be noted that the secure random number filled in the file header structure is not encrypted.

[0083] Optionally, the writing module 86 is further used to traverse multiple target source files before modifying the directory table generated according to the encrypted target source file to obtain the number of multiple target source files and the file types of multiple target source files; determine the total number of directories in the directory table according to the number, and construct a directory structure of the directory table according to the file type, wherein the total number of directories corresponds to the number; and generate the directory table according to the total number of directories and the directory structure.

[0084] It should be noted that before encrypting the source file, it is also necessary to generate a directory table to indicate the storage address of the encrypted source file in the data storage. The directory table is saved in records, and the size of a record is 1024 bytes. Specifically, traverse the unencrypted source files, determine the size of the unencrypted source files, and generate records (i.e. directories) of 1024 bytes each. When a record cannot be saved, the next record will continue to be saved, and so on. At the same time, determine the file type of the unencrypted source file and construct the directory table structure. Generate a directory table based on the directory table structure and the total number of records, and record the total number of records (i.e. the total number of directories) in the first entry of the directory table. The directory table structure is as follows: Figure 7 As shown, from Figure 7 It can be seen that the first entry in the directory table is used to record the total number of directory entries. In other words, the recording of the actual source file size can be selected starting from the second entry in the directory table.

[0085] Optionally, the writing module 86 is also used to modify the directory table generated according to the encrypted target source file, and then encrypt the filled file header structure and the filled directory table according to the encryption protection key, so as to at least encrypt the encryption key in the filled file header structure and encrypt the storage address in the directory table.

[0086] As described in the aforementioned optional embodiment, the populated file header structure is encrypted using the encryption protection key and written into the source file processing package. Furthermore, while the target source file is encrypted using the encryption key and written into the data storage area within the source file processing package, the generated directory table is modified based on the storage address of the encrypted target source file within the data storage area. The modified directory table is then encrypted using the encryption protection key and written into the source file processing package.

[0087] Optionally, the writing module 86 is also used to modify the directory table generated according to the encrypted target source file, obtain the decryption password input by the target object, and obtain the encryption protection key and the encryption key according to the decryption password; decrypt the encrypted directory table according to the encryption protection key to obtain a decrypted directory table; when the target object requests to access the first source file, obtain the target storage address of the first source file according to the decrypted directory table; decrypt the encrypted first source file in the data storage area according to the target storage address and the encryption key.

[0088] It can be understood that the decryption password and the encryption password are the same password, so the encryption protection key and encryption key generated according to the encryption password, and the encryption protection key and decryption key decrypted according to the decryption password also correspond to the same key.

[0089] Optionally, the writing module 86 is further configured to obtain the encrypted first source file from the data storage area according to the target storage address; and decrypt the encrypted first source file according to the encryption key.

[0090] It is understandable that the first source file can be all encrypted target source files, several encrypted target source files, or a specific target source file, depending on the needs of the target object, that is, it can be determined according to the operation of the target object. Figure 4 As shown, the target object operates an encrypted file system based on Chrome or Nodejs, and then can find the decrypted directory table through the encrypted file system, and then can determine the location of the first source file in the data storage area, and then read and decrypt the first source file.

[0091] Optionally, the writing module 86 is further used to obtain the random number in the file header structure; obtain the encryption protection key according to the random number and the decryption password through a key derivation algorithm; and decrypt the file header structure according to the encryption protection key to obtain the encryption key.

[0092] That is, when the program is run, the specific decryption process is as follows: after obtaining the decryption password, the random number in the file header structure of the source file's processing package is obtained. Then, based on the random number and the decryption password, the encryption protection key is calculated using the PKCS#5 key derivation algorithm. Furthermore, the file header structure is decrypted using the encryption protection key. For example, the file header structure can be 1024 bytes, of which the last 512 bytes are the random number and the first 512 bytes contain the rest of the file header structure. In other words, the encryption protection key actually encrypts and decrypts the first 512 bytes. After decrypting the first 512 bytes, the encryption key and magic number can be obtained. The magic number can be used to verify whether it is the desired encrypted source file processing package.

[0093] Optionally, the acquisition module 82 is further configured to acquire a random number generated by a random algorithm; generate an encryption protection key from the random number and the encryption password according to a key derivation algorithm; and generate an encryption key according to the encryption protection key and the random number.

[0094] For example, the random algorithm can generate a random number of 512 bytes in length. The encryption protection key can be obtained using the PKCS#5 key derivation algorithm based on the random number and the encryption password. The encryption key can then be determined by dividing the encryption protection key with the random number and taking the remainder. The specific determination method is not limited in this optional embodiment. However, it should be noted that once the encryption key is determined, it remains unchanged and is inserted into the file header structure, encrypted and protected by the encryption protection key. The encryption protection key is not stored and can only be calculated using the PKCS#5 key derivation algorithm using the user's input password and the random number. This provides better protection for the source file.

[0095] For a specific embodiment, reference may be made to the example shown in the above-mentioned method for processing source files, which will not be described in detail in this example.

[0096] Optionally, in this embodiment, the electronic device may be located in at least one network device among a plurality of network devices of a computer network.

[0097] Optionally, in this embodiment, the processor may be configured to execute the following steps through a computer program:

[0098] S1, obtaining an encryption password input by the target object, and generating an encryption key according to the encryption password;

[0099] S2, encrypting the target source file according to the encryption key;

[0100] S3, writing the encrypted target source file into the data storage area, and modifying the directory table generated according to the target source file according to the encrypted target source file, wherein the directory table is at least used to indicate the storage address of the encrypted target source file in the data storage area.

[0101] In one embodiment, the terminal device or server may be a node in a distributed system, wherein the distributed system may be a blockchain system, and the blockchain system may be a distributed system formed by connecting multiple nodes through network communication. The nodes may form a peer-to-peer (P2P) network, and any computing device, such as a server, terminal, or other electronic device, may become a node in the blockchain system by joining the peer-to-peer network.

[0102] According to one aspect of the present application, a computer program product is provided, comprising a computer program / instructions containing program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via a communication component and / or installed from a removable medium. When the computer program is executed by a central processing unit, the various functions provided in the embodiments of the present application are performed.

[0103] The serial numbers of the above embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0104] It should be noted that the computer system of the electronic device is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0105] A computer system includes a central processing unit (CPU), which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) or programs loaded from the storage unit into random access memory (RAM). The RAM also stores various programs and data required for system operation. The CPU, the read-only memory, and the RAM are connected to each other via a bus. Input / output interfaces (I / O interfaces) are also connected to the bus.

[0106] The following components are connected to the input / output interface: an input section including a keyboard, mouse, etc.; an output section including a cathode ray tube (CRT), a liquid crystal display (LCD), and a speaker; a storage section including a hard disk; and a communication section including a network interface card such as a local area network card and a modem. The communication section performs communication processing via a network such as the Internet. A drive is also connected to the input / output interface as needed. Removable media such as magnetic disks, optical disks, magneto-optical disks, semiconductor memories, etc. are installed in the drive as needed so that computer programs read from them can be installed into the storage section as needed.

[0107] In particular, according to an embodiment of the present application, the processes described in the various method flow charts can be implemented as computer software programs. For example, an embodiment of the present application includes a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for executing the methods shown in the flow charts. In such an embodiment, the computer program can be downloaded and installed from a network via a communication portion, and / or installed from a removable medium. When the computer program is executed by a central processing unit, the various functions defined in the system of the present application are performed.

[0108] According to one aspect of the present application, a computer-readable storage medium is provided, and a processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the methods provided in the various optional implementations described above.

[0109] Optionally, in this embodiment, the computer-readable storage medium may be configured to store a computer program for performing the following steps:

[0110] S1, obtaining an encryption password input by the target object, and generating an encryption key according to the encryption password;

[0111] S2, encrypting the target source file according to the encryption key;

[0112] S3, writing the encrypted target source file into the data storage area, and modifying the directory table generated according to the target source file according to the encrypted target source file, wherein the directory table is at least used to indicate the storage address of the encrypted target source file in the data storage area.

[0113] Optionally, in this embodiment, a person of ordinary skill in the art may understand that all or part of the steps in the various methods of the above embodiments may be completed by instructing the hardware related to the terminal device through a program, and the program may be stored in a computer-readable storage medium, which may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0114] The serial numbers of the above embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0115] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above-mentioned computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling one or more computer devices (which can be personal computers, servers, or network devices, etc.) to execute all or part of the steps of the methods of each embodiment of the present application.

[0116] In the above embodiments of the present application, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.

[0117] In the several embodiments provided in this application, it should be understood that the disclosed client can be implemented in other ways. Among them, the device embodiments described above are merely illustrative. For example, the division of the above-mentioned units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0118] The units described above as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0119] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.

[0120] The above is only a preferred embodiment of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A method for processing a source file, characterized in that: include: Obtaining an encryption password input by the target object, and generating an encryption key based on the encryption password; encrypting the target source file according to the encryption key; The encrypted target source file is written into the data storage area, and a directory table generated based on the target source file is modified according to the encrypted target source file, wherein the directory table is at least used to indicate a storage address of the encrypted target source file in the data storage area. Before encrypting the target source file according to the encryption key, the method further includes: Acquire a file header structure of a processing package of a source file, wherein the processing package of the source file is a file corresponding to the data storage area; Filling the file header structure according to a random number and the encryption key, wherein the random number is used to generate an encryption protection key, and the encryption protection key is used to generate the encryption key, wherein, after modifying the directory table generated according to the target source file according to the encrypted target source file, the method further includes: The filled file header structure and the filled directory table are encrypted according to the encryption protection key, so as to at least encrypt the encryption key in the filled file header structure and encrypt the storage address in the directory table.

2. The method for processing source files according to claim 1, wherein: Before modifying the directory table generated according to the encrypted target source file, the method further includes: Traversing the plurality of target source files to obtain the number of the plurality of target source files and the file types of the plurality of target source files; Determining a total number of directories in the directory table according to the quantity, and constructing a directory structure of the directory table according to the file type, wherein the total number of directories corresponds to the quantity; The directory table is generated according to the total number of directories and the directory structure.

3. The method for processing source files according to claim 1, wherein: After modifying the directory table generated according to the encrypted target source file, the method further includes: Obtaining a decryption password input by the target object, and obtaining the encryption protection key and the encryption key according to the decryption password; decrypting the encrypted directory table according to the encryption protection key to obtain a decrypted directory table; When the target object requests to access the first source file, obtaining the target storage address of the first source file according to the decrypted directory table; The encrypted first source file is decrypted in the data storage area according to the target storage address and the encryption key.

4. The method for processing source files according to claim 3, wherein: Decrypting the encrypted first source file in the data storage area according to the target storage address and the encryption key includes: Obtain the encrypted first source file from the data storage area according to the target storage address; The encrypted first source file is decrypted according to the encryption key.

5. The method for processing source files according to claim 3, wherein: Obtaining the encryption protection key and the encryption key according to the decryption password includes: Obtain the random number in the file header structure; Obtaining the encryption protection key according to the random number and the decryption password through a key derivation algorithm; The file header structure is decrypted according to the encryption protection key to obtain the encryption key.

6. The method for processing source files according to claim 1, wherein: Generating an encryption key according to the encryption password, including: Get the random number generated by the random algorithm; Generate an encryption protection key from the random number and the encryption password according to a key derivation algorithm; An encryption key is generated according to the encryption protection key and the random number.

7. A source file processing device, characterized in that: include: An acquisition module, configured to acquire an encrypted password input by a target object and generate an encryption key according to the encrypted password; An encryption module, configured to encrypt the target source file according to the encryption key; A writing module is used to write the encrypted target source file into the data storage area, and modify the directory table generated according to the encrypted target source file, wherein the directory table is at least used to indicate the storage address of the encrypted target source file in the data storage area, wherein the encryption module is further used to obtain the file header structure of the processing package of the source file, wherein the processing package of the source file is the file corresponding to the data storage area; fill the file header structure according to the random number and the encryption key, wherein the random number is used to generate an encryption protection key, and the encryption protection key is used to generate the encryption key, Among them, the writing module is also used to encrypt the filled file header structure and the filled directory table according to the encryption protection key, so as to at least encrypt the encryption key in the filled file header structure and encrypt the storage address in the directory table.

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.

Citation Information

Patent Citations

  • Method and device for preventing decompilation, computer equipment and storage medium

    CN113553553A

  • Login management method and system based on information encryption and medium

    CN115189875A