A file encryption and decryption method, device and medium

CN117675250BActive Publication Date: 2026-10-16HISENSE GRP HLDG CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202211056245.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-31
Publication Date
2026-10-16
Estimated Expiration
2042-08-31

AI Technical Summary

Technical Problem

[0004]本申请提供了一种文件加、解密方法、设备及介质,用以解决现有技术中的加密方法很容易被定位到加密位置,加密安全性低的问题

Benefits of technology

[0015] In this embodiment, a target file to be encrypted and a pre-configured first target value are obtained. The first target value includes at least one sub-target value. Encryption information corresponding to the stored sub-target values ​​is obtained, and an encryption information group is determined. This encryption information is either an encryption position or an encryption byte length. The encryption information group includes an encryption position and an encryption byte length. Based on the encryption position carried in the encryption information group, the target position corresponding to the encryption position in the target file is determined. Based on the target position, the file content of the encryption byte length is obtained and encrypted. Since this embodiment uses an encryption information group obtained based on the first target value, which includes an encryption position and an encryption byte length, to determine the file content corresponding to the encryption position in the target file before encrypting it, the method of selecting a fixed position for file encryption is avoided, thus improving the security of file encryption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117675250B_ABST
    Figure CN117675250B_ABST
Patent Text Reader

Abstract

The application provides a file encryption and decryption method, device and medium, comprising: obtaining a target file to be encrypted and a pre-configured first target value, the first target value comprising at least one sub-target value, obtaining saved encryption information corresponding to the sub-target value, determining an encryption information group, wherein the encryption information is an encryption position or an encryption byte length, determining a target position in the target file corresponding to the encryption position according to the encryption position carried in the encryption information group, obtaining file content with the encryption byte length according to the target position, and encrypting the file content. In the embodiment of the application, the encryption information group is obtained based on the first target value, the encryption information group contains the encryption position and the encryption byte length, the file content corresponding to the encryption position in the target file to be encrypted is determined, and then the file content is encrypted, thereby avoiding selecting a fixed position to encrypt the file and improving the security of file encryption.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of information security technology, and in particular to a method, device and medium for encrypting and decrypting files. Background Technology

[0002] In today's society, with the rapid development of science and technology and the era of big data, the ways in which data is generated and acquired are becoming more and more diverse. Various electronic devices and software can easily collect files stored on electronic devices. In order to protect files from being damaged, altered, or leaked due to accidental or malicious reasons, encrypting files has become particularly important.

[0003] Currently, there are various methods for file encryption, the most common being encryption using specific bytes, such as encrypting file digests using various algorithms. However, this method has low security; attackers can easily determine the encryption location and then crack the encrypted file. Summary of the Invention

[0004] This application provides a file encryption and decryption method, device, and medium to solve the problem that encryption methods in the prior art are easily located at the encryption position and have low encryption security.

[0005] In a first aspect, embodiments of this application provide a file encryption method, the method comprising:

[0006] Obtain the target file to be encrypted and a pre-configured first target value, wherein the first target value includes at least one sub-target value;

[0007] Obtain the encrypted information corresponding to the saved sub-target value, and determine the encrypted information group, wherein the encrypted information is an encrypted position or an encrypted byte length, and the encrypted information group includes an encrypted position and an encrypted byte length;

[0008] Based on the encryption location carried in the encryption information group, the target location corresponding to the encryption location in the target file is determined. Based on the target location, the file content of the encryption byte length is obtained, and the file content is encrypted.

[0009] Secondly, embodiments of this application also provide a file decryption method, the method comprising:

[0010] Obtain the target file to be decrypted and a pre-configured first target value, wherein the first target value includes at least one sub-target value;

[0011] Obtain the decryption information corresponding to the saved subtarget value, and determine the decryption information group, wherein the decryption information is a decryption position or a decryption byte length, and the decryption information group includes a decryption position and a decryption byte length;

[0012] Based on the decryption location carried in the decryption information group, determine the target location corresponding to the decryption location in the target file, obtain the file content of the decryption byte length based on the target location, and decrypt the file content.

[0013] Thirdly, embodiments of this application also provide an electronic device, the electronic device including a processor, the processor being configured to execute a computer program stored in a memory to implement the steps of the file encryption method or the file decryption method described above.

[0014] Fourthly, embodiments of this application also provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of any of the encryption methods or file decryption methods described above.

[0015] In this embodiment, a target file to be encrypted and a pre-configured first target value are obtained. The first target value includes at least one sub-target value. Encryption information corresponding to the stored sub-target values ​​is obtained, and an encryption information group is determined. This encryption information is either an encryption position or an encryption byte length. The encryption information group includes an encryption position and an encryption byte length. Based on the encryption position carried in the encryption information group, the target position corresponding to the encryption position in the target file is determined. Based on the target position, the file content of the encryption byte length is obtained and encrypted. Since this embodiment uses an encryption information group obtained based on the first target value, which includes an encryption position and an encryption byte length, to determine the file content corresponding to the encryption position in the target file before encrypting it, the method of selecting a fixed position for file encryption is avoided, thus improving the security of file encryption. Attached Figure Description

[0016] To more clearly illustrate the technical solutions of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0017] Figure 1 A schematic diagram of a file encryption process provided in an embodiment of this application;

[0018] Figure 2This is a schematic diagram of the elliptic curve corresponding to the first target ellipse equation provided in the embodiments of this application;

[0019] Figure 3 This is a schematic diagram of the elliptic curve corresponding to the second target ellipse equation provided in the embodiments of this application;

[0020] Figure 4 A schematic diagram of the elliptic curve corresponding to the third target ellipse equation provided in the embodiments of this application;

[0021] Figure 5 This is a schematic diagram of the elliptic curve corresponding to the fourth target ellipse equation provided in the embodiments of this application;

[0022] Figure 6 A schematic diagram illustrating the correspondence between the first target value and the content of the file to be encrypted, as provided in this application embodiment;

[0023] Figure 7 A schematic diagram illustrating the file encryption process provided in this application embodiment;

[0024] Figure 8 A schematic diagram of a file decryption process provided in an embodiment of this application;

[0025] Figure 9 This is a schematic diagram of a file encryption device provided in an embodiment of this application;

[0026] Figure 10 This is a schematic diagram of a file decryption device provided in an embodiment of this application;

[0027] Figure 11 This is a schematic diagram of an electronic device structure provided in an embodiment of this application. Detailed Implementation

[0028] To make the objectives, technical solutions, and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0029] To improve the security of file encryption, this application provides a file encryption and decryption method, device, and medium.

[0030] In this embodiment, the electronic device obtains a target file to be encrypted and a pre-configured first target value, wherein the first target value includes at least one sub-target value. It obtains the encryption information corresponding to the stored sub-target value, determines an encryption information group, wherein the encryption information is an encryption position or an encryption byte length. The encryption information group includes an encryption position and an encryption byte length. Based on the encryption position carried in the encryption information group, it determines the target position corresponding to the encryption position in the target file. Based on the target position, it obtains the file content of the encryption byte length and encrypts the file content.

[0031] Figure 1 This application provides a schematic diagram of a file encryption process, which includes:

[0032] S101: Obtain the target file to be encrypted and a pre-configured first target value, wherein the first target value includes at least one sub-target value.

[0033] The file encryption method provided in this application is applied to an electronic device, which may be a server, terminal, or PC.

[0034] In this embodiment of the application, the electronic device receives an encryption request input by the user, wherein the encryption request carries identification information of the target file to be encrypted, and the electronic device determines and obtains the target file based on the identification information.

[0035] Furthermore, in order to avoid encrypting the file content in the regular location of the target file, in this embodiment of the application, the electronic device stores a pre-configured first target value, and the electronic device can determine the file content of the target file to be encrypted based on the first target value.

