Source code encryption and decryption method, device and storage medium
By encrypting the file paths of multiple compilation result files and generating a unique encrypted source code, the problem of low source code encryption reliability in the existing technology is solved, and higher source code security is achieved.
Patent Information
- Application Number
- CN202210812409.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-12
- Publication Date
- 2025-04-08
- Estimated Expiration
- 2042-07-12
AI Technical Summary
In the prior art, the reliability of source code encryption is not high, resulting in insufficient security of source code.
By obtaining the file paths of multiple compilation result files to be encrypted, each compilation result file is encrypted according to the file path, and a different encrypted compilation file is generated, thereby determining the unique encrypted source code. This method uses the file path to generate a cryptographic table, and forward conversion of the compiled result file, increasing the irreversibility of the key and cracking difficulty.
It improves the reliability and security of source code encryption, generates different passwords through different file paths, and increases the difficulty of cracking the encrypted source code.
Smart Images

Figure CN115062279B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a source code encryption and decryption method, device and storage medium. Background Art
[0002] With the continuous development of programming language technology, various programming languages have emerged. Each company also uses the programming language it needs to write source code according to actual conditions, and encrypts the source code after the source code is written to prevent the source code from being attacked by illegal personnel after the application software is generated.
[0003] In the related art, when encrypting source code, most of them adopt code obfuscation, that is, obfuscating the source code according to certain rules so that external users cannot see the real source code, thereby realizing encryption of the source code.
[0004] However, the above-mentioned method of encrypting the source code has the problem that the encryption reliability of the source code is not high, thereby resulting in the problem that the security of the source code is not high. Summary of the invention
[0005] Based on this, it is necessary to provide a source code encryption and decryption method, device and storage medium that can improve the reliability and security of source code encryption in response to the above technical problems.
[0006] In a first aspect, the present application provides a source code encryption method, the method comprising:
[0007] Obtaining file paths of multiple compilation result files to be encrypted; the multiple compilation result files to be encrypted constitute the source code to be encrypted, and different compilation result files correspond to different file paths;
[0008] Encrypt the corresponding compilation result files according to the file paths corresponding to the compilation result files to obtain encrypted compilation files corresponding to the compilation result files;
[0009] According to the encrypted compilation files corresponding to the compilation result files, the encrypted source code corresponding to the source code to be encrypted is determined.
[0010] In this embodiment, since the file paths of the compilation result files are different, the compilation result files are encrypted respectively through different file paths, so that each compilation result file corresponds to a different password, and one compilation result file has one password, thereby increasing the difficulty of cracking / attacking the encrypted source code obtained through each encrypted compilation file, that is, the reliability of encrypting the source code is higher, and the security of the source code is also higher.
[0011] In one embodiment, the above-mentioned encrypting the corresponding compilation result files according to the file paths corresponding to the compilation result files to obtain the encrypted compilation files corresponding to the compilation result files includes:
[0012] Determine, according to the file path corresponding to each compilation result file, an encryption code table corresponding to each compilation result file; the encryption code table includes a plurality of code table elements;
[0013] Each encryption code table is used to perform forward conversion on the corresponding compilation result file to determine the encrypted compilation file corresponding to each compilation result file.
[0014] In this embodiment, the corresponding encryption code table is determined by the file path corresponding to each compilation result file, and the compilation result file corresponding to each encryption code table is used for forward conversion to determine the corresponding encrypted compilation files. In this way, by converting each compilation result file through the encryption code table, the problem of easy theft caused by the key being transmitted with the encrypted source code can be avoided, thereby effectively improving the security of the source code encryption. In addition, each encryption code table includes multiple code table elements, which can increase the difficulty of cracking the encryption code table, that is, further improve the security of the source code encryption.
[0015] In one embodiment, the above-mentioned determining the encryption code table corresponding to each compilation result file according to the file path corresponding to each compilation result file includes:
[0016] Performing a hash operation on the file path of each compilation result file to determine the hash data corresponding to each compilation result file;
[0017] Determine, according to the hash data corresponding to each compilation result file, a plurality of code table elements corresponding to each compilation result file;
[0018] The multiple code table elements corresponding to each compilation result file are filled into the corresponding empty code table respectively to obtain the encryption code table corresponding to each compilation result file; the empty code table has the same length as the encryption code table.
[0019] In this embodiment, a hash operation is performed on the file path of each compilation result file, a corresponding plurality of code table elements are determined according to the determined hash data, and the plurality of code table elements are respectively filled into the corresponding positions of the corresponding empty code table to obtain an encryption code table corresponding to each compilation result file. Here, the encryption code table is calculated by a hash operation. Since the hash data calculated by the hash algorithm has an irreversible property, that is, it cannot be reversed to the original value, the obtained encryption code table has a higher security, so the source code can be effectively protected by the encryption code table.
[0020] In one embodiment, the determining of the plurality of code table elements corresponding to each compilation result file according to the hash data corresponding to each compilation result file includes:
[0021] Performing a calculation operation, the calculation operation comprising: performing four arithmetic operations on hash data corresponding to a compilation result file and the number of times the hash data is used, determining a calculation result corresponding to the compilation result file, and determining a code table element according to the calculation result;
[0022] Execute the above calculation operation repeatedly until a preset number of cycles is reached, and obtain a plurality of code table elements corresponding to the above compilation result file; the preset number of cycles is the same as the length of the encryption code table;
[0023] According to the multiple code table elements corresponding to the compilation result files, multiple code table elements corresponding to each compilation result file are determined.
[0024] In this embodiment, by performing four arithmetic operations on hash data and the number of times the hash data is used and determining code table elements through hash operations, the security of the encryption code table can be further enhanced, thereby further enhancing the security of the source code.
[0025] In one embodiment, performing four arithmetic operations on hash data corresponding to a compilation result file and the number of times the hash data is used to determine the operation result corresponding to the compilation result file includes:
[0026] Performing four arithmetic operations on hash data corresponding to a compilation result file and the number of times the hash data is used to determine the four arithmetic operations results; the above four arithmetic operations are obtained by customizing the four arithmetic operations according to the source code to be encrypted;
[0027] Perform hash operations on the four arithmetic operation results to determine the operation results corresponding to the compilation result file.
[0028] In this embodiment, the four arithmetic operations are user-defined four arithmetic operations, which can increase the difficulty of decompiling, that is, increase the difficulty of cracking, and further enhance the reliability and security of encrypting the source code.
[0029] In one embodiment, determining a code table element according to the calculation result includes:
[0030] Performing a modulo operation on the calculation result and a preset value to determine a remainder corresponding to the calculation result; the preset value is greater than or equal to the length of the encryption code table;
[0031] It is determined whether the remainder exists in the empty code table corresponding to the compilation result file, and if the remainder does not exist, the remainder is used as a code table element.
[0032] In this embodiment, the code table elements are determined by a modulo operation. Since the modulo operation is not allowed, the code table elements and the encrypted code table obtained in this way are more secure, thereby effectively enhancing the security of the source code.
[0033] In one embodiment, the encryption code table is a BASE64 code table based on 64 printable characters, and the length of the BASE64 code table is 66.
[0034] In this embodiment, the encryption code table is a BASE64 code table based on 64 printable characters, and the length of the BASE64 code table is 66, which can make the encrypted source code more suitable for transmission on different platforms and in different languages, and expand the scope of application of the encrypted source code.
[0035] In one embodiment, the method further comprises:
[0036] The encrypted source code and the corresponding decryption method are used to generate a dynamic link library, and the dynamic link library is sent to a user device that needs to use the source code to be encrypted.
[0037] In this embodiment, by sending the encrypted source code and the decrypted dynamic link library to the user device, it is convenient for the user device to obtain the source code for use.
[0038] In a second aspect, the present application also provides a source code decryption method, the method comprising:
[0039] Load the dynamic link library according to the preset loading method, and obtain the encrypted source code and the corresponding decryption method in the dynamic link library;
[0040] Obtain the file paths of multiple encrypted compiled files that constitute the encrypted source code; different encrypted compiled files correspond to different file paths;
[0041] Decrypt the corresponding encrypted compiled files according to the file paths corresponding to the encrypted compiled files, and determine the decrypted compiled files corresponding to the encrypted compiled files;
[0042] According to the decryption compiled files corresponding to the encrypted compiled files, the decrypted source code corresponding to the encrypted source code is determined.
[0043] In this embodiment, since the file paths of the encrypted compiled files are different, each encrypted compiled file can be decrypted using a different file path, so that each encrypted compiled file can be decrypted using a different password, thereby achieving fast and accurate decryption of each encrypted compiled file.
[0044] In one embodiment, the above-mentioned decrypting the corresponding encrypted compiled files according to the file paths corresponding to the encrypted compiled files and determining the decrypted compiled files corresponding to the encrypted compiled files includes:
[0045] Determine the decryption code table corresponding to each encrypted compiled file according to the file path corresponding to each encrypted compiled file; the decryption code table includes multiple code table elements;
[0046] The corresponding encrypted compiled files are reversely converted using each decryption code table to determine the decryption compiled files corresponding to each encrypted compiled file.
[0047] In this embodiment, the corresponding decryption code table is obtained through the file path of the encrypted compiled file, and decrypted, so that the decryption process of each encrypted compiled file can be accurately and quickly implemented, thereby improving the security and efficiency of decryption.
[0048] In one embodiment, the preset loading method is a loading method using a Java virtual machine tool interface.
[0049] In a third aspect, the present application further provides a source code encryption device, the device comprising:
[0050] A first file path acquisition module is used to acquire file paths of a plurality of compilation result files to be encrypted; the plurality of compilation result files to be encrypted constitute the source code to be encrypted, and different compilation result files correspond to different file paths;
[0051] The encrypted file determination module is used to encrypt the corresponding compilation result file according to the file path corresponding to the compilation result file to obtain the encrypted compilation file corresponding to each compilation result file;
[0052] The encrypted source code determination module is used to determine the encrypted source code corresponding to the source code to be encrypted according to the encrypted compilation files corresponding to each compilation result file.
[0053] In a fourth aspect, the present application further provides a source code decryption device, the device comprising:
[0054] The parsing module is used to load the dynamic link library according to a preset loading method, and obtain the encrypted source code and the corresponding decryption method in the dynamic link library;
[0055] The second file path acquisition module is used to acquire the file paths of multiple encrypted compiled files constituting the encrypted source code; different encrypted compiled files correspond to different file paths;
[0056] A decryption file determination module, used to decrypt the corresponding encrypted compiled files according to the file paths corresponding to the encrypted compiled files, and determine the decryption compiled files corresponding to the encrypted compiled files;
[0057] The decryption source code determination module is used to determine the decrypted source code corresponding to the encrypted source code according to the decryption compiled files corresponding to each encrypted compiled file.
[0058] In a fifth aspect, the present application further provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the method of the first aspect when executing the computer program.
[0059] In a sixth aspect, the present application further provides a user device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the method in the second aspect when executing the computer program.
[0060] In a seventh aspect, the present application further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the method of the first aspect are implemented.
[0061] In an eighth aspect, the present application further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the method in the second aspect are implemented.
[0062] In a ninth aspect, the present application further provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the method of the first aspect are implemented.
[0063] In a tenth aspect, the present application further provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the method of the second aspect are implemented.
[0064] The above-mentioned source code encryption and decryption method, device and storage medium encrypt the corresponding compilation result files according to the file paths of the obtained multiple compilation result files to be encrypted, obtain the encrypted compilation files corresponding to each compilation result file, and determine the encrypted source code corresponding to the source code to be encrypted according to the encrypted compilation files corresponding to each compilation result file; wherein, the multiple compilation result files to be encrypted constitute the source code to be encrypted, and different compilation result files correspond to different file paths. In this method, since the file paths of each compilation result file are different, each compilation result file is encrypted through different file paths, so that each compilation result file corresponds to a different password, and one compilation result file and one password are realized, thereby increasing the difficulty of the encrypted source code obtained through each encrypted compilation file to be cracked / attacked, that is, the reliability of encrypting the source code is higher, and the security of the source code is also higher. BRIEF DESCRIPTION OF THE DRAWINGS
[0065] Figure 1 An application environment diagram of a source code encryption method in an embodiment;
[0066] Figure 2 A schematic diagram of a flow chart of a source code encryption method in one embodiment;
[0067] Figure 3 A schematic diagram of a flow chart of a source code encryption method in another embodiment;
[0068] Figure 4 A schematic diagram of a flow chart of a source code encryption method in another embodiment;
[0069] Figure 5 A schematic diagram of a flow chart of a source code encryption method in another embodiment;
[0070] Figure 6 A schematic diagram of a flow chart of a source code encryption method in another embodiment;
[0071] Figure 7 A schematic diagram of a flow chart of a source code encryption method in another embodiment;
[0072] Figure 8 is a structural block diagram of a source code encryption device in an embodiment;
[0073] Fig. 9 is a structural block diagram of a source code decryption device in an embodiment;
[0074] Fig.10 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0075] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0076] The source code encryption and decryption method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Among them, the computer device 102 can communicate with the user device 104. The data storage system can store the data that the computer device 102 needs to process. The data storage system can be integrated on the computer device 102, or it can be placed on the cloud or other network servers. The computer device 102 and the user device 104 can exchange encrypted source code data, etc. In addition, the computer device 102 can be a terminal or a server. When it is a terminal, it can be but not limited to various personal computers, laptops, smart phones, tablets, Internet of Things devices, and portable wearable devices; when it is a server, it can be implemented with an independent server or a server cluster composed of multiple servers. The user device 104 is similar to the computer device 102 and can be a terminal or a server.
[0077] In one embodiment, Figure 2 As shown, a source code encryption method is provided, which is applied to Figure 1 Taking the computer device in the example as an example, the method may include the following steps:
[0078] S202, obtaining file paths of a plurality of compilation result files to be encrypted; the plurality of compilation result files to be encrypted constitute the source code to be encrypted, and different compilation result files correspond to different file paths.
[0079] In this step, generally after the source code to be encrypted of an application software is written, the source code to be encrypted can be compiled first to generate a compiled compressed package, and then the compiled compressed package can be decompressed to obtain multiple compiled result files to be encrypted. Generally, a source code to be encrypted will be compiled and decompressed to obtain multiple compiled result files.
[0080] The source code to be encrypted in this embodiment can be a source code to be encrypted written in Java language, or a source code to be encrypted written in C# language, or a source code to be encrypted written in other languages. Taking the source code to be encrypted written in Java language as an example, after compiling the source code to be encrypted, a product Jar package is generated, and by decompressing the product Jar package, multiple Java compilation result files can be obtained.
[0081] In addition, the file path corresponding to each compilation result file here refers to the package path of each compilation result file in the project, and different compilation result files have different package paths in the project. The project here refers to the project created in the application software when writing the source code to be encrypted. By creating a project and compiling files, the file path of each compilation result file can be obtained. Each compilation result file here can be called a class, such as a .class file in the Java language.
[0082] S204, encrypting the corresponding compilation result files according to the file paths corresponding to the compilation result files, to obtain encrypted compilation files corresponding to the compilation result files.
[0083] In this step, after obtaining the file path corresponding to each compilation result file, the file path of each compilation result file can be used to generate a corresponding key through a preset encryption algorithm, and then the corresponding compilation result file is encrypted using each key to obtain an encrypted file corresponding to each compilation result file, which is recorded as an encrypted compilation file, that is, the corresponding compilation result file is encrypted using the file path corresponding to each compilation result file. The preset encryption algorithm here may include a digest algorithm, a hash algorithm, a hash algorithm, and the like.
[0084] S206, determining the encrypted source code corresponding to the source code to be encrypted according to the encrypted compiled files corresponding to the compiled result files.
[0085] In this step, after obtaining the encrypted compiled files corresponding to each compiled result file, all the encrypted compiled files can be compressed and packaged to obtain the encrypted compressed package, which is recorded as the encrypted source code corresponding to the source code to be encrypted. Taking the source code to be encrypted written in Java language as an example, after encrypting and compressing the compiled result files to be encrypted, an encrypted product Jar package is generated.
[0086] After obtaining the encrypted source code, optionally, the encrypted source code and the corresponding decryption method may be used to generate a dynamic link library, and the dynamic link library may be sent to a user device that needs to use the source code to be encrypted.
[0087] The decryption method here refers to a decryption method corresponding to the encryption method. For example, each compilation result file is encrypted through the file path of each compilation result file, and accordingly, each encrypted compilation file can also be decrypted through the corresponding file path.
[0088] Here, the encrypted source code and the corresponding decryption method can be packaged, and a dynamic link library can be generated and sent to the corresponding user device.
[0089] The dynamic link library here is a way to implement the concept of shared function library in the operating system. The implementation forms are different in different operating systems, such as dll files in Windows systems, so files in Linux / Unix systems, and dylib files in MaxOs systems. The user devices here are generally authorized user devices, that is, legal user devices, so that the source code can be prevented from being copied and used without authorization while ensuring the stable operation of the system, that is, the encryption security of the source code can be further enhanced; in addition, it can be written in multiple programming languages to enhance the functions of the application software corresponding to the source code and simplify project management.
[0090] In the above-mentioned source code encryption method, the corresponding compilation result files are encrypted according to the file paths of the obtained multiple compilation result files to be encrypted, and the encrypted compilation files corresponding to each compilation result file are obtained, and the encrypted source code corresponding to the source code to be encrypted is determined according to the encrypted compilation files corresponding to each compilation result file; wherein, the multiple compilation result files to be encrypted constitute the source code to be encrypted, and different compilation result files correspond to different file paths. In this method, since the file paths of each compilation result file are different, each compilation result file is encrypted through different file paths, so that each compilation result file corresponds to a different password, and one compilation result file and one password are realized, thereby increasing the difficulty of the encrypted source code obtained through each encrypted compilation file to be cracked / attacked, that is, the reliability of encrypting the source code is higher, and the security of the source code is also higher.
[0091] The above embodiment mentioned that the corresponding compiled files can be encrypted through the file paths of the compiled result files. The following embodiment will describe in detail the encryption process.
[0092] In another embodiment, Figure 3 As shown, another source code encryption method is provided. Based on the above embodiment, the above S204 may include the following steps:
[0093] S302, determining an encryption code table corresponding to each compilation result file according to a file path corresponding to each compilation result file; the encryption code table includes a plurality of code table elements.
[0094] In this step, after obtaining the file path corresponding to each compilation result file, each file path can be processed by a preset encryption algorithm to obtain a code table corresponding to each compilation result file, which is recorded as an encryption code table. The encryption code table includes multiple code table elements, and the multiple code table elements in each encryption code table are different from each other, which can increase the difficulty of cracking the encryption code table.
[0095] Optionally, the encryption code table here is a BASE64 code table based on 64 printable characters, and the length of the BASE64 code table is 66. That is, the BASE64 code table includes 66 code table elements, and the 66 code table elements are different from each other. Here, a BASE64 code table with a length of 66 is generated for each compilation result file.
[0096] S304, using each encryption code table to perform forward conversion on the corresponding compilation result file, and determine the encrypted compilation file corresponding to each compilation result file.
[0097] In this step, the general standard BASE64 code table will have an agreed mapping code table. Here, after obtaining the encryption code table corresponding to each compilation result file, taking a compilation result file as an example, the corresponding encryption code table and the standard code table (such as the standard BASE64 code table) can be used for conversion, and the corresponding compilation result file can be forward converted according to the converted result, that is, the compilation result is taken out according to the number of bytes and converted into what letters or numbers, etc., and finally the compiled file after the conversion of the compilation result file can be obtained, that is, the encryption of the compilation result file is completed, and the obtained file is recorded as the encrypted compilation file.
[0098] Afterwards, in this manner, the corresponding compilation result files can be forward converted using the encryption code table corresponding to each compilation result file to obtain the encrypted compilation files corresponding to each compilation result file.
[0099] In this embodiment, the corresponding encryption code table is determined by the file path corresponding to each compilation result file, and the compilation result file corresponding to each encryption code table is used for forward conversion to determine the corresponding encrypted compilation files. In this way, by converting each compilation result file through the encryption code table, the problem of easy theft caused by the key being transmitted with the encrypted source code can be avoided, thereby effectively improving the security of the source code encryption. In addition, each encryption code table includes multiple code table elements, which can increase the difficulty of cracking the encryption code table, that is, further improve the security of the source code encryption. Furthermore, the encryption code table is a BASE64 code table based on 64 printable characters, and the length of the BASE64 code table is 66, which can make the encrypted source code more suitable for transmission on different platforms and in different languages, and expand the scope of application of the encrypted source code.
[0100] The above embodiment mentioned that the corresponding encryption code table can be generated according to the file path of the compilation result file. The following embodiment will describe in detail the process of generating the encryption code table corresponding to each compilation result file.
[0101] In another embodiment, Figure 4 As shown, another source code encryption method is provided. Based on the above embodiment, the above S302 may include the following steps:
[0102] S402, performing a hash operation on the file path of each compilation result file to determine hash data corresponding to each compilation result file.
[0103] A hash algorithm may be used to perform a hash operation on the path of the compilation result file. The hash algorithm here refers to a method of creating a small digital "fingerprint" from any kind of data, such as a summary algorithm, a hash algorithm, and the like.
[0104] After obtaining each compilation result file, taking one compilation result file as an example, a hash operation can be performed on the compilation result file using a hash algorithm to obtain a key seed corresponding to the compilation result file, which is recorded as hash data. The same hash algorithm can be used to perform a hash operation on all compilation result files to obtain a key seed corresponding to each compilation result file, which is recorded as hash data.
[0105] S404: Determine a plurality of code table elements corresponding to each compilation result file according to the hash data corresponding to each compilation result file.
[0106] In this step, after obtaining the hash data corresponding to each compilation result file, optionally, the code table elements corresponding to each compilation result file can be obtained by operating each hash data in the following manner, which can include the following steps A1-A3:
[0107] Step A1, performing a calculation operation, the calculation operation comprising: performing four arithmetic operations on hash data corresponding to a compilation result file and the number of times the hash data is used, determining a calculation result corresponding to the compilation result file, and determining a code table element according to the calculation result.
[0108] Among them, for performing the four arithmetic operations, optionally, the four arithmetic operations can be performed on the hash data corresponding to a compilation result file and the number of times the hash data is used to determine the four arithmetic operations results; the above-mentioned four arithmetic operations are obtained after customizing the four arithmetic operations according to the source code to be encrypted; the four arithmetic operations results are hashed to determine the operation results corresponding to the compilation result file.
[0109] Taking a compilation result file as an example, the corresponding hash data may be a key seed, and the number of times the hash data is used is the number of times the key seed has been used. Specifically, after obtaining the key seed corresponding to the compilation result file, the number of times the key seed has been used can be obtained at the same time, and a custom arithmetic operation is performed on the key seed and the number of times the key seed has been used to obtain the arithmetic operation result. Then, a hash algorithm is used to perform a hash operation on the arithmetic operation result to obtain the operation result corresponding to the arithmetic operation result, that is, the operation result corresponding to the compilation result file is obtained.
[0110] The number of times the key seed has been used here is 0 at the beginning. As the key seed is continuously used, a counter can be used to increase one each time, and finally the number of times the key seed has been used when the key seed is used this time is obtained through the counter.
[0111] The four arithmetic operations here refer to the four arithmetic operations including addition, subtraction, multiplication and division. They are custom arithmetic operations, which are generally customized by the developer corresponding to the source code to be encrypted. That is, different companies and different developers may have different custom arithmetic operations. In this way, when others crack the source code, it will be difficult to know what the custom arithmetic operations are, which will increase the difficulty of decompilation, that is, it will increase the difficulty of being cracked, and further enhance the reliability and security of encrypting the source code.
[0112] After obtaining a calculation result corresponding to a compilation result file, optionally, a modulo operation can be performed on the calculation result and a preset value to determine the remainder corresponding to the calculation result; the above preset value is greater than or equal to the length of the encryption code table; it is determined whether the remainder exists in the empty code table corresponding to the compilation result file, and if the remainder does not exist, the remainder is used as a code table element.
[0113] The preset value here is a value greater than or equal to the length of the encryption code table. For example, if the encryption code table is 66 in length, the preset value here can be any value between 67-256. Preferably, considering the cost and the amount of calculation, the preset value here can be selected as 128, so that each encryption code table can have A16268 variations, and one compilation result file can be kept corresponding to one password, thereby increasing the difficulty of cracking the code table, and further improving the security of encrypting the source code using the encryption code table.
[0114] After obtaining the operation result corresponding to a compilation result file as described above, the operation result can be divided by a preset value and the remainder can be obtained. At the same time, when the elements of the encryption code table are predetermined, an empty code table can be pre-set, and the elements in the empty code table are initially empty, and the remainder can be continuously filled in later. Here, after obtaining the remainder, it can be judged in the empty code table whether the remainder has been occupied, that is, whether the remainder already exists in the empty code table. If it exists, then add one to the remainder and continue to judge whether it has been occupied. If it is still occupied, continue to add one for judgment, and finally take the unoccupied remainder as a code table element.
[0115] Step A2, cyclically executing the above calculation operation until a preset number of cycles is reached, and obtaining a plurality of code table elements corresponding to the above compilation result file; the above preset number of cycles is the same as the length of the encryption code table.
[0116] The preset number of cycles is the same as the length of the encryption code table. For example, if the length of the encryption code table is 66, the preset number of cycles is 66.
[0117] In this step, after obtaining a code table element of the compilation result file, the above step A1 can be returned to execute. Each time the above step A1 is executed, a code table element of the compilation result file will be obtained. By looping the above step A1 and looping it 66 times, 66 code table elements of the compilation result file can be finally obtained, that is, multiple code table elements corresponding to the compilation result file are obtained.
[0118] Step A3: determining a plurality of code table elements corresponding to each compilation result file according to the plurality of code table elements corresponding to the compilation result file.
[0119] Through the above steps A1 and A2, multiple code table elements corresponding to a compilation result file can be obtained. Here, each compilation result file can be calculated according to the above calculation method of one compilation result file, that is, the above steps A1 and A2 are executed, so that multiple code table elements corresponding to each compilation result file can be obtained.
[0120] S406, filling the multiple code table elements corresponding to each compilation result file into the corresponding empty code table respectively, to obtain the encryption code table corresponding to each compilation result file; the empty code table has the same length as the encryption code table.
[0121] In this step, after obtaining multiple code table elements corresponding to each compilation result file, taking one compilation result file as an example, each code table element can be filled into the corresponding position in the empty code table in the order in which each code table element is obtained (for example, filling starts from the first position of the empty code table in sequence), and finally the encryption code table corresponding to the compilation result file can be obtained. All compilation result files are filled in this way, so that the encryption code tables corresponding to all compilation result files can be obtained.
[0122] In this embodiment, by performing a hash operation on the file path of each compilation result file, determining the corresponding multiple code table elements according to the determined hash data, and filling the multiple code table elements into the corresponding positions of the corresponding empty code table, the encryption code table corresponding to each compilation result file is obtained. Here, the encryption code table is calculated by hash operation. Since the hash data calculated by the hash algorithm has an irreversible property, that is, it cannot be reversed back to the original value, the security of the obtained encryption code table is higher, so the source code can be effectively protected by the encryption code table. In addition, by performing four arithmetic operations on the hash data and the number of times the hash data is used and determining the code table elements by hash operation, the security of the encryption code table can be further enhanced, and the security of the source code can be further enhanced. Further, the four arithmetic operations are customized four arithmetic operations, which can increase the difficulty of decompilation, that is, it will increase the difficulty of being cracked, and further enhance the reliability and security of encrypting the source code. Further, the code table elements are determined by the modulus operation. Since the modulus operation is not allowed, the security of the code table elements and the encryption code table obtained in this way is higher, which can effectively enhance the security of the source code.
[0123] The above embodiment introduces the specific process of encrypting the source code to be encrypted, and introduces that after the source code is encrypted to obtain the encrypted source code, the encrypted source code and the decryption method can be used to generate a dynamic link library and send it to the user device. The following embodiment describes the process of how the user device decrypts the encrypted source code.
[0124] In another embodiment, Figure 5 As shown, a source code decryption method is provided. Based on the above embodiment, the method is applied to the above user equipment as an example for description. The above method may include the following steps:
[0125] S502, loading the dynamic link library according to a preset loading method, and obtaining the encrypted source code and the corresponding decryption method in the dynamic link library.
[0126] In this step, after obtaining the dynamic link library, the user device can create a project in the corresponding application software, run the project, and load the dynamic link library using a preset loading method. The dynamic link library can then be parsed to obtain the encrypted source code and the corresponding decryption method.
[0127] Here, the source code to be encrypted written in Java language is taken as an example. Optionally, the preset loading method is the loading method using the Java virtual machine tool interface. Specifically, the encrypted source code obtained is an encrypted product Jar package, and the dynamic link library containing the decryption method is specified in the startup command of the encrypted product Jar package according to the method provided by JVMTI. When the Java virtual machine is started, the Java compilation result file will be loaded through the class loading method of the decryption package. Among them, the Java virtual machine tool interface, that is, the JVMTI tool interface API (Java Virtual Machine Tool Interface), provides the Java virtual machine with a hook (the behavior of monitoring events) for the performance analyzer, which can capture events such as function calls, class loading, unloading, and thread entry and exit. In this way, multiple encrypted compiled files can be parsed from the encrypted product Jar package.
[0128] S504, obtaining file paths of multiple encrypted compiled files constituting the encrypted source code; different encrypted compiled files correspond to different file paths.
[0129] Before obtaining the file path of each encrypted compiled file in this step, it is also possible to determine whether the first 4 bytes of each encrypted compiled file conform to the magic number "0xCAFEBABE" defined in the Java language. If it conforms to the magic number, it is determined that the encrypted compiled file is an encrypted file, and its file path can be subsequently obtained and decrypted; if it does not conform to the magic number, it is determined that the encrypted compiled file is not an encrypted file, and the file can be directly returned to the Java virtual machine. Here, by determining whether the encrypted compiled file is an encrypted file, it is possible to avoid executing the subsequent decryption process for a non-encrypted file, resulting in a waste of resources and an increase in the amount of calculation, thereby saving computing resources.
[0130] In this step, similar to the above S202, the file paths of the multiple encrypted compiled files refer to the package paths of the encrypted compiled files in the project, and different encrypted compiled files have different package paths in the project.
[0131] It should be noted that each encrypted compilation file here corresponds to each of the above-mentioned compilation result files, that is, one encrypted compilation file corresponds to a corresponding compilation result file, and the package path of each encrypted compilation result file in the project is the same as the package path of its corresponding compilation result file in the project, and the acquisition method is also the same as that of the above-mentioned compilation result file, which will not be repeated here.
[0132] S506, decrypting the corresponding encrypted compiled files according to the file paths corresponding to the encrypted compiled files, and determining the decrypted compiled files corresponding to the encrypted compiled files.
[0133] In this step, similar to the above S204, after obtaining the file paths corresponding to the encrypted compiled files, the file paths of the encrypted compiled files can be used to generate corresponding keys through a preset encryption algorithm, and then the corresponding encrypted compiled files are decrypted using the keys to obtain the decrypted files corresponding to the encrypted compiled files, which are recorded as decrypted compiled files, that is, the corresponding encrypted compiled files are decrypted using the file paths corresponding to the encrypted compiled files. The preset encryption algorithms here may include path summary algorithms, hash algorithms, hash algorithms, etc.
[0134] S508, determining the decrypted source code corresponding to the encrypted source code according to the decrypted compiled files corresponding to the encrypted compiled files.
[0135] In this step, after obtaining each decrypted compiled file, each decrypted compiled file can be returned to the Java virtual machine, and at the same time, by combining the decrypted compiled files, the decrypted source code, that is, the original content, can be obtained.
[0136] In the above source code decryption method, the encrypted source code and decryption method are obtained by loading the dynamic link library, and the corresponding encrypted compiled files are decrypted according to the file paths of the obtained multiple encrypted compiled files, and each decrypted compiled file and its decrypted source code are determined; wherein, different encrypted compiled files correspond to different file paths. In this method, since the file paths of each encrypted compiled file are different, each encrypted compiled file can be decrypted by using different file paths, so that each encrypted compiled file can be decrypted using a different password, and each encrypted compiled file can be decrypted quickly and accurately.
[0137] In another embodiment, the above S506 may include the following steps:
[0138] According to the file path corresponding to each encrypted compiled file, the decryption code table corresponding to each encrypted compiled file is determined; the above decryption code table includes multiple code table elements; each decryption code table is used to reversely convert the corresponding encrypted compiled file to determine the decryption compiled file corresponding to each encrypted compiled file.
[0139] The explanation here can refer to the explanation in the above S302-S304. Mainly, after obtaining the decryption code table corresponding to each encrypted compiled file, each decryption code table can be used to reversely convert the corresponding encrypted compiled file, or called inverse conversion, to finally obtain the decrypted compiled file corresponding to each encrypted compiled file.
[0140] In this embodiment, the corresponding decryption code table is obtained through the file path of the encrypted compiled file, and decrypted, so that the decryption process of each encrypted compiled file can be accurately and quickly implemented, thereby improving the security and efficiency of decryption.
[0141] In addition, the process of generating the decryption code table may be similar to the process of generating the encryption code table described above. For details, please refer to the generation process of S402-S406 described above, which will not be repeated here.
[0142] In order to facilitate a more detailed description of the technical solution of the present application, the following uses the open class loading method provided by JVMTI, taking the source code written in Java language as an example, and combines two specific embodiments for explanation. One embodiment is the process of encrypting the source code, and the other embodiment is the process of decrypting the encrypted source code.
[0143] First, we introduce the process of encrypting the source code. Figure 6 As shown, the method may include the following steps:
[0144] S601, compile the source code to generate a product Jar package.
[0145] S602, decompress the product Jar package to obtain multiple compilation result files, and select a decompressed compilation result file as a candidate compilation file.
[0146] S603, obtaining a file path of the candidate compiled file, and performing a hash operation on the file path to obtain a key seed.
[0147] S604, using the key seed and the number of times the key seed has been used to perform a custom arithmetic operation, and then performing a hash operation on the operation result to obtain the operation result.
[0148] S605, divide the operation result by 128 to get the remainder, and determine whether the result has been occupied. If it has been occupied, add 1 to determine whether it has been occupied again, and take the unoccupied remainder and record it in an empty code table.
[0149] S606, repeat steps S604 and S605 66 times to obtain an encryption code table with a length of 66, that is, the custom BASE64 code table corresponding to the candidate compiled file, and use the encryption code table to perform BASE64 forward conversion on the candidate compiled file to obtain the encrypted compiled file corresponding to the candidate compiled file.
[0150] S607, repeating steps S602-S606, encrypting and converting all compilation result files to obtain encrypted compilation files.
[0151] S608, compress and package each encrypted compiled file to obtain an encrypted product Jar package.
[0152] S609: Provide the encrypted product Jar package and the dynamic link library containing the decryption method to the user device.
[0153] Next, we introduce the process of decrypting the encrypted source code. Figure 7 As shown, the method may include the following steps:
[0154] S701, specify the dynamic link library containing the decryption method in the startup command of the in-process Jar package according to the method provided by JVMTI. When the Java virtual machine is started, the Java compilation result file will be loaded through the class loading method of the decryption package, and multiple encrypted compilation files in the dynamic link library will be parsed to obtain.
[0155] S702, selecting a decompressed encrypted compiled file as a candidate decryption file.
[0156] S703, determine whether the first 4 bytes of the candidate decryption file match the magic number "0xCAFEBABE" defined in the Java language. If so, directly respond with the file content of the candidate decryption file; if not, determine that the candidate decryption file is an encrypted file and execute the subsequent decryption process.
[0157] S704, obtaining the file path of the candidate decryption file, and performing a hash operation on the file path to obtain a key seed.
[0158] S705, using the key seed and the number of times the key seed has been used to perform a custom arithmetic operation, and then performing a hash operation on the operation result to obtain the operation result.
[0159] S706, divide the operation result by 128 to get the remainder, and determine whether the result has been occupied. If it has been occupied, add 1 to determine whether it has been occupied again, and take the unoccupied remainder and record it in an empty code table.
[0160] S707, repeat steps S705 and S706 66 times to obtain a decryption code table with a length of 66, that is, a custom BASE64 code table corresponding to the candidate decryption file, and use the decryption code table to perform BASE64 reverse conversion on the candidate decryption file to obtain the decryption compiled file corresponding to the candidate decryption file.
[0161] S708, repeating steps S702-S707, decrypting and converting all the encrypted compiled files, obtaining each decrypted compiled file, and returning each decrypted compiled file to the Java virtual machine to realize the response to the Java virtual machine.
[0162] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0163] Based on the same inventive concept, the embodiment of the present application also provides a source code encryption and decryption device for implementing the source code encryption and decryption method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in one or more source code encryption and decryption device embodiments provided below can refer to the limitations on the source code encryption and decryption method above, and will not be repeated here.
[0164] In one embodiment, Figure 8 As shown, a source code encryption device is provided, comprising: a first file path acquisition module 11, an encrypted file determination module 12 and an encrypted source code determination module 13, wherein:
[0165] The first file path acquisition module 11 is used to acquire the file paths of a plurality of compilation result files to be encrypted; the plurality of compilation result files to be encrypted constitute the source code to be encrypted, and different compilation result files correspond to different file paths;
[0166] The encrypted file determination module 12 is used to encrypt the corresponding compilation result file according to the file path corresponding to the compilation result file, and obtain the encrypted compilation file corresponding to each compilation result file;
[0167] The encrypted source code determination module 13 is used to determine the encrypted source code corresponding to the source code to be encrypted according to the encrypted compilation files corresponding to each compilation result file.
[0168] In another embodiment, another source code encryption device is provided. Based on the above embodiment, the encrypted file determination module 12 may include:
[0169] An encryption code table determination unit is used to determine the encryption code table corresponding to each compilation result file according to the file path corresponding to each compilation result file; the encryption code table includes multiple code table elements;
[0170] The encryption unit is used to use each encryption code table to perform forward conversion on the corresponding compilation result file to determine the encrypted compilation file corresponding to each compilation result file.
[0171] Optionally, the encryption code table is a BASE64 code table based on 64 printable characters, and the length of the BASE64 code table is 66.
[0172] In another embodiment, another source code encryption device is provided. Based on the above embodiment, the encryption code table determination unit may include:
[0173] A hash operation subunit, used to perform a hash operation on the file path of each compilation result file to determine the hash data corresponding to each compilation result file;
[0174] A code table element determination subunit, used to determine a plurality of code table elements corresponding to each compilation result file according to hash data corresponding to each compilation result file;
[0175] The code table element filling subunit is used to fill multiple code table elements corresponding to each compilation result file into the corresponding empty code table to obtain the encryption code table corresponding to each compilation result file; the empty code table has the same length as the encryption code table.
[0176] Optionally, the code table element determination subunit is specifically used to perform a calculation operation, which includes: performing four arithmetic operations on hash data corresponding to a compilation result file and the number of times the hash data is used to determine the calculation result corresponding to the compilation result file, and determining a code table element according to the calculation result; looping the above-mentioned calculation operation until a preset number of loops is reached to obtain multiple code table elements corresponding to the compilation result file; the preset number of loops is the same as the length of the encryption code table; and determining multiple code table elements corresponding to each compilation result file according to the multiple code table elements corresponding to the compilation result file.
[0177] Optionally, the above-mentioned code table element determination subunit is specifically used to perform four arithmetic operations on hash data corresponding to a compilation result file and the number of times the hash data is used to determine the results of the four arithmetic operations; the above-mentioned four arithmetic operations are obtained after customizing the four arithmetic operations according to the source code to be encrypted; hash operations are performed on the results of the four arithmetic operations to determine the operation results corresponding to the compilation result file.
[0178] Optionally, the above-mentioned code table element determination subunit is specifically used to perform a modulo operation on the calculation result and a preset numerical value to determine the remainder corresponding to the calculation result; the above-mentioned preset numerical value is greater than or equal to the length of the encryption code table; it is determined whether the remainder exists in the empty code table corresponding to the compilation result file, and if the remainder does not exist, the remainder is used as a code table element.
[0179] In another embodiment, another source code encryption device is provided. Based on the above embodiment, the above device may also include: a sending module, which is used to generate a dynamic link library from the encrypted source code and the corresponding decryption method, and send the dynamic link library to a user device that needs to use the source code to be encrypted.
[0180] In another embodiment, another source code decryption device is provided, such as Fig. 9 As shown, based on the above embodiment, the device may include:
[0181] The parsing module 21 is used to load the dynamic link library according to a preset loading method, and obtain the encrypted source code and the corresponding decryption method in the dynamic link library;
[0182] The second file path acquisition module 22 is used to acquire the file paths of multiple encrypted compiled files constituting the encrypted source code; different encrypted compiled files correspond to different file paths;
[0183] The decryption file determination module 23 is used to decrypt the corresponding encrypted compiled files according to the file paths corresponding to the encrypted compiled files, and determine the decryption compiled files corresponding to the encrypted compiled files;
[0184] The decryption source code determination module 24 is used to determine the decrypted source code corresponding to the encrypted source code according to the decryption compiled files corresponding to each encrypted compiled file.
[0185] Optionally, the decrypted file determination module may include:
[0186] A decryption code table determining unit, used to determine a decryption code table corresponding to each encrypted compiled file according to the file path corresponding to each encrypted compiled file; the decryption code table includes a plurality of code table elements;
[0187] The decryption unit is used to use each decryption code table to reversely convert the corresponding encrypted compiled files to determine the decrypted compiled files corresponding to each encrypted compiled file.
[0188] Optionally, the above-mentioned preset loading method is a loading method using a Java virtual machine tool interface.
[0189] Each module in the above source code encryption device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0190] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Fig.10 As shown. The computer device includes a processor, a memory, a communication interface, a display screen and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be achieved through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a source code encryption method is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covered on the display screen, or a key, trackball or touchpad set on the computer device housing, or an external keyboard, touchpad or mouse, etc.
[0191] Those skilled in the art will understand that Fig.10 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0192] In one embodiment, a user device is provided. For the structural composition of the user device, reference may be made to the structural composition of the above-mentioned computer device, which will not be described in detail here.
[0193] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:
[0194] Obtain file paths of multiple compilation result files to be encrypted; the multiple compilation result files to be encrypted constitute source code to be encrypted, and different compilation result files correspond to different file paths; encrypt corresponding compilation result files according to the file paths corresponding to the compilation result files to obtain encrypted compilation files corresponding to each compilation result file; determine the encrypted source code corresponding to the source code to be encrypted according to the encrypted compilation files corresponding to each compilation result file.
[0195] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0196] According to the file path corresponding to each compilation result file, the encryption code table corresponding to each compilation result file is determined; the encryption code table includes multiple code table elements; each encryption code table is used to perform forward conversion on the corresponding compilation result file to determine the encrypted compilation file corresponding to each compilation result file.
[0197] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0198] A hash operation is performed on the file path of each compilation result file to determine the hash data corresponding to each compilation result file; based on the hash data corresponding to each compilation result file, a plurality of code table elements corresponding to each compilation result file are determined; the plurality of code table elements corresponding to each compilation result file are respectively filled into the corresponding empty code table to obtain the encryption code table corresponding to each compilation result file; the empty code table has the same length as the encryption code table.
[0199] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0200] Executing a calculation operation, the calculation operation comprising: performing four arithmetic operations on hash data corresponding to a compilation result file and the number of times the hash data is used, determining a calculation result corresponding to the above compilation result file, and determining a code table element according to the calculation result; looping the above calculation operation until a preset number of loops is reached to obtain a plurality of code table elements corresponding to the above compilation result file; the preset number of loops is the same as the length of the encryption code table; and determining a plurality of code table elements corresponding to each compilation result file according to the plurality of code table elements corresponding to the above compilation result file.
[0201] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0202] Performing four arithmetic operations on hash data corresponding to a compilation result file and the number of times the hash data is used to determine the results of the four arithmetic operations; the above four arithmetic operations are obtained by customizing the four arithmetic operations according to the source code to be encrypted; performing hash operations on the results of the four arithmetic operations to determine the results of the operations corresponding to the compilation result file.
[0203] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0204] Perform a modulo operation on the calculation result and a preset value to determine the remainder corresponding to the calculation result; the above preset value is greater than or equal to the length of the encryption code table; determine whether the remainder exists in the empty code table corresponding to the compilation result file, and if the remainder does not exist, use the remainder as a code table element.
[0205] In one embodiment, the encryption code table is a BASE64 code table based on 64 printable characters, and the length of the BASE64 code table is 66.
[0206] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0207] The encrypted source code and the corresponding decryption method are used to generate a dynamic link library, and the dynamic link library is sent to a user device that needs to use the source code to be encrypted.
[0208] In one embodiment, a user equipment is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the following steps are implemented:
[0209] The dynamic link library is loaded according to a preset loading method to obtain the encrypted source code and the corresponding decryption method in the dynamic link library; the file paths of multiple encrypted compiled files constituting the encrypted source code are obtained; different encrypted compiled files correspond to different file paths; the corresponding encrypted compiled files are decrypted according to the file paths corresponding to the encrypted compiled files to determine the decrypted compiled files corresponding to each encrypted compiled file; the decrypted source code corresponding to the encrypted source code is determined according to the decrypted compiled files corresponding to each encrypted compiled file.
[0210] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0211] According to the file path corresponding to each encrypted compiled file, the decryption code table corresponding to each encrypted compiled file is determined; the above decryption code table includes multiple code table elements; each decryption code table is used to reversely convert the corresponding encrypted compiled file to determine the decryption compiled file corresponding to each encrypted compiled file.
[0212] In one embodiment, the preset loading method is a loading method using a Java virtual machine tool interface.
[0213] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0214] Obtain file paths of multiple compilation result files to be encrypted; the multiple compilation result files to be encrypted constitute source code to be encrypted, and different compilation result files correspond to different file paths; encrypt corresponding compilation result files according to the file paths corresponding to the compilation result files to obtain encrypted compilation files corresponding to each compilation result file; determine the encrypted source code corresponding to the source code to be encrypted according to the encrypted compilation files corresponding to each compilation result file.
[0215] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0216] According to the file path corresponding to each compilation result file, the encryption code table corresponding to each compilation result file is determined; the encryption code table includes multiple code table elements; each encryption code table is used to perform forward conversion on the corresponding compilation result file to determine the encrypted compilation file corresponding to each compilation result file.
[0217] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0218] A hash operation is performed on the file path of each compilation result file to determine the hash data corresponding to each compilation result file; based on the hash data corresponding to each compilation result file, a plurality of code table elements corresponding to each compilation result file are determined; the plurality of code table elements corresponding to each compilation result file are respectively filled into the corresponding empty code table to obtain the encryption code table corresponding to each compilation result file; the empty code table has the same length as the encryption code table.
[0219] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0220] Executing a calculation operation, the calculation operation comprising: performing four arithmetic operations on hash data corresponding to a compilation result file and the number of times the hash data is used, determining a calculation result corresponding to the above compilation result file, and determining a code table element according to the calculation result; looping the above calculation operation until a preset number of loops is reached to obtain a plurality of code table elements corresponding to the above compilation result file; the preset number of loops is the same as the length of the encryption code table; and determining a plurality of code table elements corresponding to each compilation result file according to the plurality of code table elements corresponding to the above compilation result file.
[0221] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0222] Performing four arithmetic operations on hash data corresponding to a compilation result file and the number of times the hash data is used to determine the results of the four arithmetic operations; the above four arithmetic operations are obtained by customizing the four arithmetic operations according to the source code to be encrypted; performing hash operations on the results of the four arithmetic operations to determine the results of the operations corresponding to the compilation result file.
[0223] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0224] Perform a modulo operation on the calculation result and a preset value to determine the remainder corresponding to the calculation result; the above preset value is greater than or equal to the length of the encryption code table; determine whether the remainder exists in the empty code table corresponding to the compilation result file, and if the remainder does not exist, use the remainder as a code table element.
[0225] In one embodiment, the encryption code table is a BASE64 code table based on 64 printable characters, and the length of the BASE64 code table is 66.
[0226] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0227] The encrypted source code and the corresponding decryption method are used to generate a dynamic link library, and the dynamic link library is sent to a user device that needs to use the source code to be encrypted.
[0228] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0229] The dynamic link library is loaded according to a preset loading method to obtain the encrypted source code and the corresponding decryption method in the dynamic link library; the file paths of multiple encrypted compiled files constituting the encrypted source code are obtained; different encrypted compiled files correspond to different file paths; the corresponding encrypted compiled files are decrypted according to the file paths corresponding to the encrypted compiled files to determine the decrypted compiled files corresponding to each encrypted compiled file; the decrypted source code corresponding to the encrypted source code is determined according to the decrypted compiled files corresponding to each encrypted compiled file.
[0230] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0231] According to the file path corresponding to each encrypted compiled file, the decryption code table corresponding to each encrypted compiled file is determined; the above decryption code table includes multiple code table elements; each decryption code table is used to reversely convert the corresponding encrypted compiled file to determine the decryption compiled file corresponding to each encrypted compiled file.
[0232] In one embodiment, the preset loading method is a loading method using a Java virtual machine tool interface.
[0233] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:
[0234] Obtain file paths of multiple compilation result files to be encrypted; the multiple compilation result files to be encrypted constitute source code to be encrypted, and different compilation result files correspond to different file paths; encrypt corresponding compilation result files according to the file paths corresponding to the compilation result files to obtain encrypted compilation files corresponding to each compilation result file; determine the encrypted source code corresponding to the source code to be encrypted according to the encrypted compilation files corresponding to each compilation result file.
[0235] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0236] According to the file path corresponding to each compilation result file, the encryption code table corresponding to each compilation result file is determined; the encryption code table includes multiple code table elements; each encryption code table is used to perform forward conversion on the corresponding compilation result file to determine the encrypted compilation file corresponding to each compilation result file.
[0237] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0238] A hash operation is performed on the file path of each compilation result file to determine the hash data corresponding to each compilation result file; based on the hash data corresponding to each compilation result file, a plurality of code table elements corresponding to each compilation result file are determined; the plurality of code table elements corresponding to each compilation result file are respectively filled into the corresponding empty code table to obtain the encryption code table corresponding to each compilation result file; the empty code table has the same length as the encryption code table.
[0239] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0240] Executing a calculation operation, the calculation operation comprising: performing four arithmetic operations on hash data corresponding to a compilation result file and the number of times the hash data is used, determining a calculation result corresponding to the above compilation result file, and determining a code table element according to the calculation result; looping the above calculation operation until a preset number of loops is reached to obtain a plurality of code table elements corresponding to the above compilation result file; the preset number of loops is the same as the length of the encryption code table; and determining a plurality of code table elements corresponding to each compilation result file according to the plurality of code table elements corresponding to the above compilation result file.
[0241] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0242] Performing four arithmetic operations on hash data corresponding to a compilation result file and the number of times the hash data is used to determine the results of the four arithmetic operations; the above four arithmetic operations are obtained by customizing the four arithmetic operations according to the source code to be encrypted; performing hash operations on the results of the four arithmetic operations to determine the results of the operations corresponding to the compilation result file.
[0243] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0244] Perform a modulo operation on the calculation result and a preset value to determine the remainder corresponding to the calculation result; the above preset value is greater than or equal to the length of the encryption code table; determine whether the remainder exists in the empty code table corresponding to the compilation result file, and if the remainder does not exist, use the remainder as a code table element.
[0245] In one embodiment, the encryption code table is a BASE64 code table based on 64 printable characters, and the length of the BASE64 code table is 66.
[0246] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0247] The encrypted source code and the corresponding decryption method are used to generate a dynamic link library, and the dynamic link library is sent to a user device that needs to use the source code to be encrypted.
[0248] In one embodiment, a computer program product is provided, comprising a computer program, which, when executed by a processor, implements the following steps:
[0249] The dynamic link library is loaded according to a preset loading method to obtain the encrypted source code and the corresponding decryption method in the dynamic link library; the file paths of multiple encrypted compiled files constituting the encrypted source code are obtained; different encrypted compiled files correspond to different file paths; the corresponding encrypted compiled files are decrypted according to the file paths corresponding to the encrypted compiled files to determine the decrypted compiled files corresponding to each encrypted compiled file; the decrypted source code corresponding to the encrypted source code is determined according to the decrypted compiled files corresponding to each encrypted compiled file.
[0250] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0251] According to the file path corresponding to each encrypted compiled file, the decryption code table corresponding to each encrypted compiled file is determined; the above decryption code table includes multiple code table elements; each decryption code table is used to reversely convert the corresponding encrypted compiled file to determine the decryption compiled file corresponding to each encrypted compiled file.
[0252] In one embodiment, the preset loading method is a loading method using a Java virtual machine tool interface.
[0253] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.
[0254] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0255] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0256] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A source code encryption method, characterized in that: The method comprises: Obtaining file paths of multiple compilation result files to be encrypted; the multiple compilation result files to be encrypted constitute the source code to be encrypted, and different compilation result files correspond to different file paths; Encrypting the corresponding compilation result files according to the file paths corresponding to the compilation result files to obtain encrypted compilation files corresponding to the compilation result files, wherein the encrypted compilation files are obtained according to the encryption code tables corresponding to the compilation result files, wherein the encryption code tables are determined according to a plurality of code table elements corresponding to the compilation result files, and the plurality of code table elements corresponding to the compilation result files are determined according to the hash numbers corresponding to the compilation result files; Determining the encrypted source code corresponding to the source code to be encrypted according to the encrypted compiled files corresponding to the compiled result files; Determining, according to the hash data corresponding to each of the compilation result files, a plurality of code table elements corresponding to each of the compilation result files, including: Performing a calculation operation, the calculation operation comprising: performing four arithmetic operations on the hash data corresponding to a compilation result file and the number of times the hash data is used, determining a calculation result corresponding to the compilation result file, and determining a code table element according to the calculation result; Executing the calculation operation in a loop until a preset number of loops is reached, thereby obtaining a plurality of code table elements corresponding to the compilation result file; the preset number of loops is the same as the length of the encryption code table; According to the multiple code table elements corresponding to the compilation result files, multiple code table elements corresponding to each of the compilation result files are determined.
2. The method according to claim 1, characterized in that The step of encrypting the corresponding compilation result files according to the file paths corresponding to the compilation result files to obtain encrypted compilation files corresponding to the compilation result files includes: Determine, according to the file path corresponding to each of the compilation result files, an encryption code table corresponding to each of the compilation result files; the encryption code table includes a plurality of code table elements; Each of the encryption code tables is used to perform forward conversion on the corresponding compilation result file to determine the encrypted compilation file corresponding to each of the compilation result files.
3. The method according to claim 2, characterized in that The step of determining, according to the file path corresponding to each of the compilation result files, an encryption code table corresponding to each of the compilation result files, comprises: Performing a hash operation on the file path of each of the compilation result files to determine hash data corresponding to each of the compilation result files; Determining, according to the hash data corresponding to each of the compilation result files, a plurality of code table elements corresponding to each of the compilation result files; The multiple code table elements corresponding to each of the compilation result files are filled into the corresponding empty code table respectively to obtain the encryption code table corresponding to each of the compilation result files; the empty code table has the same length as the encryption code table.
4. The method according to claim 3, characterized in that: The performing four arithmetic operations on the hash data corresponding to one of the compilation result files and the number of times the hash data is used to determine the operation result corresponding to the compilation result file includes: Performing four arithmetic operations on the hash data and the number of times the hash data is used corresponding to a compilation result file to determine the four arithmetic operations results; the four arithmetic operations are obtained by customizing the four arithmetic operations according to the source code to be encrypted; A hash operation is performed on the four arithmetic operation results to determine the operation results corresponding to the compilation result file.
5. The method according to claim 4, characterized in that The determining a code table element according to the operation result includes: Performing a modulo operation on the calculation result and a preset value to determine a remainder corresponding to the calculation result; the preset value is greater than or equal to the length of the encryption code table; It is determined whether the remainder exists in an empty code table corresponding to the compilation result file, and when the remainder does not exist, the remainder is used as a code table element.
6. The method according to claim 1, characterized in that The method further comprises: The encrypted source code and the corresponding decryption method are used to generate a dynamic link library, and the dynamic link library is sent to a user device that needs to use the source code to be encrypted.
7. A source code decryption method, characterized in that: The method comprises: Loading a dynamic link library according to a preset loading method, obtaining an encrypted source code and a corresponding decryption method in the dynamic link library; Obtaining file paths of multiple encrypted compiled files constituting the encrypted source code; different encrypted compiled files correspond to different file paths; Decrypting the corresponding encrypted compiled files according to the file paths corresponding to the encrypted compiled files, and determining the decrypted compiled files corresponding to the encrypted compiled files; Determining the decrypted source code corresponding to the encrypted source code according to the decrypted compiled files corresponding to the encrypted compiled files; Wherein, the encrypted source code is obtained according to any one of the methods of claims 1 to 6.
8. The method according to claim 7, characterized in that The decrypting the corresponding encrypted compiled files according to the file paths corresponding to the encrypted compiled files, and determining the decrypted compiled files corresponding to the encrypted compiled files, comprises: According to the file path corresponding to the encrypted compiled file, a decryption code table corresponding to the encrypted compiled file is determined; the decryption code table includes a plurality of code table elements; the corresponding encrypted compiled file is reversely converted using the decryption code table to determine the decryption compiled file corresponding to the encrypted compiled file.
9. A device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 8 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
Ciphertext generation method, ciphertext decryption method and encryption / decryption device
CN103873250A
Cloud OS Java source code protection method
CN104268444A
Resource protection method and device and resource reading method and device for application program
CN114297589A