File fingerprint generation method and device, equipment and storage medium
Patent Information
- Application Number
- CN202310001267.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-03
- Publication Date
- 2026-09-11
- Estimated Expiration
- 2043-01-03
AI Technical Summary
[0005]本申请提供一种文件指纹生成方法、装置、设备及存储介质,用以解决安全性较低的问题
[0018] The file fingerprint generation method, apparatus, device, and storage medium provided in this application receive a file and a custom value, calculate a remainder based on the received custom value, and then calculate the file fingerprint of the received file using a hash operation rule corresponding to the remainder. Because a hash operation rule corresponding to the remainder is used, an unknown variable is added, making it difficult for external parties to crack or tamper with the file using the same hash operation rule, thus increasing the security of the file fingerprint.
Smart Images

Figure CN115964691B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer security technology, and in particular to a method, apparatus, device and storage medium for generating file fingerprints. Background Technology
[0002] With the continuous development of computer technology, computer security has increasingly become a key area of concern. In the field of computer security, ensuring the safety of downloaded files is a primary concern; if downloaded files are tampered with, it will seriously threaten computer security.
[0003] Currently, existing technologies typically use MD5 (Message Digest Algorithm MD5) to calculate file fingerprints during file upload and then calculate the file fingerprints again during file download. By comparing the two file fingerprints, it is determined whether the file has been tampered with.
[0004] However, the inventors have discovered that the existing technology has at least the following technical problems: the MD5 algorithm has been proven to be crackable, so the existing technology has a low security problem. Summary of the Invention
[0005] This application provides a method, apparatus, device, and storage medium for generating document fingerprints to address the problem of low security.
[0006] Firstly, this application provides a method for generating document fingerprints, including:
[0007] Receive files and custom values uploaded by users through terminal devices; divide the custom value by a preset standard value to obtain the remainder; based on the remainder, find the correspondence between the preset remainder and the hash operation rule to obtain the corresponding target hash operation rule; use the target hash operation rule to calculate the file fingerprint of the file.
[0008] In one possible implementation, a target hashing rule is used to calculate the file fingerprint of the file, including: obtaining the target hashing script corresponding to the target hashing rule; inputting the file into the target hashing script to obtain the file fingerprint of the file.
[0009] In one possible implementation, based on the remainder, a pre-defined correspondence between the remainder and the hash operation rule is found to obtain the corresponding target hash operation rule. This includes: based on the remainder, a pre-defined correspondence between the remainder and the initial secure hash algorithm, and a pre-defined correspondence between the remainder and the cyclic secure hash method, to obtain the corresponding target initial secure hash algorithm and target cyclic secure hash method respectively; based on the remainder, the number of iterations of the target cyclic secure hash method is determined; after performing the target initial secure hash algorithm operation a pre-defined number of times, the target cyclic secure hash method operation is performed for the specified number of iterations to determine the target hash operation rule.
[0010] In one possible implementation, the preset standard value includes a first preset standard value, a second preset standard value, and a third preset standard value; correspondingly, dividing the custom value by the preset standard value to obtain the remainder includes: dividing the custom value by the first preset standard value to obtain a first remainder; dividing the custom value by the second preset standard value to obtain a second remainder; and dividing the custom value by the third preset standard value to obtain a third remainder.
[0011] In one possible implementation, the correspondence between the remainder and the hash operation rule includes the correspondence between the remainder and the initial secure hash algorithm, and the correspondence between the remainder and the cyclic secure hash method. Accordingly, based on the remainder, a preset correspondence between the remainder and the hash operation rule is found to obtain the corresponding target hash operation rule, including: based on the first remainder, finding the correspondence between the remainder and the initial secure hash algorithm to obtain the target initial secure hash algorithm; based on the second remainder, finding the correspondence between the remainder and the cyclic secure hash method to obtain the target cyclic secure hash method; determining the third remainder as the number of iterations of the target cyclic secure hash method; and performing the target initial secure hash algorithm operation a preset number of times, followed by the target cyclic secure hash method operation a preset number of iterations, to determine the target hash operation rule.
[0012] In one possible implementation, the file fingerprint of a file is calculated using a target hashing algorithm, including: calculating a first fingerprint of the file using a target initial secure hashing algorithm; inputting the first fingerprint into a script corresponding to a target cyclic secure hashing algorithm to obtain a second fingerprint; decrementing the loop count by one to obtain a new loop count; inputting the second fingerprint into a script corresponding to a target cyclic secure hashing algorithm to obtain a new second fingerprint; overwriting the original second fingerprint with the new second fingerprint; decrementing the new loop count by one; repeating the steps of inputting the second fingerprint into the script corresponding to the target cyclic secure hashing algorithm to obtain a new second fingerprint until the new loop count is zero; and determining the new second fingerprint as the file fingerprint of the file.
[0013] In one possible implementation, before receiving the file and custom value uploaded by the user through the terminal device, the method further includes: receiving the file upload request sent by the user through the terminal device; and sending a value input prompt message to the terminal device based on the file upload request.
[0014] In one possible implementation, after calculating the file fingerprint of the file using the target hash operation rule, the method further includes: receiving a file download request and a verification value sent by the terminal device; obtaining the corresponding target file according to the file download request; performing the file fingerprint calculation steps using the target file and the verification value to obtain a verification fingerprint; sending the target file to the terminal device in response to the verification fingerprint being the same as the file fingerprint corresponding to the target file; and sending a file tampering prompt to the terminal device in response to the verification fingerprint being different from the file fingerprint corresponding to the target file.
[0015] Secondly, this application provides a file fingerprint generation device, comprising: a data receiving module for receiving a file and a custom value uploaded by a user through a terminal device; a remainder obtaining module for dividing the custom value by a preset standard value to obtain a remainder; a rule obtaining module for finding the correspondence between a preset remainder and a hash operation rule based on the remainder to obtain the corresponding target hash operation rule; and a fingerprint calculation module for calculating the file fingerprint of the file using the target hash operation rule.
[0016] Thirdly, this application provides an electronic device, including: a processor and a memory communicatively connected to the processor; the memory stores computer-executable instructions; the processor executes the computer-executable instructions stored in the memory, causing the processor to perform the file fingerprint generation method as described in the first aspect.
[0017] Fourthly, this application provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the file fingerprint generation method as described in the first aspect.
[0018] The file fingerprint generation method, apparatus, device, and storage medium provided in this application receive a file and a custom value, calculate a remainder based on the received custom value, and then calculate the file fingerprint of the received file using a hash operation rule corresponding to the remainder. Because a hash operation rule corresponding to the remainder is used, an unknown variable is added, making it difficult for external parties to crack or tamper with the file using the same hash operation rule, thus increasing the security of the file fingerprint. Attached Figure Description
[0019] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0020] Figure 1 This is a schematic diagram illustrating an application scenario of the document fingerprint generation method provided in the embodiments of this application;
[0021] Figure 2 A flowchart illustrating the document fingerprint generation method provided in this application embodiment;
[0022] Figure 3 This is a schematic diagram of the structure of the document fingerprint generation device provided in the embodiments of this application;
[0023] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0024] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation
[0025] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0026] Computers have become an important tool for information exchange, and various files can be stored on remote servers and databases via the network, then downloaded to local devices when needed. This file transfer method introduces new computer security risks; modifying files on the network can cause security problems for the computer that downloads the file.
[0027] Therefore, currently, MD5 is commonly used to calculate the file fingerprint of uploaded files. During file download, the terminal that receives the file calculates the file fingerprint again. If they match, it means the file has not been tampered with; if they do not match, it means the file has been tampered with. However, the MD5 algorithm can be cracked, so using MD5 to calculate file fingerprints has a relatively low security issue.
[0028] To address the aforementioned technical problems, the inventors propose the following technical concept: when a user uploads a file, a custom value is also uploaded simultaneously. The custom value is used to select a hashing rule, and the selected hashing rule is used to calculate the file fingerprint.
[0029] Figure 1 This is a schematic diagram illustrating an application scenario of the document fingerprint generation method provided in this application embodiment. For example... Figure 1 In this scenario, the components include: terminal device 101 and server 102.
[0030] Terminal device 101 may include computers, servers, tablets, mobile phones, PDAs (personal digital assistants), and laptops, which can input and send data.
[0031] Server 102 can be a standalone service, or it can be implemented using a single server or a cluster of multiple servers with more powerful processing capabilities and higher security. Where possible, it can also be replaced by a computer or laptop with strong computing power.
[0032] In the specific implementation process, the terminal device 101 is used to allow users to upload files and customize values.
[0033] Server 102 is used to obtain the hash operation rules corresponding to the custom values and to calculate the file fingerprint of the received file using the corresponding hash operation rules.
[0034] The connection between terminal device 101 and server 102 can be either a wired connection or a wireless network connection.
[0035] It is understood that the structure illustrated in the embodiments of this application does not constitute a specific limitation on the document fingerprint generation method. In other feasible embodiments of this application, the above architecture may include more or fewer components than illustrated, or combine some components, or split some components, or arrange different components, which can be determined according to the actual application scenario and is not limited here. Figure 1 The components shown can be implemented by hardware, software, or a combination of both.
[0036] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.
[0037] Figure 2 This is a flowchart illustrating the document fingerprint generation method provided in an embodiment of this application. The execution entity of this embodiment may be... Figure 1 The server 102 in this embodiment can also be a computer and / or a mobile phone, etc., and this embodiment does not impose any special restrictions on it. Figure 2 As shown, the method includes:
[0038] S201: Receive files and custom values uploaded by users through terminal devices.
[0039] In this step, the file can be a Docker (application container engine) file or other types of files, and the custom value can be a positive integer greater than the preset value.
[0040] Uploaded files may include software installation packages, compressed files, etc. Custom values may be used, such as 55, 57, 123, etc. This application embodiment does not limit the specific values of these custom values.
[0041] S202: Divide the custom value by the preset standard value and obtain the remainder.
[0042] In this step, the preset standard value can be pre-calibrated by the staff. There can be one or more preset standard values, and correspondingly, the number of remainders can be equal to the number of preset standard values.
[0043] S203: Based on the remainder, find the correspondence between the preset remainder and the hash operation rule to obtain the corresponding target hash operation rule.
[0044] In this step, the pre-defined correspondence between the remainder and the hashing rule can be stored in the form of a table, dictionary, or key-value pairs. The target hashing rule can be a single MD5, SHA-1 (Secure Hash Algorithm 1), SHA-256 (Secure Hash Algorithm 256), SHA-512 (Secure Hash Algorithm 512), SHA-384 (Secure Hash Algorithm 384), SHA-224 (Secure Hash Algorithm 224), etc. Alternatively, at least two of the above secure hashing algorithms can be arranged sequentially, with the output value of one secure hashing algorithm used as the input value of another, and the output value of the last secure hashing algorithm used as the output value of the hashing rule. Alternatively, at least one of the above-mentioned secure hash algorithms can be used to calculate the file fingerprint in a loop. This involves using the output value of the selected secure hash algorithm as the input value and looping it for a preset number of times or a remainder number of times to obtain the file fingerprint.
[0045] For example, if the target hash operation rule corresponding to the remainder is to use SHA-256 for file fingerprinting, then SHA-256 is used to calculate the file fingerprint of the received file. Another example is to use SHA-256 and SHA-512 as the remainders to calculate the file fingerprint, using the output value of SHA-256 as the input value of SHA-512, and the output value of SHA-512 as the file fingerprint. Yet another example is to perform SHA-1 alone to obtain a first file fingerprint, then input this first file fingerprint into an algorithm combination consisting of at least two of the above hash operations to obtain a second file fingerprint, which is then used as the file fingerprint of the received file. Alternatively, the second file fingerprint can be input into the algorithm combination again to obtain a new second file fingerprint, and this process can be repeated multiple times until the final second file fingerprint is determined as the file fingerprint of the received file.
[0046] S204: The file fingerprint of the file is calculated using the target hash operation rules.
[0047] In this step, the file can be input into a script or program corresponding to the target hash operation rule mentioned above to obtain the file fingerprint.
[0048] As described in the above embodiments, this application receives a file and a custom value, calculates a remainder based on the received custom value, and then uses the hash operation rule corresponding to the remainder to calculate the file fingerprint of the received file. Because the hash operation rule corresponding to the remainder is used, an unknown variable is added, making it difficult for external parties to crack or tamper with the file using the same hash operation rule, thus increasing the security of the file fingerprint.
[0049] In one possible implementation, step S204 above, which uses a target hashing rule to calculate the file fingerprint, specifically includes:
[0050] S204A1: Obtain the target hash operation script corresponding to the target hash operation rule.
[0051] In this step, the target hash operation script corresponding to the target hash operation rule can be read from a database or storage unit. There can be one or more target hash operation scripts corresponding to the target hash operation rule.
[0052] S204A2: Input the file into the target hashing script to obtain the file fingerprint.
[0053] In this step, a single target hashing script can be used to calculate the file fingerprint. Alternatively, a first target hashing script can be used to calculate the first file fingerprint, which is then input into a second target hashing script to obtain the second file fingerprint, and so on, with the output of the last target hashing script serving as the file fingerprint of the received file. Another option is to use a target hashing script to read the file and calculate the file fingerprint thereafter.
[0054] As can be seen from the description of the above embodiments, the embodiments of this application obtain the target hash operation script corresponding to the target hash operation rule, input the file into the target hash operation script, and obtain the file fingerprint of the file. This realizes the generation of file fingerprints using different scripts for different target hash operation rules, thereby increasing file security.
[0055] In one possible implementation, in step S203 above, based on the remainder, a preset correspondence between the remainder and the hash operation rule is found to obtain the corresponding target hash operation rule, including:
[0056] S203A1: Based on the remainder, find the preset correspondence between the remainder and the initial secure hash algorithm, and the preset correspondence between the remainder and the cyclic secure hash method, and obtain the corresponding target initial secure hash algorithm and target cyclic secure hash method respectively.
[0057] In this step, the correspondence between the remainder and the initial secure hash algorithm, and the correspondence between the remainder and the cyclic secure hash method, can be stored using any of the following: tables, dictionaries, or key-value pairs. These can be pre-set by the staff. The target cyclic secure hash method can be at least one of the aforementioned secure hash algorithms used cyclically.
[0058] Among them, the target cyclic secure hashing method, such as SHA-512, or after calculating the file fingerprint using SHA-512, the calculated file fingerprint is input into SHA-256, that is, combining SHA-512 and SHA-256, or the file fingerprint of the file can be calculated by cyclically using SHA-512 and SHA-256 in the above manner. During the loop, the output of SHA-256 can be used as the input of SHA-512 for the loop.
[0059] S203A2: Determine the number of cycles for the target cyclic secure hash method based on the remainder.
[0060] In this step, the remainder value can be determined as the number of iterations, or the remainder can be input into a preset formula to obtain the number of iterations.
[0061] The preset formula is as follows:
[0062] T = aX + b
[0063] In the formula, T represents the number of cycles, X represents the remainder, and a and b represent constants.
[0064] S203A3: After performing a preset number of target initial secure hash algorithm operations, a target cyclic secure hash method operation is performed for a specified number of iterations, which is determined as the target hash operation rule.
[0065] In this step, the preset number of times can be once or a pre-defined number of times. The target cyclic secure hashing method can include one secure hashing algorithm or at least two secure hashing algorithms.
[0066] The initial secure hash algorithm operation, performed a preset number of times, can be achieved by using the output of the initial secure hash algorithm as the input value and performing the operation again, for a total of the preset number of operations. If the target cyclic secure hashing method includes at least two secure hash algorithms, these algorithms can be arranged in a preset order, with the output of the first secure hash algorithm used as the input of the second, and so on, until the output of the last secure hash algorithm is used as the input of the first, thus performing a cyclic operation.
[0067] As can be seen from the description of the above embodiments, the embodiments of this application obtain the target initial secure hash algorithm and the target cyclic secure hash method corresponding to the remainder by searching for a preset correspondence based on the remainder, and then use the number of cycles corresponding to the remainder to perform the operation of the target cyclic secure hash method. The target hash operation rule becomes to perform the target initial secure hash algorithm operation a preset number of times, and then perform the target cyclic secure hash method operation a certain number of cycles, thereby realizing a more complex file fingerprint calculation, thus making the file more secure.
[0068] In one possible implementation, the preset standard value in the above embodiments includes a first preset standard value, a second preset standard value, and a third preset standard value.
[0069] The first, second, and third preset standard values can be pre-defined by staff or server maintenance personnel.
[0070] Accordingly, in step S202 above, dividing the custom value by a preset standard value to obtain the remainder specifically includes:
[0071] S2021: Divide the custom value by the first preset standard value to obtain the first remainder.
[0072] In this step, the custom value can be greater than the first preset standard value, the second preset standard value, and the third preset standard value. Alternatively, this step can use a modulo function to calculate the first remainder, using the custom value as the dividend of the modulo function and the remainder as the divisor.
[0073] S2022: Divide the custom value by the second preset standard value to obtain the second remainder.
[0074] This step is similar to step S2021 above, and will not be repeated here.
[0075] S2023: Divide the custom value by the third preset standard value to obtain the third remainder.
[0076] This step is similar to step S2021 above, and will not be repeated here.
[0077] As can be seen from the description of the above embodiments, the embodiments of this application generate different remainders by taking the remainders of the custom values with different preset standard values, which increases the complexity of the processing and thus increases the difficulty of cracking the file fingerprint.
[0078] In one possible implementation, the correspondence between the remainder and the hashing rules includes the correspondence between the remainder and the initial secure hashing algorithm, and the correspondence between the remainder and the cyclic secure hashing method.
[0079] Accordingly, in step S203 above, based on the remainder, the corresponding relationship between the preset remainder and the hash operation rule is found to obtain the corresponding target hash operation rule, specifically including:
[0080] S203B1: Based on the first remainder, find the correspondence between the remainder and the initial secure hash algorithm to obtain the target initial secure hash algorithm.
[0081] In this step, the correspondence between the remainder and the initial secure hash algorithm is similar to that in step S203A1 above, and will not be repeated here.
[0082] S203B2: Based on the second remainder, find the correspondence between the remainder and the cyclic secure hash method to obtain the target cyclic secure hash method.
[0083] In this step, the correspondence between the remainder and the circular secure hashing method is similar to that in step S203A1 above, and will not be repeated here.
[0084] S203B3: Determine the third remainder as the number of cycles for the target cyclic secure hashing method.
[0085] In this step, for example, if the third remainder is 7, the loop will run 7 times. If the third remainder is 9, the loop will run 9 times. And if the third remainder is 2, the loop will run 2 times.
[0086] S203B4: After performing a preset number of target initial secure hash algorithm operations, a target cyclic secure hash method operation is performed for a specified number of iterations, which is determined as the target hash operation rule.
[0087] This step is similar to step S203A3 above, and will not be repeated here.
[0088] As can be seen from the description of the above embodiments, the embodiments of this application increase the computational complexity of file fingerprints by finding the target initial secure hash algorithm corresponding to the first preset standard value, the target cyclic secure hash method corresponding to the second preset standard value, and determining the third remainder as the number of cycles of the target cyclic secure hash method. The target initial secure hash algorithm, the target cyclic secure hash method, and the number of cycles are combined to form the target hash operation rule, thereby increasing the security of the file.
[0089] In one possible implementation, step S204 above, which uses a target hashing rule to calculate the file fingerprint of the file, includes:
[0090] S204B1: Calculate the first fingerprint of the file using the target initial secure hash algorithm.
[0091] In this step, the received file can be input into the target's initial secure hash algorithm to obtain the first fingerprint.
[0092] S204B2: Input the first fingerprint into the script corresponding to the target cyclic secure hash method to obtain the second fingerprint.
[0093] In this step, if the target cyclic secure hashing method corresponds to only one secure hashing algorithm, then a script is used to calculate the file fingerprint to obtain the second fingerprint. If the target cyclic secure hashing method corresponds to at least two secure hashing algorithms, then the number of scripts can be one, or the same as the number of secure hashing algorithms.
[0094] For example, a target circular secure hash method might involve calculating a SHA-256 hash, then inputting the SHA-256 result into SHA-512, with the SHA-512 output being the second fingerprint. SHA-256 and SHA-512 can be calculated using separate scripts, or their calculations can be performed using a single script. Alternatively, a target circular secure hash method might involve calculating a SHA-1 hash, inputting the result into SHA-256, and inputting the SHA-256 output into SHA-512. In this case, a single script could be used to calculate SHA-1, SHA-256, and SHA-512, or different scripts could be used for each hash.
[0095] S204B3: Decrease the number of iterations by one to get the new number of iterations.
[0096] In this step, for example, if the original number of iterations was 7, then the new number of iterations will be 6. Or, for example, if the original number of iterations was 3, then the new number of iterations will be 2.
[0097] S204B4: Input the second fingerprint into the script corresponding to the target cyclic secure hash method to obtain a new second fingerprint.
[0098] In this step, the output value of the target cyclic secure hash method is used as the input value of the target cyclic secure hash method, and the target cyclic secure hash method is used to calculate again to obtain a new second fingerprint.
[0099] S204B5: Overwrite the existing second fingerprint with a new second fingerprint.
[0100] In this step, the original second fingerprint may be deleted and a new second fingerprint may be written.
[0101] S204B6: Decrease the new loop count by one.
[0102] This step is similar to step S204B3 above, and will not be repeated here.
[0103] S204B7: Repeat the steps of inputting the second fingerprint into the target cyclic secure hash method to obtain a new second fingerprint and decrementing the new cycle count by one, until the new cycle count is zero.
[0104] In this step, steps S204B4 to S204B6 can be repeated to update the second fingerprint until the number of cycles is 0.
[0105] S204B8: The new second fingerprint is identified as the file fingerprint of the document.
[0106] In this step, the final obtained second fingerprint can be identified as the file fingerprint of the file.
[0107] For example, if the final file fingerprint is "j2hFsGd87o", then "j2hFsGd87o" is determined as the file fingerprint of the received file.
[0108] As can be seen from the description of the above embodiments, the embodiments of this application calculate the first fingerprint of the file by using the target initial secure hash algorithm, calculate the second fingerprint of the first fingerprint by using the script corresponding to the target cyclic secure hash method, and update the second fingerprint by cyclically using the target cyclic secure hash method until the number of cycles is reduced to 0, and determine the second fingerprint as the file fingerprint, thereby achieving the effect of increasing the complexity of the file fingerprint calculation method and increasing the security of the file fingerprint.
[0109] In one possible implementation, before receiving the file and custom value uploaded by the user through the terminal device in step S201 above, the method further includes:
[0110] S210: Receive file upload requests sent by users through terminal devices.
[0111] In this step, a preset command may be received from the terminal device. The file upload request may be triggered by a user pressing a button or module in a webpage or client.
[0112] S211 sends a numerical input prompt to the terminal device based on the file upload request.
[0113] In this step, the numerical input prompt message is displayed, such as "Please enter an integer greater than 40", "Please enter an integer greater than 10", or "Please enter an integer greater than the displayed value". The numerical value in the prompt message can be the largest value among the first preset standard value, the second preset standard value, and the third preset standard value, or it can be a value greater than any of the first preset standard value, the second preset standard value, and the third preset standard value. When there is only one preset standard value, the numerical value in the prompt message can be greater than that preset standard value.
[0114] As can be seen from the description of the above embodiments, the embodiments of this application send a prompt message to the terminal device when the user uploads a file on the terminal device, so that the user can input an appropriate value to facilitate the subsequent calculation of the remainder.
[0115] In one possible implementation, after calculating the file fingerprint of the file using the target hash operation rule in step S204, the method further includes:
[0116] S205: Receive file download request and verification value sent by terminal device.
[0117] In this step, the file download request can be sent by the user triggering the file download button on their terminal device, or it can be a value corresponding to a specific file. The verification value can be entered by the user, a value stored by the user corresponding to a file, or a custom value entered when uploading the file.
[0118] For example, if a user enters the number "88" when uploading file A, then the user should also enter the number "88" when downloading file A. This application does not impose specific restrictions on the numbers entered by the user.
[0119] S206: Obtain the corresponding target file based on the file download request.
[0120] In this step, the corresponding target file can be found based on the file download request and then read. The target file can be stored in a storage unit or a database.
[0121] S207: Using the target file and verification values, perform the file fingerprint calculation steps to obtain the verification fingerprint.
[0122] In this step, the file fingerprint calculation step can be steps S202 to S204 described above, and its specific implementation is as described in the above embodiments. It can involve replacing the file in step S204 with the target file, replacing the custom value in step S202 with the verification value, calculating the file fingerprint, and obtaining the verification fingerprint.
[0123] S208: In response to the verification that the fingerprint matches the file fingerprint corresponding to the target file, the target file is sent to the terminal device.
[0124] In this step, a preset script or program can be used to compare and verify the fingerprint with the file fingerprint, obtaining results that are the same or different. The file can be sent via the internet, via wired connection, or via wireless connection.
[0125] S209: In response to the fact that the verification fingerprint is different from the file fingerprint corresponding to the target file, a file tampering prompt is sent to the terminal device.
[0126] In this step, the process of comparing and verifying the fingerprint with the document fingerprint is similar to step S208 above. The message indicating that the document has been tampered with may include phrases such as "The document has been tampered with," "The document has been modified," or "The document is different from the original document; please check."
[0127] As can be seen from the description of the above embodiments, the embodiments of this application obtain the target file corresponding to the file download request by receiving a file download request and a verification value, and use the target file and the verification value to perform a file fingerprint calculation step to obtain a verification fingerprint. If the verification fingerprint is the same as the file fingerprint corresponding to the target file, the target file is sent to the terminal device. If the verification fingerprint is different from the file fingerprint corresponding to the target file, a file tampering prompt is sent to the terminal device, thereby realizing verification during file download. When the file is tampered with, it can detect that the file to be transmitted is different from the original uploaded file.
[0128] In one possible implementation, a file and a custom value A uploaded by the user via a terminal device are received. A is then moduloed by 3, 3, and 50, yielding three remainders B, C, and D. When B is 0, a SHA-1 hash is performed on the file; when B is 1, a SHA-256 hash is performed; and when B is 2, a SHA-512 hash is performed. The result of B is input into the composite hash rule corresponding to C. When C is 0, only the SHA-1 hash is performed; when C is 1, SHA-1 and SHA-256 hashes are performed sequentially; and when C is 2, SHA-1, SHA-256, and SHA-512 hashes are performed sequentially. The composite hash rule corresponding to C is then iterated D times to complete the final Docker file fingerprint calculation.
[0129] In the above embodiments, scripts, software, and programs can be substituted for each other.
[0130] Figure 3 This is a schematic diagram of the structure of a document fingerprint generation device provided in an embodiment of this application. Figure 3 As shown, the document fingerprint generation device 300 includes: a data receiving module 301, a remainder acquisition module 302, a rule acquisition module 303, and a fingerprint calculation module 304.
[0131] The data receiving module 301 is used to receive files and custom values uploaded by users through terminal devices.
[0132] The remainder acquisition module 302 is used to divide a custom value by a preset standard value to obtain the remainder.
[0133] The rule acquisition module 303 is used to find the correspondence between the preset remainder and the hash operation rule based on the remainder, and obtain the corresponding target hash operation rule.
[0134] The fingerprint calculation module 304 is used to calculate the file fingerprint of a file using the target hash operation rules.
[0135] The apparatus provided in this embodiment can be used to execute the technical solutions of the above method embodiments. Its implementation principle and technical effects are similar, and will not be described again here.
[0136] In one possible implementation, the fingerprint calculation module 304 is specifically used to obtain the target hash operation script corresponding to the target hash operation rule. The file is input into the target hash operation script to obtain the file fingerprint.
[0137] The apparatus provided in this embodiment can be used to execute the technical solutions of the above method embodiments. Its implementation principle and technical effects are similar, and will not be described again here.
[0138] In one possible implementation, the rule acquisition module 303 is specifically used to find, based on the remainder, a preset correspondence between the remainder and the initial secure hash algorithm, and a preset correspondence between the remainder and the cyclic secure hash method, respectively obtaining the corresponding target initial secure hash algorithm and target cyclic secure hash method. Based on the remainder, the number of iterations for the target cyclic secure hash method is determined. After performing the target initial secure hash algorithm operation a preset number of times, the target cyclic secure hash method operation is then performed for the specified number of iterations, thus determining the target hash operation rule.
[0139] The apparatus provided in this embodiment can be used to execute the technical solutions of the above method embodiments. Its implementation principle and technical effects are similar, and will not be described again here.
[0140] In one possible implementation, the preset standard values include a first preset standard value, a second preset standard value, and a third preset standard value. The remainder acquisition module 302 is specifically used to divide the custom value by the first preset standard value to obtain a first remainder; divide the custom value by the second preset standard value to obtain a second remainder; and divide the custom value by the third preset standard value to obtain a third remainder.
[0141] The apparatus provided in this embodiment can be used to execute the technical solutions of the above method embodiments. Its implementation principle and technical effects are similar, and will not be described again here.
[0142] In one possible implementation, the correspondence between the remainder and the hash operation rules includes the correspondence between the remainder and the initial secure hash algorithm, and the correspondence between the remainder and the cyclic secure hash method. The rule acquisition module 303 is specifically used to find the correspondence between the remainder and the initial secure hash algorithm based on the first remainder, thus obtaining the target initial secure hash algorithm. Based on the second remainder, it finds the correspondence between the remainder and the cyclic secure hash method, thus obtaining the target cyclic secure hash method. The third remainder is determined as the number of iterations for the target cyclic secure hash method. After performing a preset number of target initial secure hash algorithm operations, the target cyclic secure hash method is then performed for the specified number of iterations, thus determining the target hash operation rule.
[0143] The apparatus provided in this embodiment can be used to execute the technical solutions of the above method embodiments. Its implementation principle and technical effects are similar, and will not be described again here.
[0144] In one possible implementation, the rule acquisition module 303 is specifically used to calculate the first fingerprint of the file using the target initial secure hash algorithm. The first fingerprint is input into the script corresponding to the target cyclic secure hash method to obtain the second fingerprint. The loop count is decremented by one to obtain a new loop count. The second fingerprint is input into the script corresponding to the target cyclic secure hash method to obtain a new second fingerprint. The new second fingerprint overwrites the original second fingerprint. The new loop count is decremented by one. The steps of inputting the second fingerprint into the script corresponding to the target cyclic secure hash method, obtaining the new second fingerprint, and decrementing the new loop count are repeated until the new loop count is zero. The new second fingerprint is then determined as the file fingerprint of the file.
[0145] The apparatus provided in this embodiment can be used to execute the technical solutions of the above method embodiments. Its implementation principle and technical effects are similar, and will not be described again here.
[0146] In one possible implementation, the document fingerprint generation device 300 further includes a prompt sending module 305.
[0147] The prompt sending module 305 is used to receive file upload requests sent by users through terminal devices. Based on the file upload request, it sends numerical input prompt information to the terminal device.
[0148] The apparatus provided in this embodiment can be used to execute the technical solutions of the above method embodiments. Its implementation principle and technical effects are similar, and will not be described again here.
[0149] In one possible implementation, the document fingerprint generation device 300 further includes a document verification module 306.
[0150] The file verification module 306 is specifically used to receive a file download request and a verification value sent by the terminal device. Based on the file download request, it obtains the corresponding target file. Using the target file and the verification value, it performs a file fingerprint calculation to obtain a verification fingerprint. If the verification fingerprint matches the file fingerprint corresponding to the target file, it sends the target file to the terminal device. If the verification fingerprint differs from the file fingerprint corresponding to the target file, it sends a file tampering notification to the terminal device.
[0151] The apparatus provided in this embodiment can be used to execute the technical solutions of the above method embodiments. Its implementation principle and technical effects are similar, and will not be described again here.
[0152] To implement the above embodiments, this application also provides an electronic device.
[0153] refer to Figure 4 The diagram illustrates a structural schematic of an electronic device 400 suitable for implementing embodiments of this application. The electronic device 400 can be a terminal device or a server. The terminal device can include, but is not limited to, mobile terminals such as mobile phones, laptops, digital radio receivers, personal digital assistants (PDAs), portable Android devices (PADs), portable media players (PMPs), and in-vehicle terminals (e.g., in-vehicle navigation terminals), as well as fixed terminals such as digital TVs and desktop computers. Figure 4 The electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.
[0154] like Figure 4 As shown, the electronic device 400 may include a processor (e.g., a central processing unit, a graphics processing unit, etc.) 401 and a memory 402 communicatively connected to the processor. The memory 402 can perform various appropriate actions and processes based on programs stored in the read-only memory (ROM) 402, computer-executed instructions, or programs loaded from storage device 408 into random access memory (RAM) 403, to implement the file fingerprint generation method in any of the above embodiments. The RAM 403 also stores various programs and data required for the operation of the electronic device 400. The processing device 401, ROM 402, and RAM 403 are interconnected via a bus 404. An input / output (I / O) interface 405 is also connected to the bus 404.
[0155] Typically, the following devices can be connected to I / O interface 405: input devices 406 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 407 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 408 including, for example, magnetic tapes, hard disks, etc.; and communication devices 409. Communication device 409 allows electronic device 400 to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 4 An electronic device 400 with various devices is shown; however, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively.
[0156] Specifically, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program carried on a computer-readable storage medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication device 409, or installed from storage device 408, or installed from ROM 402. When the computer program is executed by processing device 401, it performs the functions defined in the methods of embodiments of this application.
[0157] It should be noted that the computer-readable storage medium described above in this application can be a computer-readable signal medium or a computer storage medium, or any combination of the two. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this application, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable storage medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable storage medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.
[0158] The aforementioned computer-readable storage medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device.
[0159] The aforementioned computer-readable storage medium carries one or more programs, which, when executed by the electronic device, cause the electronic device to perform the method shown in the above embodiments.
[0160] Computer program code for performing the operations of this application can be written in one or more programming languages or a combination thereof. These programming languages include object-oriented programming languages—such as Java, Smalltalk, and C++—and conventional procedural programming languages—such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a Local Area Network (LAN) or a Wide Area Network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0161] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0162] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the units do not necessarily limit the module itself; for example, the rule acquisition module can also be described as a "target hash operation rule acquisition module".
[0163] The functions described above in this document can be performed, at least in part, by one or more hardware logic components. For example, exemplary types of hardware logic components that can be used, without limitation, include: Field Programmable Gate Arrays (FPGAs), Application-Specific Integrated Circuits (ASICs), Application Standard Products (ASSPs), System-on-Chip (SoCs), Complex Programmable Logic Devices (CPLDs), and so on.
[0164] This application also provides a computer-readable storage medium storing computer-executable instructions. When a processor executes the computer-executable instructions, it implements the technical solution of the file fingerprint generation method in any of the above embodiments. Its implementation principle and beneficial effects are similar to those of the file fingerprint generation method. Please refer to the implementation principle and beneficial effects of the file fingerprint generation method. It will not be repeated here.
[0165] In the context of this application, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. Machine-readable media can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0166] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the technical solution of the file fingerprint generation method in any of the above embodiments. Its implementation principle and beneficial effects are similar to those of the file fingerprint generation method, and can be found in the implementation principle and beneficial effects of the file fingerprint generation method, which will not be repeated here.
[0167] The above description is merely a preferred embodiment of this application and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of disclosure in this application is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features with similar functions disclosed in this application.
[0168] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the following claims.
[0169] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.
Claims
1. A method for generating a file fingerprint, characterized in that, include: Receive files and custom values uploaded by users via their terminal devices; Divide the custom value by the preset standard value to obtain the remainder; Based on the remainder, find the correspondence between the preset remainder and the hash operation rule to obtain the corresponding target hash operation rule; The file fingerprint of the file is calculated using the target hash operation rule. The step of finding the correspondence between the preset remainder and the hash operation rule based on the remainder to obtain the corresponding target hash operation rule includes: Based on the remainder, find the preset correspondence between the remainder and the initial secure hash algorithm, and the preset correspondence between the remainder and the cyclic secure hash method, and obtain the corresponding target initial secure hash algorithm and target cyclic secure hash method respectively. Based on the remainder, determine the number of cycles for the target cyclic secure hash method; After performing the target initial secure hash algorithm operation a preset number of times, the target cyclic secure hash method operation is performed a specified number of times to determine the target hash operation rule.
2. The method according to claim 1, characterized in that, The step of calculating the file fingerprint of the file using the target hash operation rule includes: Obtain the target hash operation script corresponding to the target hash operation rule; The file is input into the target hashing script to obtain the file fingerprint.
3. The method according to claim 1, characterized in that, The preset standard values include a first preset standard value, a second preset standard value, and a third preset standard value; Accordingly, dividing the custom value by a preset standard value to obtain the remainder includes: Divide the custom value by the first preset standard value to obtain the first remainder; Divide the custom value by the second preset standard value to obtain the second remainder; Divide the custom value by the third preset standard value to obtain the third remainder.
4. The method according to claim 3, characterized in that, The correspondence between the remainder and the hash operation rules includes the correspondence between the remainder and the initial secure hash algorithm, and the correspondence between the remainder and the cyclic secure hash method. Accordingly, the step of finding the correspondence between the preset remainder and the hash operation rule based on the remainder to obtain the corresponding target hash operation rule includes: Based on the first remainder, find the correspondence between the remainder and the initial secure hash algorithm to obtain the target initial secure hash algorithm; Based on the second remainder, find the correspondence between the remainder and the cyclic secure hash method to obtain the target cyclic secure hash method; The third remainder is determined as the number of cycles for the target cyclic secure hash method; After performing the target initial secure hash algorithm operation a preset number of times, the target cyclic secure hash method operation is performed a specified number of times to determine the target hash operation rule.
5. The method according to claim 4, characterized in that, The step of calculating the file fingerprint of the file using the target hash operation rule includes: The first fingerprint of the file is calculated using the target initial secure hash algorithm; The first fingerprint is input into the script corresponding to the target cyclic secure hash method to obtain the second fingerprint; Subtract one from the previous number of iterations to get the new number of iterations; The second fingerprint is input into the script corresponding to the target cyclic secure hash method to obtain a new second fingerprint; The new second fingerprint covers the original second fingerprint; Decrease the new loop count by one; Repeat the steps of inputting the second fingerprint into the script corresponding to the target cyclic secure hash method to obtain a new second fingerprint, until the new cycle count is decremented by one, until the new cycle count is zero. The new second fingerprint is identified as the file fingerprint of the document.
6. The method according to any one of claims 1 to 5, characterized in that, Before receiving the file and custom value uploaded by the user through the terminal device, the method further includes: Receive file upload requests sent by users via their terminal devices; Based on the file upload request, a numerical input prompt message is sent to the terminal device.
7. The method according to any one of claims 1 to 5, characterized in that, After calculating the file fingerprint of the file using the target hash operation rule, the method further includes: Receive the file download request and verification value sent by the terminal device; Based on the file download request, obtain the corresponding target file; Using the target file and the verification value, perform the file fingerprint calculation step to obtain the verification fingerprint; In response to the verification fingerprint being identical to the file fingerprint corresponding to the target file, the target file is sent to the terminal device; In response to the fact that the verification fingerprint is different from the file fingerprint corresponding to the target file, a file tampering prompt is sent to the terminal device.
8. A document fingerprint generation device, characterized in that, include: The data receiving module is used to receive files and custom values uploaded by users through their terminal devices; The remainder acquisition module is used to divide the custom value by a preset standard value to obtain the remainder; The rule acquisition module is used to find the correspondence between the preset remainder and the hash operation rule based on the remainder, and obtain the corresponding target hash operation rule; The fingerprint calculation module is used to calculate the file fingerprint of the file using the target hash operation rules; The rule acquisition module is specifically used to find the correspondence between the preset remainder and the initial secure hash algorithm and the preset remainder and the cyclic secure hash method based on the remainder, so as to obtain the corresponding target initial secure hash algorithm and target cyclic secure hash method respectively. Based on the remainder, determine the number of cycles for the target cyclic secure hash method; After performing the target initial secure hash algorithm operation a preset number of times, the target cyclic secure hash method operation is performed a specified number of times to determine the target hash operation rule.
9. An electronic device, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory, causing the processor to perform the file fingerprint generation method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the file fingerprint generation method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Configuration file processing method and device, equipment and storage medium
CN117472470A