[0036] Specifically, in this embodiment, the first target value includes at least one sub-target value, which can be used to determine the encrypted byte length of the target file. Furthermore, in this embodiment, to further improve the security of file encryption, the first target value used when encrypting each file can be different. For example, the electronic device can store the correspondence between file identification information and the first target value. Each file with different identification information corresponds to a different first target value. The electronic device can determine the first target value of the target file based on the identification information corresponding to the target file and this correspondence.

[0037] S102: Obtain the encrypted information corresponding to the saved sub-target value, and determine the encrypted information group, wherein the encrypted information is an encrypted position or an encrypted byte length, and the encrypted information group includes an encrypted position and an encrypted byte length.

[0038] In this embodiment, each sub-target value that makes up the first target value represents an encrypted information, and the encrypted information represented by each sub-target value can be configured together with the first target value in the electronic device. The encrypted information is either an encrypted position or an encrypted byte length.

[0039] Specifically, in this embodiment of the application, after obtaining a pre-configured first target value, the electronic device obtains the encryption information corresponding to each sub-target value, and determines an encryption information group based on the different encryption information. It should be noted that an encryption information group includes at least one encryption position and one encryption byte length.

[0040] Specifically, in this embodiment, at least one sub-target value constitutes a first target value. Based on this, when pre-configuring the encryption information corresponding to each sub-target value of the first target value, the encryption information of two adjacent sub-target values ​​is different. When determining the encryption information group, the electronic device can determine the encryption information corresponding to two adjacent sub-target values ​​as an encryption information group.

[0041] S103: Based on the encryption location carried in the encryption information group, determine the target location corresponding to the encryption location in the target file, obtain the file content of the encryption byte length based on the target location, and encrypt the file content.

[0042] In this embodiment of the application, for each encrypted information group that has been determined, the encrypted position contained in the encrypted information group is determined. The electronic device can find the target position corresponding to the encrypted position in the target file according to the encrypted position, and obtain the file content of the encrypted byte length starting from the target position. The file content is determined as the file content to be encrypted in the target file, and the file content is encrypted.

[0043] In this application, both the sub-target value representing the encrypted location and the sub-target value representing the length of the encrypted bytes are specific numerical values. Therefore, in this embodiment, when determining the target location based on the sub-target value representing the encrypted location, the electronic device uses this sub-target value as the number of bytes containing the target location. That is, if the sub-target value representing the encrypted location is 125, the electronic device determines the 125th byte in the target file as the target location.

[0044] After determining the target location, the electronic device considers the content within the specified encrypted byte length, starting from that target location, as the file content to be encrypted. It should be noted that, for the last encrypted information group, if the byte length from the last byte of the target file to the target location is less than the encrypted byte length, the electronic device determines the content from the target location to the last byte as the file content to be encrypted.

[0045] In this embodiment of the application, the electronic device uses a preset encryption algorithm to encrypt the file content, wherein the encryption algorithm may be the SM4 encryption algorithm.

[0046] In this embodiment of the application, the content of the file to be encrypted in the target file is determined by the encrypted information group obtained based on the first target value, and then the content of the file is encrypted, thus avoiding the need to select a fixed position to encrypt the file and improving the security of file encryption.

[0047] In order to determine a first target value so that the electronic device can flexibly encrypt the target file according to the first target value, based on the above embodiments, in this application embodiment, the method for determining the first target value includes:

[0048] Obtain the pre-saved file information of the target file and the encryptor's account ID, wherein the file information includes at least one of the following: file size, file type, and file content in preset bytes;

[0049] The file information and the account ID are encrypted using a preset encryption algorithm to determine a first value, and the target ellipse equation is determined based on the first value and a pre-saved template of the elliptic curve equation.

[0050] Obtain the pre-saved second value, and determine the first target value based on the second value and the target ellipse equation.

[0051] In this embodiment of the application, the electronic device can generate a first target value based on the file information of the target file and the information of the encryptor, and encrypt the target file based on the first target value.

[0052] Specifically, in this embodiment, the electronic device obtains pre-saved file information of the target file and the encryptor's account ID. This file information includes at least one of the following: file size, file type, and a preset number of bytes of file content. The preset number of bytes of file content can be a portion of the file's content, such as 1KB or 16 bytes from the beginning of the file and 1KB or 16 bytes from the end of the file. In this embodiment, the 1KB or 16 bytes from the beginning of the file can be referred to as the file header information, and the 1KB or 16 bytes from the end of the file can be referred to as the file footer information.

[0053] After obtaining the file information and account ID, the electronic device sorts the file information and account ID according to a preset order and encrypts them using a preset encryption algorithm to determine a first value. The preset order can be account ID, file size, file type, file header information, and file footer information, and the preset encryption algorithm is the SM3 algorithm. Because the encryptor's account ID is used when generating the first value, in this embodiment, the first value determined by the electronic device is different for different encryptors, which can better improve the security of file encryption.

[0054] In this embodiment of the application, after determining the first value, the electronic device obtains a pre-saved template of the elliptic curve equation, which can be y 2 =x 3 +ax+b. The electronic device splits the first value into two sub-values ​​according to a preset method, and determines these two sub-values ​​as parameters a and b respectively, thus obtaining the equation of the target ellipse.

[0055] Generally, in the embodiments of this application, the first value is a 16-bit number. When the electronic device splits the first value into two sub-values, it can split the first 8 bits into one sub-value and the last 8 bits into another sub-value. For example, in the embodiments of this application, if the first value is 1628451369512087, then the first value is split into 16284513 and 69512087, where 16284513 is determined as parameter a and 69512087 is determined as parameter b. Based on this first value, the equation of the target ellipse is determined to be y. 2 =x 3 +16284513x+69512087.

[0056] The electronic device uses a pre-saved second value as the x-axis of the target ellipse equation, substitutes this second value into the target ellipse equation to obtain a solution, and determines this solution as the first target value. Typically, the second value is 0, and the first target value is 64 bits.

[0057] Furthermore, in this embodiment of the application, after determining the target ellipse equation, the electronic device can verify the target ellipse equation based on the characteristics of the ellipse to determine whether the target ellipse equation can be used to draw an elliptic curve. If it can, the subsequent process of determining the first target value is executed. If it cannot, the electronic device needs to redetermine the first value based on the file content of other preset bytes and redetermine the target elliptic curve equation until the determined target elliptic curve equation can be used to draw an elliptic curve.

[0058] In this embodiment of the application, the equation of the elliptic curve defined on Fp (where p is a prime number greater than 3) is:

[0059] y 2 =x 3 +ax+b

[0060] Where a∈Fp, b∈Fp, and (4a 3 +27b 2 )modp≠0, that is (4a 3 +27b 2 The remainder between ) and p is not 0.

[0061] In this embodiment of the application, the elliptic curve E(Fp) is defined as:

[0062] E(Fp) = {(x,y)|x;y∈Fp}

[0063] Where x∈Fp, y∈Fp, and satisfy {y 2 =x 3 +ax+b}∪{O}, where O is the point at infinity, i.e., the zero point.

[0064] In this embodiment of the application, the points on the elliptic curve E(Fp) form an Abelian group according to the following addition rules:

[0065] Addition rule one: O + O = O, that is, the sum of infinity and infinity is infinity;

[0066] Addition rule two: P+O=O+P=P, meaning that if there exists a point P(x;y) in the elliptic curve, then the sum of the ordinate of P and the ordinate at infinity, the sum of the ordinate of P and the ordinate at infinity, and the value of the ordinate of P are the same.

[0067] Addition rule three: The inverse element of P is -P = (x; -y), P + (-P) = 0. That is, if there exists a point P in the elliptic curve, then the sum of the ordinates of P and the inverse element of P is infinity, i.e., 0.

[0068] Addition rule four: P2=(x2;y2)∈E(Fp)\{O}, P3=(x3;y3)=P1+P2≠O, then x3=λ 2-x1-x2, y3=λ(x1-x3)-y1, where, if x1≠x2, then λ=(y2-y1) / (x2-x1); if x1=x2 and P2≠-P1, then λ=(3x2+a) / 2y1. This means there are three points P1, P2, and P3 in the elliptic curve, where P3 is the symmetric point about the x-axis to the intersection of the lines P1 and P2 with the elliptic curve. The coordinates of P3 can be determined using the coordinates of P1 and P2, and the slope of the tangent line to the elliptic curve at P3 can also be determined. Specifically, if the x-coordinates of P1 and P2 are different, the slope of the tangent line is λ=(y2-y1) / (x2-x1); if the x-coordinates of P1 and P2 are the same, and the y-coordinates of P2 and P1 are not inverses of each other, then the slope of the tangent line is λ=(3x2+a) / 2y1.

[0069] Figure 2 This is a schematic diagram of the elliptic curve corresponding to the first target ellipse equation provided in the embodiments of this application, as shown in the figure. Figure 2 As shown, the equation of the first target ellipse is y 2 =x 3 -x, the first objective ellipse equation can be used to plot an elliptic curve.

[0070] Figure 3 This is a schematic diagram of the elliptic curve corresponding to the second target ellipse equation provided in the embodiments of this application, as shown in the figure. Figure 3 As shown, the equation of the second target ellipse is y 2 =x 3 -x+1, the second objective ellipse equation can be used to plot an elliptic curve.

[0071] Figure 4 This is a schematic diagram of the elliptic curve corresponding to the third target ellipse equation provided in the embodiments of this application, as shown in the figure. Figure 4 As shown, the equation of the third objective ellipse is y 2 =x 3 +x+1, the equation of the third objective ellipse can be used to plot an elliptic curve.

[0072] Figure 5 This is a schematic diagram of the elliptic curve corresponding to the fourth target ellipse equation provided in the embodiments of this application, as shown in the figure. Figure 5 As shown, the equation of the fourth objective ellipse is y 2 =x 3 +x-1, the fourth objective ellipse equation can be used to plot an elliptic curve.

[0073] In this embodiment, the electronic device uses elliptic curves to determine the first target value and encrypts the target file based on the first target value. This makes the location and length of the encryption in the target file irregular, making it difficult for crackers to locate the encryption location and length, thus preventing cracking and improving encryption security. Furthermore, in this embodiment, the electronic device encrypts only a portion of the target file, resulting in less time than full-text encryption and improving encryption efficiency.

[0074] To determine the encryption information and encrypt the target file based on the encryption information, based on the above embodiments, the process of determining the encryption information corresponding to the sub-target value in this embodiment includes:

[0075] Determine the position of the sub-target value within the first target value;

[0076] Based on the pre-saved correspondence between location and encrypted information, the encrypted information corresponding to the sub-target value at the corresponding location is determined. The encrypted information corresponding to the first sub-target value is the length of the encrypted bytes, and the encrypted information corresponding to two adjacent sub-target values ​​is different.

[0077] In this embodiment of the application, the electronic device can pre-store the encryption information corresponding to each sub-target value, and the electronic device can determine the encryption information of the sub-target value during the encryption process.

[0078] If the electronic device determines the encryption information of the sub-target value during the encryption process, the electronic device has a pre-stored correspondence between the position of the sub-target value in the first target value and the encryption information. The electronic device can determine the encryption information corresponding to each sub-target value based on this correspondence and the position of each sub-target value in the first target value.

[0079] For example, in this embodiment of the application, the electronic device pre-stores the encrypted information corresponding to the first position as the encrypted byte length, the encrypted information corresponding to the second position as the encrypted position, and so on. Thus, the electronic device can determine that the encrypted information corresponding to the first sub-target value is the encrypted byte length, the encrypted information corresponding to the second sub-target value is the encrypted position, and so on.

[0080] Specifically, the electronic device determines the position of each sub-target value within the first target value, and determines the encryption information corresponding to the sub-target value at the corresponding position based on the pre-saved correspondence between the position and the encryption information.

[0081] It should be noted that, in order to improve the encryption effect on the target file, in this embodiment, the electronic device can encrypt the first byte of the target file when encrypting it. Based on this, in this embodiment, when determining the encryption information corresponding to each sub-target value, the electronic device can determine the encryption information corresponding to the first sub-target value as the encryption byte length, so that the electronic device can encrypt the first byte of the target file based on this first sub-target value. Furthermore, to ensure that the constructed encryption information group includes both the encryption position and the encryption byte length, in this embodiment, the encryption information corresponding to two adjacent sub-target values ​​is different.

[0082] To determine the encryption information group and encrypt the target file based on the encryption information group, in this embodiment of the application, based on the above embodiments, determining the encryption information group includes:

[0083] If the encrypted information is the encrypted information corresponding to the value of the first sub-target, then the encrypted information is determined as an encrypted information group, and the encrypted position corresponding to the encrypted information group is determined as the first byte;

[0084] Based on the position of the sub-target value within the first target value, the encrypted information corresponding to every two adjacent sub-target values ​​other than the first sub-target value is determined as an encrypted information group.

[0085] In this embodiment, when determining an encrypted information group, if the encrypted information is the encrypted information corresponding to the first sub-target value, then the encrypted information is determined as an encrypted information group, and the encryption position corresponding to the encrypted information group is determined to be the first byte. That is, in this embodiment, if the encrypted information is the encrypted information corresponding to the first sub-target value, then the encrypted information group containing the encrypted information only contains the sub-target value corresponding to the encrypted information, and the electronic device determines the encryption position corresponding to the encrypted information group to be the first byte, and the encrypted information corresponding to the first sub-target value is the length of the encrypted bytes.

[0086] In addition, the electronic device determines the encrypted information corresponding to every two adjacent sub-target values ​​other than the first sub-target value as an encrypted information group based on the position of the sub-target value in the first target value.

[0087] To better encrypt the target file and improve encryption security, based on the above embodiments, in this embodiment, after determining the encryption information group and before determining the target position corresponding to the encryption position in the target file according to the encryption position carried in the encryption information group, the method further includes:

[0088] Based on the position of the corresponding sub-target value in the first target value, the order of the encrypted information groups is determined, and then the subsequent steps of determining the target position corresponding to the encrypted position in the target file are performed for the encrypted information carried in the encrypted information group in turn.

[0089] In this embodiment, when encrypting a target file, the electronic device may determine only one encryption information group and encrypt a segment of the file content. However, to improve the security of file encryption, the electronic device may determine multiple encryption information groups and encrypt multiple segments of the file content.

[0090] Specifically, in this embodiment, if the electronic device determines multiple encrypted information groups, it determines the position of the sub-target value corresponding to each encrypted information group within the first target value, and determines the order of each encrypted information group. The electronic device then sequentially targets each encrypted information group according to this order, and determines the target position corresponding to the encrypted position in the target file based on the encrypted position carried in the encrypted information group.

[0091] To determine the target location for encrypting a target file and improve encryption security, based on the above embodiments, in this embodiment, determining the target location corresponding to the encrypted location in the target file according to the encrypted location carried in the encrypted information group includes:

[0092] If the encrypted information group is the first encrypted information group, then the first byte of the target file is taken as the target position;

[0093] If the encrypted information group is not the first encrypted information group, then according to the sorting result, the termination position corresponding to the first encrypted information group before the encrypted information group is determined; the termination position is determined as the starting position corresponding to the encrypted information group, and the target position is determined according to the starting position and the sub-target value corresponding to the encrypted position.

[0094] In this embodiment, when determining the target location based on an encrypted information group, if the encrypted information group is the first encrypted information group, the electronic device uses the first byte of the target file as the target location. If the encrypted information group is not the first encrypted information group, the electronic device determines the termination position corresponding to the first encrypted information group preceding the current encrypted information group according to the sorting result of the encrypted information groups, determines the termination position as the starting position corresponding to the current encrypted information group, and determines the target location based on the starting position and the sub-target value corresponding to the encrypted position carried in the encrypted information group.

[0095] Figure 6This is a schematic diagram illustrating the correspondence between a first target value and the content of the file to be encrypted, as provided in an embodiment of this application. Figure 6 As shown, the first target value includes multiple encrypted information groups. The first encrypted information group contains an encrypted byte length, and the other encrypted information groups include an encryption position and an encrypted byte length. The electronic device can determine the content of the file to be encrypted within the target file based on this first target value. Figure 6 In the encryption information, the sub-target value at the encryption location is 4 bytes, and the value range of the sub-target value is 0 to 65535; the sub-target value of the encryption information in terms of the encryption byte length is 2 bytes, and the value range of the sub-target value is 0 to 255.

[0096] To better encrypt the target file and improve encryption security, based on the above embodiments, in this embodiment, if the encrypted information group is the last encrypted information group, obtaining the file content with the encrypted byte length according to the target position includes:

[0097] The content from the target position to the last byte of the target file is determined as the candidate file content;

[0098] If the byte length of the candidate file content does not exceed the encrypted byte length, then the candidate file content is determined as the file content;

[0099] If the byte length of the candidate file content exceeds the encrypted byte length, then the content of the encrypted byte length after the target position is determined, and the content of the encrypted byte length is determined as the file content; and the saved second target value is obtained, and the first target value is updated using the second target value; the first byte after the file content is determined as the encryption start position corresponding to the updated first target value; and the content after the file content is encrypted according to the updated first target value and the encryption start position.

[0100] In this embodiment of the application, in order to improve the security of file encryption, the electronic device encrypts not only the first byte of the target file, but also the last byte of the target file.

[0101] Specifically, in this embodiment, for each encrypted information group, if the encrypted information group is the last encrypted information group, the content from the target position to the last byte of the target file is determined as candidate file content, and the byte length of the candidate file content is determined. If the byte length of the candidate file content does not exceed the encrypted byte length carried in the encrypted information group, the electronic device determines the candidate file content as the file content to be encrypted; if the byte length of the candidate file content exceeds the encrypted byte length, the electronic device determines the content of the encrypted byte length after the target position and determines the content of the encrypted byte length as the file content. Furthermore, the electronic device obtains the saved second target value, uses the second target value as the first target value, uses the content after the file content as the target file, and continues to encrypt the file until the last byte of the target file is encrypted.

[0102] Specifically, the electronic device acquires the saved second target value, updates the first target value using the second target value, determines the first byte after the file content as the encryption start position corresponding to the updated first target value, and encrypts the content after the file content based on the updated first target value and the encryption start position.

[0103] It should be noted that this second target value is also determined based on the target elliptic curve equation.

[0104] Figure 7 This is a schematic diagram of the file encryption process provided in the embodiments of this application, as shown below. Figure 7 As shown, the process includes:

[0105] S701: Obtain the target file to be encrypted and a pre-configured first target value, wherein the first target value includes at least one sub-target value.

[0106] S702: Obtain the encrypted information corresponding to the saved sub-target value, and determine the encrypted information group, wherein the encrypted information is an encrypted position or an encrypted byte length, and the encrypted information group includes an encrypted position and an encrypted byte length.

[0107] S703: Determine the order of the encrypted information groups based on the position of the corresponding sub-target value within the first target value.

[0108] S704: If the encrypted information group is the last encrypted information group, then the content from the target position to the last byte of the target file is determined as the candidate file content.

[0109] S705: Determine whether the byte length of the candidate file content exceeds the encrypted byte length. If not, execute S706; if yes, execute S707.

[0110] S706: The content of the candidate file is determined as the content of this file.

[0111] S707: Determine the content of the encrypted byte length following the target location, and determine the content of the encrypted byte length as the file content.

[0112] S708: Obtain the saved second target value, use the second target value to update the first target value; determine the first byte after the content of the file as the encryption start position corresponding to the updated first target value; and execute S702.

[0113] Figure 8 This application provides a schematic diagram of a file decryption process, which includes:

[0114] S801: Obtain the target file to be decrypted and a pre-configured first target value, wherein the first target value includes at least one sub-target value.

[0115] The file decryption method provided in this application is applied to an electronic device, which may be a server, terminal, or PC.

[0116] In this embodiment of the application, the electronic device receives a decryption request input by the user, wherein the decryption request carries identification information of the target file to be decrypted, and the electronic device determines and obtains the target file based on the identification information.

[0117] Furthermore, in order to avoid decrypting the file content in the regular location of the target file, in this embodiment of the application, the electronic device stores a pre-configured first target value, and the electronic device can determine the file content to be decrypted in the target file based on the first target value.

[0118] Specifically, in this embodiment, the first target value includes at least one sub-target value, which can be used to determine the decryption byte length of the target file. Furthermore, in this embodiment, to further improve the security of file decryption, the first target value used when decrypting each file can be different. For example, the electronic device can store the correspondence between file identification information and the first target value. Each file with different identification information corresponds to a different first target value. The electronic device can determine the first target value of the target file based on the identification information corresponding to the target file and this correspondence.

[0119] It should be noted that, in the embodiments of this application, the first target value used by the electronic device when decrypting the target file is the same as the first target value used when encrypting the target file.

[0120] S802: Obtain the decryption information corresponding to the saved subtarget value, and determine the decryption information group, wherein the decryption information is a decryption position or a decryption byte length, and the decryption information group includes a decryption position and a decryption byte length.

[0121] In this embodiment, each sub-target value that makes up the first target value represents a decryption information, and the decryption information represented by each sub-target value can be configured together with the first target value in the electronic device. The decryption information is either the decryption location or the decryption byte length.

[0122] Specifically, in this embodiment of the application, after obtaining a pre-configured first target value, the electronic device obtains decryption information corresponding to each sub-target value and determines a decryption information group based on the different decryption information. It should be noted that a decryption information group includes at least one decryption position and one decryption byte length.

[0123] Specifically, in this embodiment, at least one sub-target value constitutes a first target value. Based on this, when pre-configuring the decryption information corresponding to each sub-target value of the first target value, the decryption information of two adjacent sub-target values ​​is different. When determining the decryption information group, the electronic device can determine the encrypted information corresponding to two adjacent sub-target values ​​as a decryption information group.

[0124] It should be noted that, in this embodiment of the application, for each sub-target value in the first target value, the type of the encryption information corresponding to the sub-target value is consistent with the type of the decryption information corresponding to the sub-target value. That is, if the encryption information corresponding to the sub-target value is the encryption position, then the decryption information corresponding to the sub-target value is the decryption position; if the encryption information corresponding to the sub-target value is the encryption byte length, then the decryption information corresponding to the sub-target value is the decryption byte length.

[0125] S803: Based on the decryption location carried in the decryption information group, determine the target location corresponding to the decryption location in the target file, obtain the file content of the decryption byte length based on the target location, and decrypt the file content.

[0126] In this application embodiment, for each decryption information group that has been determined, the decryption position contained in the decryption information group is determined. The electronic device can find the target position corresponding to the decryption position in the target file according to the decryption position, and obtain the file content of the decryption byte length starting from the target position. The file content is determined as the file content to be decrypted in the target file, and the file content is decrypted.

[0127] In this application, both the sub-target value representing the decryption location and the sub-target value representing the length of the decryption bytes are specific numerical values. Therefore, in this embodiment, when determining the target location based on the sub-target value representing the decryption location, the electronic device uses this sub-target value as the number of bytes containing the target location. For example, if the sub-target value representing the decryption location is 125, the electronic device determines the 125th byte in the target file as the target location.

[0128] After determining the target location, the electronic device considers the content within the decryption byte length starting from that target location as the file content to be decrypted. It should be noted that, for the last decryption information group, if the length between the last byte of the target file and the byte length at the target location is less than the decryption byte length, the electronic device determines the content from the target location to the last byte as the file content to be decrypted.

[0129] In this embodiment of the application, the electronic device uses a preset decryption algorithm to decrypt the file content, wherein the decryption algorithm may be the SM4 decryption algorithm.

[0130] In one possible implementation, the method for determining the first target value includes:

[0131] Obtain the pre-saved file information of the target file and the account ID of the decryptor, wherein the file information includes the file size, file type, and file content in preset bytes;

[0132] The file information and the account ID are decrypted using a preset decryption algorithm to determine a first value, and the target ellipse equation is determined based on the first value and a pre-saved template of the elliptic curve equation.

[0133] Obtain the pre-saved second value, and determine the first target value based on the second value and the target ellipse equation.

[0134] In one possible implementation, the process of determining the decryption information corresponding to the sub-target value includes:

[0135] Determine the position of the sub-target value within the first target value;

[0136] Based on the pre-saved correspondence between location and decryption information, the decryption information corresponding to the sub-target value at the corresponding location is determined. The decryption information corresponding to the first sub-target value is the length of the decryption bytes, and the decryption information corresponding to two adjacent sub-target values ​​is different.

[0137] In one possible implementation, determining the decryption information group includes:

[0138] If the decryption information is the decryption information corresponding to the value of the first sub-target, then the decryption information is determined as a decryption information group, and the decryption position corresponding to the decryption information group is determined as the first byte;

[0139] Based on the position of the sub-target value within the first target value, the decryption information corresponding to every two adjacent sub-target values ​​other than the first sub-target value is determined as a decryption information group.

[0140] In one possible implementation, after determining the decryption information group and before determining the target location corresponding to the decryption location in the target file based on the decryption location carried in the decryption information group, the method further includes:

[0141] Based on the position of the corresponding sub-target value in the first target value, the order of the decryption information groups is determined, and then, for each decryption information carried in the decryption information group, the subsequent steps of determining the target position corresponding to the decryption position in the target file based on the decryption position carried in the decryption information group are executed.

[0142] In one possible implementation, determining the target location corresponding to the decryption location in the target file based on the decryption location carried in the decryption information group includes:

[0143] If the decryption information group is the first decryption information group, then the first byte of the target file is taken as the target location;

[0144] If the decryption information group is not the first decryption information group, then according to the sorting result, the termination position corresponding to the first candidate decryption information group before the decryption information group is determined; the termination position is determined as the starting position corresponding to the decryption information group, and the target position is determined according to the sub-target value corresponding to the starting position and the decryption position.

[0145] In one possible implementation, if the decryption information group is the last decryption information group, obtaining the file content with the decryption byte length based on the target position includes:

[0146] The content from the target position to the last byte of the target file is determined as the candidate file content;

[0147] If the byte length of the candidate file content does not exceed the decryption byte length, then the candidate file content is determined as the file content;

[0148] If the byte length of the candidate file content exceeds the decryption byte length, then the content of the decryption byte length after the target position is determined, and the content of the decryption byte length is determined as the file content; and the saved second target value is obtained, and the first target value is updated using the second target value; the first byte after the file content is determined as the decryption start position corresponding to the updated first target value; and the content after the file content is decrypted according to the updated first target value and the decryption start position.

[0149] In this embodiment of the application, the process of decrypting the target file by the electronic device is the same as the process of encrypting the target file, and will not be described again here.

[0150] Figure 9 This application provides a schematic diagram of a file encryption device, which includes:

[0151] Processing module 901 is used to obtain the target file to be encrypted and a pre-configured first target value, wherein the first target value includes at least one sub-target value; obtain the encryption information corresponding to the saved sub-target value; and determine the encryption information group, wherein the encryption information is an encryption position or an encryption byte length, and the encryption information group includes an encryption position and an encryption byte length.

[0152] The encryption module 902 is used to determine the target position corresponding to the encryption position in the target file according to the encryption position carried in the encryption information group, obtain the file content of the encryption byte length according to the target position, and encrypt the file content.

[0153] In one possible implementation, the processing module 901 is further configured to obtain pre-saved file information of the target file and the encryptor's account ID, wherein the file information includes at least one of file size, file type, and file content in preset bytes; encrypt the file information and the account ID using a preset encryption algorithm to determine a first value, and determine the target ellipse equation based on the first value and a pre-saved template of the elliptic curve equation; obtain a pre-saved second value, and determine the first target value based on the second value and the target ellipse equation.

[0154] In one possible implementation, the processing module 901 is further configured to determine the position of the sub-target value in the first target value; and to determine the encryption information corresponding to the sub-target value at the corresponding position according to the pre-saved correspondence between the position and the encryption information, wherein the encryption information corresponding to the first sub-target value is the length of the encryption bytes, and the encryption information corresponding to two adjacent sub-target values ​​is different.

[0155] In one possible implementation, the processing module 901 is specifically configured to, if the encrypted information is the encrypted information corresponding to the first sub-target value, determine the encrypted information as an encrypted information group and determine the encrypted position corresponding to the encrypted information group as the first byte; and, based on the position of the sub-target value in the first target value, determine the encrypted information corresponding to every two adjacent other sub-target values ​​other than the first sub-target value as an encrypted information group.

[0156] In one possible implementation, the processing module 901 is further configured to determine the order of the encrypted information groups based on the position of the corresponding sub-target value in the first target value;

[0157] The encryption module 902 is specifically used to sequentially perform the following steps for determining the target location corresponding to the encryption location in the target file based on the encryption location carried in the encryption information group.

[0158] In one possible implementation, the encryption module 902 is specifically configured to: if the encrypted information group is the first encrypted information group, then take the first byte of the target file as the target position; if the encrypted information group is not the first encrypted information group, then determine the termination position corresponding to the first candidate encrypted information group before the encrypted information group according to the sorting result; determine the termination position as the starting position corresponding to the encrypted information group; and determine the target position according to the starting position and the sub-target value corresponding to the encrypted position.

[0159] In one possible implementation, the encryption module 902 is specifically configured to: if the encrypted information group is the last encrypted information group, determine the content from the target position to the last byte of the target file as candidate file content; if the byte length of the candidate file content does not exceed the encrypted byte length, determine the candidate file content as the file content; if the byte length of the candidate file content exceeds the encrypted byte length, determine the content of the encrypted byte length after the target position, and determine the content of the encrypted byte length as the file content; obtain a saved second target value, update the first target value using the second target value; determine the first byte after the file content as the encryption start position corresponding to the updated first target value; and encrypt the content after the file content according to the updated first target value and the encryption start position.

[0160] Figure 10 This application provides a schematic diagram of a file decryption device, which includes:

[0161] Processing module 1001 is used to obtain the target file to be decrypted and a pre-configured first target value, wherein the first target value includes at least one sub-target value; obtain the decryption information corresponding to the saved sub-target value; determine the decryption information group, wherein the decryption information is a decryption position or a decryption byte length, and the decryption information group includes a decryption position and a decryption byte length.

[0162] The decryption module 1002 is used to determine the target position corresponding to the decryption position in the target file according to the decryption position carried in the decryption information group, obtain the file content of the decryption byte length according to the target position, and decrypt the file content.

[0163] In one possible implementation, the processing module 1001 is further configured to obtain pre-saved file information of the target file and the account ID of the decryptor, wherein the file information includes file size, file type, and file content in preset bytes; decrypt the file information and the account ID using a preset decryption algorithm to determine a first value, and determine the target ellipse equation based on the first value and a pre-saved template of the elliptic curve equation; obtain a pre-saved second value, and determine the first target value based on the second value and the target ellipse equation.

[0164] In one possible implementation, the processing module 1001 is further configured to determine the position of the sub-target value in the first target value; and to determine the decryption information corresponding to the sub-target value at the corresponding position according to the pre-saved correspondence between the position and the decryption information, wherein the decryption information corresponding to the first sub-target value is the decryption byte length, and the decryption information corresponding to two adjacent sub-target values ​​is different.

[0165] In one possible implementation, the processing module 1001 is specifically configured to: if the decryption information is the decryption information corresponding to the first sub-target value, determine the decryption information as a decryption information group and determine the decryption position corresponding to the decryption information group as the first byte; and, based on the position of the sub-target value in the first target value, determine the decryption information corresponding to every two adjacent other sub-target values ​​other than the first sub-target value as a decryption information group.

[0166] In one possible implementation, the processing module 1001 is further configured to determine the order of the decrypted information groups based on the position of the corresponding sub-target value in the first target value;

[0167] The decryption module 1002 is specifically used to sequentially perform the following steps for determining the target location corresponding to the decryption location in the target file based on the decryption location carried in the decryption information group.

[0168] In one possible implementation, the decryption module 1002 is specifically configured to: if the decryption information group is the first decryption information group, then take the first byte of the target file as the target position; if the decryption information group is not the first decryption information group, then determine the termination position corresponding to the first candidate decryption information group before the decryption information group according to the sorting result; determine the termination position as the starting position corresponding to the decryption information group, and determine the target position according to the starting position and the sub-target value corresponding to the decryption position.

[0169] In one possible implementation, the decryption module 1002 is specifically configured to: if the decryption information group is the last decryption information group, determine the content from the target position to the last byte of the target file as candidate file content; if the byte length of the candidate file content does not exceed the decryption byte length, determine the candidate file content as the file content; if the byte length of the candidate file content exceeds the decryption byte length, determine the content of the decryption byte length after the target position, determine the content of the decryption byte length as the file content; obtain a saved second target value, update the first target value using the second target value; determine the first byte after the file content as the decryption start position corresponding to the updated first target value; and decrypt the content after the file content according to the updated first target value and the decryption start position.

[0170] Based on the above embodiments, this application also provides an electronic device. Figure 11 This application provides a schematic diagram of an electronic device structure, such as... Figure 11 As shown, it includes: processor 1101, communication interface 1102, memory 1103 and communication bus 1104, wherein processor 1101, communication interface 1102 and memory 1103 communicate with each other through communication bus 1104.

[0171] The memory 1103 stores a computer program, which, when executed by the processor 1101, causes the processor 1101 to perform the following steps:

[0172] Obtain the target file to be encrypted and a pre-configured first target value, wherein the first target value includes at least one sub-target value;

[0173] Obtain the encrypted information corresponding to the saved sub-target value, and determine the encrypted information group, wherein the encrypted information is an encrypted position or an encrypted byte length, and the encrypted information group includes an encrypted position and an encrypted byte length;

[0174] Based on the encryption location carried in the encryption information group, the target location corresponding to the encryption location in the target file is determined. Based on the target location, the file content of the encryption byte length is obtained, and the file content is encrypted.

[0175] Furthermore, the processor 1101 is also used for:

[0176] Obtain the pre-saved file information of the target file and the encryptor's account ID, wherein the file information includes at least one of the following: file size, file type, and file content in preset bytes;

[0177] The file information and the account ID are encrypted using a preset encryption algorithm to determine a first value, and the target ellipse equation is determined based on the first value and a pre-saved template of the elliptic curve equation.

[0178] Obtain the pre-saved second value, and determine the first target value based on the second value and the target ellipse equation.

[0179] Furthermore, the processor 1101 is also used for:

[0180] Determine the position of the sub-target value within the first target value;

[0181] Based on the pre-saved correspondence between location and encrypted information, the encrypted information corresponding to the sub-target value at the corresponding location is determined. The encrypted information corresponding to the first sub-target value is the length of the encrypted bytes, and the encrypted information corresponding to two adjacent sub-target values ​​is different.

[0182] Furthermore, the processor 1101 is also used for:

[0183] If the encrypted information is the encrypted information corresponding to the value of the first sub-target, then the encrypted information is determined as an encrypted information group, and the encrypted position corresponding to the encrypted information group is determined as the first byte;

[0184] Based on the position of the sub-target value within the first target value, the encrypted information corresponding to every two adjacent sub-target values ​​other than the first sub-target value is determined as an encrypted information group.

[0185] Furthermore, the processor 1101 is also used for:

[0186] Based on the position of the corresponding sub-target value in the first target value, the order of the encrypted information groups is determined, and then the subsequent steps of determining the target position corresponding to the encrypted position in the target file are performed for the encrypted information carried in the encrypted information group in turn.

[0187] Furthermore, the processor 1101 is also used for:

[0188] If the encrypted information group is the first encrypted information group, then the first byte of the target file is taken as the target position;

[0189] If the encrypted information group is not the first encrypted information group, then according to the sorting result, the termination position corresponding to the first candidate encrypted information group before the encrypted information group is determined; the termination position is determined as the starting position corresponding to the encrypted information group, and the target position is determined according to the starting position and the sub-target value corresponding to the encrypted position.

[0190] Furthermore, the processor 1101 is also used for:

[0191] The content from the target position to the last byte of the target file is determined as the candidate file content;

[0192] If the byte length of the candidate file content does not exceed the encrypted byte length, then the candidate file content is determined as the file content;

[0193] If the byte length of the candidate file content exceeds the encrypted byte length, then the content of the encrypted byte length after the target position is determined, and the content of the encrypted byte length is determined as the file content; and the saved second target value is obtained, and the first target value is updated using the second target value; the first byte after the file content is determined as the encryption start position corresponding to the updated first target value; and the content after the file content is encrypted according to the updated first target value and the encryption start position.

[0194] Since the principle behind the problem-solving function of the aforementioned electronic device is similar to that of file encryption methods, the implementation of the aforementioned electronic device can be found in the embodiments of the method, and repeated details will not be elaborated here.

[0195] Based on the above embodiments, in this embodiment, the memory 1103 stores a computer program, and when the program is executed by the processor 1101, the processor 1101 can also perform the following steps:

[0196] Obtain the target file to be decrypted and a pre-configured first target value, wherein the first target value includes at least one sub-target value;

[0197] Obtain the decryption information corresponding to the saved subtarget value, and determine the decryption information group, wherein the decryption information is a decryption position or a decryption byte length, and the decryption information group includes a decryption position and a decryption byte length;

[0198] Based on the decryption location carried in the decryption information group, determine the target location corresponding to the decryption location in the target file, obtain the file content of the decryption byte length based on the target location, and decrypt the file content.

[0199] Furthermore, the processor 1101 is also used for:

[0200] Obtain the pre-saved file information of the target file and the account ID of the decryptor, wherein the file information includes the file size, file type, and file content in preset bytes;

[0201] The file information and the account ID are decrypted using a preset decryption algorithm to determine a first value, and the target ellipse equation is determined based on the first value and a pre-saved template of the elliptic curve equation.

[0202] Obtain the pre-saved second value, and determine the first target value based on the second value and the target ellipse equation.

[0203] Furthermore, the processor 1101 is also used for:

[0204] Determine the position of the sub-target value within the first target value;

[0205] Based on the pre-saved correspondence between location and decryption information, the decryption information corresponding to the sub-target value at the corresponding location is determined. The decryption information corresponding to the first sub-target value is the length of the decryption bytes, and the decryption information corresponding to two adjacent sub-target values ​​is different.

[0206] Furthermore, the processor 1101 is also used for:

[0207] If the decryption information is the decryption information corresponding to the value of the first sub-target, then the decryption information is determined as a decryption information group, and the decryption position corresponding to the decryption information group is determined as the first byte;

[0208] Based on the position of the sub-target value within the first target value, the decryption information corresponding to every two adjacent sub-target values ​​other than the first sub-target value is determined as a decryption information group.

[0209] Furthermore, the processor 1101 is also used for:

[0210] Based on the position of the corresponding sub-target value in the first target value, the order of the decryption information groups is determined, and then, for each decryption information carried in the decryption information group, the subsequent steps of determining the target position corresponding to the decryption position in the target file based on the decryption position carried in the decryption information group are executed.

[0211] Furthermore, the processor 1101 is also used for:

[0212] If the decryption information group is the first decryption information group, then the first byte of the target file is taken as the target location;

[0213] If the decryption information group is not the first decryption information group, then according to the sorting result, the termination position corresponding to the first candidate decryption information group before the decryption information group is determined; the termination position is determined as the starting position corresponding to the decryption information group, and the target position is determined according to the sub-target value corresponding to the starting position and the decryption position.

[0214] Furthermore, the processor 1101 is also used for:

[0215] The content from the target position to the last byte of the target file is determined as the candidate file content;

[0216] If the byte length of the candidate file content does not exceed the decryption byte length, then the candidate file content is determined as the file content;

[0217] If the byte length of the candidate file content exceeds the decryption byte length, then the content of the decryption byte length after the target position is determined, and the content of the decryption byte length is determined as the file content; and the saved second target value is obtained, and the first target value is updated using the second target value; the first byte after the file content is determined as the decryption start position corresponding to the updated first target value; and the content after the file content is decrypted according to the updated first target value and the decryption start position.

[0218] Since the principle of the above-mentioned electronic device in solving the problem is similar to that of the file decryption method, the implementation of the above-mentioned electronic device can be found in the embodiments of the method, and repeated parts will not be described again.

[0219] The communication bus mentioned in the above-mentioned electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used in the figure, but this does not indicate that there is only one bus or one type of bus. The communication interface 1102 is used for communication between the above-mentioned electronic device and other devices. The memory can include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory can also be at least one storage device located remotely from the aforementioned processor.

[0220] The processors mentioned above can be general-purpose processors, including central processing units, network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits, field-programmable gate arrays or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.

[0221] Based on the above embodiments, this application also provides a computer-readable storage medium storing a computer program executable by a processor. When the program runs on the processor, it causes the processor to perform the following steps:

[0222] Obtain the target file to be encrypted and a pre-configured first target value, wherein the first target value includes at least one sub-target value;

[0223] Obtain the encrypted information corresponding to the saved sub-target value, and determine the encrypted information group, wherein the encrypted information is an encrypted position or an encrypted byte length, and the encrypted information group includes an encrypted position and an encrypted byte length;

[0224] Based on the encryption location carried in the encryption information group, the target location corresponding to the encryption location in the target file is determined. Based on the target location, the file content of the encryption byte length is obtained, and the file content is encrypted.

[0225] In one possible implementation, the method for determining the first target value includes:

[0226] Obtain the pre-saved file information of the target file and the encryptor's account ID, wherein the file information includes at least one of the following: file size, file type, and file content in preset bytes;

[0227] The file information and the account ID are encrypted using a preset encryption algorithm to determine a first value, and the target ellipse equation is determined based on the first value and a pre-saved template of the elliptic curve equation.

[0228] Obtain the pre-saved second value, and determine the first target value based on the second value and the target ellipse equation.

[0229] In one possible implementation, the process of determining the encrypted information corresponding to the sub-target value includes:

[0230] Determine the position of the sub-target value within the first target value;

[0231] Based on the pre-saved correspondence between location and encrypted information, the encrypted information corresponding to the sub-target value at the corresponding location is determined. The encrypted information corresponding to the first sub-target value is the length of the encrypted bytes, and the encrypted information corresponding to two adjacent sub-target values ​​is different.

[0232] In one possible implementation, determining the encrypted information group includes:

[0233] If the encrypted information is the encrypted information corresponding to the value of the first sub-target, then the encrypted information is determined as an encrypted information group, and the encrypted position corresponding to the encrypted information group is determined as the first byte;

[0234] Based on the position of the sub-target value within the first target value, the encrypted information corresponding to every two adjacent sub-target values ​​other than the first sub-target value is determined as an encrypted information group.

[0235] In one possible implementation, after determining the encrypted information group and before determining the target location corresponding to the encrypted location in the target file based on the encrypted location carried in the encrypted information group, the method further includes:

[0236] Based on the position of the corresponding sub-target value in the first target value, the order of the encrypted information groups is determined, and then the subsequent steps of determining the target position corresponding to the encrypted position in the target file are performed for the encrypted information carried in the encrypted information group in turn.

[0237] In one possible implementation, determining the target location corresponding to the encrypted location in the target file based on the encrypted location carried in the encrypted information group includes:

[0238] If the encrypted information group is the first encrypted information group, then the first byte of the target file is taken as the target position;

[0239] If the encrypted information group is not the first encrypted information group, then according to the sorting result, the termination position corresponding to the first candidate encrypted information group before the encrypted information group is determined; the termination position is determined as the starting position corresponding to the encrypted information group, and the target position is determined according to the starting position and the sub-target value corresponding to the encrypted position.

[0240] In one possible implementation, if the encrypted information group is the last encrypted information group, obtaining the file content with the encrypted byte length based on the target position includes:

[0241] The content from the target position to the last byte of the target file is determined as the candidate file content;

[0242] If the byte length of the candidate file content does not exceed the encrypted byte length, then the candidate file content is determined as the file content;

[0243] If the byte length of the candidate file content exceeds the encrypted byte length, then the content of the encrypted byte length after the target position is determined, and the content of the encrypted byte length is determined as the file content; and the saved second target value is obtained, and the first target value is updated using the second target value; the first byte after the file content is determined as the encryption start position corresponding to the updated first target value; and the content after the file content is encrypted according to the updated first target value and the encryption start position.

[0244] Since the principle of the computer-readable storage medium in solving the problem is similar to that of the file encryption method, the implementation of the computer-readable storage medium can be found in the embodiments of the method, and repeated details will not be described again.

[0245] Based on the above embodiments, in this embodiment, a computer-readable storage medium stores a computer program executable by a processor. When the program runs on the processor, enabling the processor to execute, the following steps are performed:

[0246] Obtain the target file to be decrypted and a pre-configured first target value, wherein the first target value includes at least one sub-target value;

[0247] Obtain the decryption information corresponding to the saved subtarget value, and determine the decryption information group, wherein the decryption information is a decryption position or a decryption byte length, and the decryption information group includes a decryption position and a decryption byte length;

[0248] Based on the decryption location carried in the decryption information group, determine the target location corresponding to the decryption location in the target file, obtain the file content of the decryption byte length based on the target location, and decrypt the file content.

[0249] In one possible implementation, the method for determining the first target value includes:

[0250] Obtain the pre-saved file information of the target file and the account ID of the decryptor, wherein the file information includes the file size, file type, and file content in preset bytes;

[0251] The file information and the account ID are decrypted using a preset decryption algorithm to determine a first value, and the target ellipse equation is determined based on the first value and a pre-saved template of the elliptic curve equation.

[0252] Obtain the pre-saved second value, and determine the first target value based on the second value and the target ellipse equation.

[0253] In one possible implementation, the process of determining the decryption information corresponding to the sub-target value includes:

[0254] Determine the position of the sub-target value within the first target value;

[0255] Based on the pre-saved correspondence between location and decryption information, the decryption information corresponding to the sub-target value at the corresponding location is determined. The decryption information corresponding to the first sub-target value is the length of the decryption bytes, and the decryption information corresponding to two adjacent sub-target values ​​is different.

[0256] In one possible implementation, determining the decryption information group includes:

[0257] If the decryption information is the decryption information corresponding to the value of the first sub-target, then the decryption information is determined as a decryption information group, and the decryption position corresponding to the decryption information group is determined as the first byte;

[0258] Based on the position of the sub-target value within the first target value, the decryption information corresponding to every two adjacent sub-target values ​​other than the first sub-target value is determined as a decryption information group.

[0259] In one possible implementation, after determining the decryption information group and before determining the target location corresponding to the decryption location in the target file based on the decryption location carried in the decryption information group, the method further includes:

[0260] Based on the position of the corresponding sub-target value in the first target value, the order of the decryption information groups is determined, and then, for each decryption information carried in the decryption information group, the subsequent steps of determining the target position corresponding to the decryption position in the target file based on the decryption position carried in the decryption information group are executed.

[0261] In one possible implementation, determining the target location corresponding to the decryption location in the target file based on the decryption location carried in the decryption information group includes:

[0262] If the decryption information group is the first decryption information group, then the first byte of the target file is taken as the target location;

[0263] If the decryption information group is not the first decryption information group, then according to the sorting result, the termination position corresponding to the first candidate decryption information group before the decryption information group is determined; the termination position is determined as the starting position corresponding to the decryption information group, and the target position is determined according to the sub-target value corresponding to the starting position and the decryption position.

[0264] In one possible implementation, if the decryption information group is the last decryption information group, obtaining the file content with the decryption byte length based on the target position includes:

[0265] The content from the target position to the last byte of the target file is determined as the candidate file content;

[0266] If the byte length of the candidate file content does not exceed the decryption byte length, then the candidate file content is determined as the file content;

[0267] If the byte length of the candidate file content exceeds the decryption byte length, then the content of the decryption byte length after the target position is determined, and the content of the decryption byte length is determined as the file content; and the saved second target value is obtained, and the first target value is updated using the second target value; the first byte after the file content is determined as the decryption start position corresponding to the updated first target value; and the content after the file content is decrypted according to the updated first target value and the decryption start position.

[0268] Since the principle of the computer-readable storage medium in solving the problem is similar to that of the file decryption method, the implementation of the computer-readable storage medium can be found in the embodiments of the method, and repeated details will not be repeated.

[0269] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0270] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to this application. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0271] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0272] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0273] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.

Claims

1. A file encryption method, characterized in that, The method includes: Obtain the target file to be encrypted and a pre-configured first target value, wherein the first target value includes at least one sub-target value; wherein the first target value is used to determine the content of the target file to be encrypted, and the sub-target value is used to determine the length of the encrypted bytes of the target file; Obtain the encrypted information corresponding to the saved sub-target value, and determine the encrypted information group, wherein the encrypted information is an encrypted position or an encrypted byte length, and the encrypted information group includes an encrypted position and an encrypted byte length; Based on the encryption location carried in the encryption information group, determine the target location corresponding to the encryption location in the target file, obtain the file content of the encryption byte length based on the target location, and encrypt the file content; The method for determining the first target value includes: Obtain the pre-saved file information of the target file and the encryptor's account ID, wherein the file information includes at least one of the following: file size, file type, and file content in preset bytes; The file information and account ID are sorted in a preset order, and the sorted file information and account ID are encrypted using a preset encryption algorithm to determine a first value. Based on the first value and a pre-saved template of the elliptic curve equation, the target elliptic equation is determined. Obtain the pre-saved second value, and determine the first target value based on the second value and the target ellipse equation; The file content of the preset bytes includes file header information and file footer information; The preset order is the account ID, the file size, the file type, the file header information, and the file footer information.

2. The method according to claim 1, characterized in that, The process of determining the encrypted information corresponding to the sub-target value includes: Determine the position of the sub-target value within the first target value; Based on the pre-saved correspondence between location and encrypted information, the encrypted information corresponding to the sub-target value at the corresponding location is determined. The encrypted information corresponding to the first sub-target value is the length of the encrypted bytes, and the encrypted information corresponding to two adjacent sub-target values ​​is different.

3. The method according to claim 2, characterized in that, The determination of the encrypted information group includes: If the encrypted information is the encrypted information corresponding to the value of the first sub-target, then the encrypted information is determined as an encrypted information group, and the encrypted position corresponding to the encrypted information group is determined as the first byte; Based on the position of the sub-target value within the first target value, the encrypted information corresponding to every two adjacent sub-target values ​​other than the first sub-target value is determined as an encrypted information group.

4. The method according to claim 3, characterized in that, After determining the encrypted information group, and before determining the target location corresponding to the encrypted location in the target file based on the encrypted location carried in the encrypted information group, the method further includes: Based on the position of the corresponding sub-target value in the first target value, the order of the encrypted information groups is determined, and then the subsequent steps of determining the target position corresponding to the encrypted position in the target file are performed for the encrypted information carried in the encrypted information group in turn.

5. The method according to claim 4, characterized in that, The step of determining the target location corresponding to the encrypted location in the target file based on the encrypted location carried in the encrypted information group includes: If the encrypted information group is the first encrypted information group, then the first byte of the target file is taken as the target position; If the encrypted information group is not the first encrypted information group, then according to the sorting result, the termination position corresponding to the first candidate encrypted information group before the encrypted information group is determined; the termination position is determined as the starting position corresponding to the encrypted information group, and the target position is determined according to the starting position and the sub-target value corresponding to the encrypted position.

6. The method according to claim 3, characterized in that, If the encrypted information group is the last encrypted information group, obtaining the file content with the encrypted byte length based on the target position includes: The content from the target position to the last byte of the target file is determined as the candidate file content; If the byte length of the candidate file content does not exceed the encrypted byte length, then the candidate file content is determined as the file content; If the byte length of the candidate file content exceeds the encrypted byte length, then the content of the encrypted byte length after the target position is determined, and the content of the encrypted byte length is determined as the file content; and the saved second target value is obtained, and the first target value is updated using the second target value; the first byte after the file content is determined as the encryption start position corresponding to the updated first target value; and the content after the file content is encrypted according to the updated first target value and the encryption start position.

7. A file decryption method, characterized in that, The method includes: Obtain the target file to be decrypted and a pre-configured first target value, wherein the first target value includes at least one sub-target value; wherein the first target value is used to determine the content of the target file to be encrypted, and the sub-target value is used to determine the length of the encrypted bytes of the target file; Obtain the decryption information corresponding to the saved subtarget value, and determine the decryption information group, wherein the decryption information is a decryption position or a decryption byte length, and the decryption information group includes a decryption position and a decryption byte length; Based on the decryption location carried in the decryption information group, determine the target location corresponding to the decryption location in the target file, obtain the file content of the decryption byte length based on the target location, and decrypt the file content. The method for determining the first target value includes: Obtain the pre-saved file information of the target file and the account ID of the decryptor, wherein the file information includes at least one of the following: file size, file type, and file content in preset bytes; The file information and account ID are sorted in a preset order, and the sorted file information and account ID are decrypted using a preset decryption algorithm to determine a first value. Based on the first value and a pre-saved template of the elliptic curve equation, the target elliptic equation is determined. Obtain the pre-saved second value, and determine the first target value based on the second value and the target ellipse equation; The file content of the preset bytes includes file header information and file footer information; The preset order is the account ID, the file size, the file type, the file header information, and the file footer information.

8. An electronic device, characterized in that, The electronic device includes a processor that executes a computer program stored in a memory to implement the steps of the file encryption method as described in any one of claims 1-6 or the file decryption method as described in claim 7.

9. A computer-readable storage medium, characterized in that, It stores a computer program that, when executed by a processor, implements the steps of the encryption method as described in any one of claims 1-6 or the file decryption method as described in claim 7.

Citation Information

Patent Citations

  • Encryption method, decryption method, device thereof and terminal thereof

    CN105635150A

  • File encryption and decryption method and device, equipment and storage medium

    CN111414635A

  • VR resource safety protection method and terminal capable of reducing space and time

    CN112651038A