Python source code packaging method, device, equipment and readable storage medium

By compiling the Python source code into a binary file and generating a cube file using signature and encryption technology, the problem of not being able to protect Python source code in the existing technology is solved, and the dual protection of the source code and user-side verification and decryption are realized.

CN114722358BActive Publication Date: 2025-03-141DATA TECH SHANGHAI CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210335086.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-31
Publication Date
2025-03-14
Estimated Expiration
2042-03-31

AI Technical Summary

Technical Problem

The Python source code cannot be effectively protected in the prior art, resulting in users tampering with the source code and thus unable to use it normally.

Method used

Generate runnable cube files by compiling Python source code into binary files and signing and encrypting the binary files using signature algorithms and encryption methods. This method implements dual protection of Python source code.

Benefits of technology

It effectively protects the Python source code, prevents tampering, and ensures the integrity and availability of the source code through signature verification and decryption on the user side.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114722358B_ABST
    Figure CN114722358B_ABST
Patent Text Reader

Abstract

The present application discloses a python source code packaging method, device, equipment and readable storage medium, the method comprising: obtaining an executable python source code, and compiling the python source code into a binary file; obtaining a signature algorithm, and using the signature algorithm to sign the binary file, obtaining signature information, and writing the signature information and signature algorithm into a newly created cube file; obtaining an encryption method, and obtaining an encryption key corresponding to the encryption method, and writing the encryption method into a cube file; using the encryption method and the encryption key, encrypting the binary file to obtain a ciphertext; writing the ciphertext into a cube file to obtain an executable cube file. It can be seen that the present application verifies that the python source code read by the user has not been modified through signature information and signature algorithms, and realizes double protection of the python source code through encryption and compilation. In addition, after the python source code of the development product is packaged into a cube file using the present application, the success rate of installing the development product is improved, and the flexibility of packaging the python source code is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of Internet technology, and more specifically, to a Python source code packaging method, device, equipment and readable storage medium. Background Art

[0002] As an interpreted language, Python programming language has been widely used in product development in various fields due to its high development efficiency.

[0003] Products developed using the Python programming language need to be packaged and released in the Python source code corresponding to the product after the product is released. The commonly used Python source code packaging solution in the prior art is to directly compress the Python source code and package the Python source code by compression. However, the Python source code packaging solution in the prior art has some defects that cannot be ignored. Due to the open source nature of the Python parser, after the Python source code developer directly compresses the Python source code and releases it to the user, the security of the Python source code cannot be guaranteed, and the user may even tamper with the Python source code, so that the tampered Python source code can no longer be used. Therefore, how to protect the Python source code on the basis of the Python source code has become the focus of attention of various technicians using the Python language.

[0004] In summary, there is an urgent need for a Python source code packaging method to solve the problem that the Python source code cannot be protected in the prior art. Summary of the invention

[0005] In view of this, the present application provides a Python source code packaging method, device, equipment and readable storage medium to solve the problem that Python source code cannot be protected in the prior art.

[0006] In order to achieve the above objectives, the proposed solution is as follows:

[0007] A python source code packaging method, including:

[0008] Obtain executable Python source code and compile the Python source code into a binary file;

[0009] Obtain a signature algorithm, and use the signature algorithm to sign the binary file to obtain signature information, and write the signature information and the signature algorithm into the newly created cube file;

[0010] Obtain an encryption method, obtain an encryption key corresponding to the encryption method, and write the encryption method into the cube file;

[0011] Encrypt the binary file using the encryption method and the encryption key to obtain a ciphertext;

[0012] The ciphertext is written into the cube file to obtain an executable cube file.

[0013] Optionally, obtaining an encryption key corresponding to the encryption method and writing the encryption method into the cube file includes:

[0014] Get hidden methods;

[0015] Obtaining an encryption key corresponding to the encryption method, and hiding the encryption method using the hiding method to obtain the hidden encryption method;

[0016] The hidden encryption method is written into the cube file.

[0017] Optionally, after obtaining the hiding method, the method further includes:

[0018] Obtaining a decryption key corresponding to the encryption method;

[0019] The decryption key is hidden by using the hiding method to obtain the hidden decryption key;

[0020] The hidden decryption key is written into the cube file.

[0021] Optionally, after obtaining the hiding method, the method further includes:

[0022] Write the hidden mode at the setting byte of the cube file;

[0023] Randomly select one or more target hiding methods other than the hiding method from a preset hiding method library;

[0024] The target hiding mode is written into the remaining bytes of the cube file except the set bytes.

[0025] Optionally, before using the encryption method and the encryption key to encrypt the binary file, the method further includes:

[0026] Obtain the developer information and current timestamp of the Python source code, and write the developer information and the current timestamp into the cube file;

[0027] The step of encrypting the binary file using the encryption method and the encryption key to obtain a ciphertext includes:

[0028] The binary file is encrypted using the encryption method, the encryption key, the developer information and the current timestamp to obtain a ciphertext.

[0029] Optionally, the Python source code includes various modules;

[0030] Signing the binary file using the signature algorithm to obtain signature information, and writing the signature information and the signature algorithm into the newly created cube file, including:

[0031] Signing each module in the binary file using the signature algorithm to obtain signature information of each module;

[0032] Write the signature algorithm and the signature information of each module into the newly created cube file according to the module;

[0033] The binary file is encrypted using the encryption method, the encryption key, the developer information and the current timestamp to obtain a ciphertext, including:

[0034] Encrypting each module of the binary file using the encryption method, the encryption key, the developer information and the current timestamp to obtain ciphertext of each module;

[0035] Writing the ciphertext into the cube file includes:

[0036] The ciphertext of each module is written into the cube file according to the module.

[0037] Optionally, the method further includes: writing a custom file format tag header into the cube file.

[0038] A python source code packaging device, comprising:

[0039] A compilation unit, used to obtain executable Python source code and compile the Python source code into a binary file;

[0040] A signature unit, used to obtain a signature algorithm, and use the signature algorithm to sign the binary file to obtain signature information, and write the signature information and the signature algorithm into a newly created cube file;

[0041] An acquiring unit, used for acquiring an encryption method and an encryption key corresponding to the encryption method, and writing the encryption method into the cube file;

[0042] An encryption unit, used to encrypt the binary file using the encryption method and the encryption key to obtain a ciphertext;

[0043] The writing unit is used to write the ciphertext into the cube file to obtain an executable cube file.

[0044] A python source code packaging device, comprising a memory and a processor;

[0045] The memory is used to store programs;

[0046] The processor is used to execute the program to implement each step of the above-mentioned Python source code packaging method.

[0047] A readable storage medium stores a computer program thereon, and when the computer program is executed by a processor, the steps of the above-mentioned Python source code packaging method are implemented.

[0048] It can be seen from the above technical solutions that the Python source code packaging method provided by the present application can obtain an executable Python source code and compile the Python source code into a binary file, so that the user-readable Python source code is compiled into a user-unreadable binary file; a signature algorithm can be obtained, and the binary file can be signed using the signature algorithm to obtain signature information, and the signature information and the signature algorithm can be written into a newly created cube file; an encryption method can be obtained, and an encryption key corresponding to the encryption method can be obtained, and the encryption method can be written into the cube file; the binary file can be encrypted using the encryption method and the encryption key to obtain a ciphertext, so that the binary file can be further converted into a ciphertext through encryption to achieve double protection of the Python source code; the ciphertext can be written into the cube file to obtain an executable cube file, so that when the user reads the cube file, the ciphertext can be decrypted using the encryption method recorded in the cube file to obtain a binary file corresponding to the ciphertext, and then the binary file corresponding to the ciphertext can be signed using the signature algorithm recorded in the cube file to obtain the signature information corresponding to the ciphertext. Compare the signature information with the signature information in the cube file. If they are consistent, it proves that the ciphertext has not been modified, and the binary file can be run to realize the function of running the Python source code. It can be seen that this application verifies that the Python source code read by the user has not been modified through signature information and signature algorithm, and realizes double protection of the Python source code through encryption and compilation.

[0049] In addition, since there are not many requirements for the operating environment when using cube files and the versions of multiple cube files are not required to be consistent, after using this application to package the Python source code corresponding to the development product into a cube file, when the user installs the development product, there are not many requirements for the user's operating environment, which improves the success rate of installing the development product, does not require the versions of the cube files corresponding to the development product to be consistent, and improves the flexibility of packaging Python source code. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.

[0051] Figure 1 A flow chart of a python source code packaging method disclosed in this application;

[0052] Figure 2 This is a structural block diagram of a Python source code packaging device disclosed in this application;

[0053] Figure 3 The hardware structure block diagram of a Python source code packaging device disclosed in an embodiment of the present application. DETAILED DESCRIPTION

[0054] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0055] The Python source code packaging method provided by the present application can be applied in various fields. For example, in the development environment of the live broadcast field, the Python source code corresponding to the live broadcast software is packaged, and the packaged Python source code is published to the client of each user, so that each user can use the live broadcast software through the corresponding client; it can also be applied to the development of mobile games and online games, the Python source code corresponding to the mobile games or online games is packaged, and the packaged Python source code is published to the client of each user, so that each user can use the mobile games or online games through the corresponding client.

[0056] Next, combine Figure 1The Python source code packaging method of this application is introduced in detail, including the following steps:

[0057] Step S1, obtain executable Python source code, and compile the Python source code into a binary file.

[0058] Specifically, you can obtain the executable Python source code that needs to be packaged, and directly compile the obtained Python source code into a binary file.

[0059] Step S2: Obtain a signature algorithm, and use the signature algorithm to sign the binary file to obtain signature information, and write the signature information and the signature algorithm into a newly created cube file.

[0060] Specifically, a signature algorithm may be randomly selected from a preset signature algorithm library, and the binary file may be signed using the selected signature algorithm to obtain signature information.

[0061] Among them, using the same signature algorithm to sign binary files with the same content will result in the same signature information. If the contents of the binary files are different, it is impossible to obtain the same signature information even if the same signature algorithm is used.

[0062] The signature algorithm library may include security algorithms such as SHA-256, SHA-384, and SHA-512.

[0063] You can create a new cube file.

[0064] Step S3: Obtain an encryption method, obtain an encryption key corresponding to the encryption method, and write the encryption method into the cube file.

[0065] Specifically, an encryption method may be randomly selected from a preset encryption library, and an encryption key corresponding to the encryption method may be obtained.

[0066] The encryption library can store the algorithms of various encryption methods, as well as the encryption key and decryption key corresponding to each encryption method. The encryption method algorithms can include: symmetric encryption algorithms and asymmetric encryption algorithms. Among them, symmetric encryption algorithms include DES algorithm, AES-128, AES-192 and AES-256, etc., and asymmetric encryption algorithms include DSA algorithm and RSA algorithm, etc.

[0067] Step S4: Use the encryption method and the encryption key to encrypt the binary file to obtain a ciphertext.

[0068] Specifically, the obtained encryption method and encryption key may be used to encrypt the binary file to obtain a ciphertext corresponding to the binary file.

[0069] The user's client can also store the encryption library in order to read the ciphertext. The cube file stores the encryption method, and the client can obtain the decryption key corresponding to the encryption method from the encryption library to decrypt the ciphertext and obtain the binary file before encryption.

[0070] Step S5: Write the ciphertext into the cube file to obtain an executable cube file.

[0071] Specifically, the generated ciphertext is written into a cube file to obtain a cube file containing the ciphertext.

[0072] After obtaining the cube file containing the ciphertext, the user's client can decrypt the ciphertext in the cube file to obtain a binary file, and then run the binary file.

[0073] It can be seen from the above technical solution that the Python source code packaging method provided in the embodiment of the present application can obtain an executable Python source code and compile the Python source code into a binary file, so that the user-readable Python source code is compiled into a user-unreadable binary file; the signature algorithm can be obtained, and the binary file is signed using the signature algorithm to obtain signature information, and the signature information and the signature algorithm are written into the newly created cube file; the encryption method can be obtained, and the encryption key corresponding to the encryption method can be obtained, and the encryption method is written into the cube file; the encryption method and the encryption key can be used to encrypt the binary file to obtain a ciphertext, so that the binary file is further converted into a ciphertext through encryption to achieve double protection of the Python source code; the ciphertext can be written into the cube file to obtain an executable cube file, so that when the user reads the cube file, the encryption method recorded in the cube file can be used to decrypt the ciphertext to obtain a binary file corresponding to the ciphertext, and then the signature algorithm recorded in the cube file can be used to sign the binary file corresponding to the ciphertext to obtain the signature information corresponding to the ciphertext. Compare the signature information with the signature information in the cube file. If they are consistent, it proves that the ciphertext has not been modified, and the binary file can be run to realize the function of running the python source code. It can be seen that this application verifies that the python source code read by the user has not been modified through the signature information and signature algorithm, and realizes the double protection of the python source code through encryption and compilation. The decrypted binary file is not human-readable, which strengthens the protection of the python source code, but the decrypted binary file can be run.

[0074] In addition, since there are not many requirements for the operating environment when using cube files and the versions of multiple cube files are not required to be consistent, after using this application to package the Python source code corresponding to the development product into a cube file, when the user installs the development product, there are not many requirements for the user's operating environment, which improves the success rate of installing the development product, does not require the versions of the cube files corresponding to the development product to be consistent, and improves the flexibility of packaging Python source code.

[0075] In addition, in this application, the encryption method can be randomly selected, not uniform, and has randomness. Based on this, due to the different encryption methods, even if the same binary file is encrypted, the generated ciphertext is different, which can ensure the uniqueness and randomness of the generated ciphertext, further strengthen the protection of the binary file, that is, further strengthen the protection of the python source code. Similarly, in this application, the signature algorithm can also be randomly selected, not uniform, and has randomness. Therefore, once the python source code is modified, this situation can be discovered in time.

[0076] In some embodiments of the present application, the process of obtaining the encryption method, obtaining the encryption key corresponding to the encryption method, and writing the encryption method into the cube file in step S3 is described in detail, and the specific steps are as follows:

[0077] S30, obtaining a hiding method.

[0078] Specifically, a hiding method may be randomly selected from a preset hiding method library.

[0079] The hiding method library may include a variety of hiding methods. For example, the real information may be stored in an even-numbered segment, that is, a random number is generated, and the real information such as the encryption method is stored in the even numbers of the random number; the real information may also be stored in an odd-numbered segment, that is, a random number is generated, and the real information such as the encryption method is stored in the odd numbers of the random number.

[0080] S31. Obtain an encryption key corresponding to the encryption method, and use the hiding method to hide the encryption method to obtain the hidden encryption method.

[0081] Specifically, the encryption method can be hidden in a variety of ways, and one optional way is provided here. For example, the encryption method can be hidden in a random number or a table, and the random number or the table is used as the hidden encryption method.

[0082] A hidden method library may be stored in the user's client to realize decryption of hidden encryption methods.

[0083] S32, writing the hidden encryption method into the cube file.

[0084] Specifically, the hidden encryption method can be written into the cube file to achieve hiding of the encryption method.

[0085] It can be seen from the above technical solution that compared with the previous embodiment, this embodiment provides an optional way to hide the encryption method. By hiding the encryption method, the client that illegally reads the cube file cannot know the encryption method corresponding to the ciphertext in the cube file, so it is even more impossible to decrypt the ciphertext, achieving a higher level of protection for the Python source code.

[0086] In some embodiments of the present application, considering that storing the encryption library may occupy memory, and the encryption library may need to be updated in real time as the number of encryption algorithms increases, this may cause inconvenience to running the packaged Python source code. Based on this, after step S30, after obtaining the hiding method, a process of writing the hidden decryption key in the cube file can be added. The process will be described in detail below, the steps are as follows:

[0087] S33. Obtain a decryption key corresponding to the encryption method.

[0088] Specifically, a decryption key corresponding to the encryption method can be obtained from the encryption library to decrypt the ciphertext.

[0089] S34: hiding the decryption key using the hiding method to obtain the hidden decryption key.

[0090] Specifically, the hiding methods used for hiding the encryption method and hiding the decryption key can be the same or different. The decryption key can be hidden in a random number or a table, and the random number or the table is used as the hidden decryption key.

[0091] S35. Write the hidden decryption key into the cube file.

[0092] Specifically, the hidden decryption key may be stored in a cube file, so that the client can read the hidden decryption key.

[0093] The client can use the same technical means as the encryption method to decrypt the hidden decryption key.

[0094] It can be seen from the above technical solution that this embodiment adds an optional method of writing the hidden decryption key into the cube file. Through the above method, when the client reads the hidden decryption key in the cube file, the corresponding hiding method can be used to obtain the decryption key. Through the above steps, the client does not need to store the encryption library, which reduces the pressure on the client memory. And the encryption method can be more real-time and more random, further avoiding the destruction of binary files, that is, further reducing the possibility of phthon source code being modified.

[0095] In some embodiments of the present application, storing the hidden method library may occupy memory, and the hidden method library may need to be updated in real time as the number of hidden methods increases, which may cause inconvenience for the client to run the packaged Python source code. Based on this, after step S30, after obtaining the hidden method, a process of writing the hidden method in the cube file can be added. The following will describe the process in detail, the steps are as follows:

[0096] S36. Write the hiding mode into the setting byte of the cube file.

[0097] Specifically, the setting byte of the cube file may be determined, and the correct hiding method may be written into the setting byte.

[0098] It can be agreed with the client in advance that the hiding mode written in the setting byte is the correct hiding mode, and only the hiding mode in the setting byte needs to be read.

[0099] S37. Randomly select one or more target hiding methods other than the aforementioned hiding method from a preset hiding method library.

[0100] Specifically, a plurality of hiding methods may be randomly selected from the hiding method library as target hiding methods. It should be noted that the randomly selected plurality of hiding methods do not include methods actually used to hide encryption methods and decryption keys.

[0101] S38, writing the target hiding mode into the remaining bytes of the cube file except the set bytes.

[0102] Specifically, a plurality of randomly selected hiding methods are written into the cube file. It should be noted that the randomly selected plurality of hiding methods cannot be written at the setting bytes of the cube file.

[0103] It can be seen from the above technical solution that this embodiment adds an optional way to write the hidden method into the cube file. Through the above method, the hidden method can be written into the set byte of the cube file, and the target hidden method can be written into the remaining bytes of the cube file except the set byte, and the target hidden method is used as a cover for the hidden method to ensure that the hidden method also has a certain degree of confidentiality, so as to keep the encryption method and decryption key confidential. Based on this, the python source code is further kept confidential. And through the above method, the client that reads the cube file can no longer store the hidden method library, which reduces the storage pressure of the client, and the hidden method can be more real-time and more random.

[0104] In some embodiments of the present application, considering that only encryption keys are used for encryption, there is no randomness, and the confidentiality of the python source code needs to be further strengthened. Therefore, the timestamp and the developer information of the python source code can be used to encrypt the binary file. Based on this, in step S4, the following steps can be added before the ciphertext is obtained by encrypting the binary file using the encryption method and the encryption key:

[0105] S40, obtaining the developer information and current timestamp of the python source code, and writing the developer information and the current timestamp into the cube file.

[0106] Specifically, the current timestamp can be generated during the packaging process, and the developer information of the Python source code can be obtained.

[0107] Subsequently, the current timestamp and the developer information may be written into the cube file.

[0108] The developer information may include the number of developers, work number, telephone number, or pinyin of their names.

[0109] Based on this, the process of encrypting the binary file using the encryption method and the encryption key to obtain the ciphertext in step S4 is described in detail, and the steps are as follows:

[0110] S41. Encrypt the binary file using the encryption method, the encryption key, the developer information and the current timestamp to obtain a ciphertext.

[0111] Specifically, encryption technology can be used to encrypt the binary file using the encryption key, developer information, and current timestamp.

[0112] It can be seen from the above technical solution that this embodiment provides an optional way to encrypt binary files. Through the above method, the encryption key, developer information and current timestamp can be used to encrypt binary files together, further improving the protection of binary files, that is, it is more possible to protect Python source code, and the current timestamp participates in encrypting binary files, which enhances the randomness of the generated ciphertext.

[0113] In some embodiments of the present application, considering that the Python source code contains various modules, each module has its own function, and the Python source code of each module constitutes a complete Python source code, the functional form of each module can realize a complete function, and thus, a complete Python source code can be written into the same cube file. Based on this, the process of obtaining the signature algorithm, signing the binary file using the signature algorithm, obtaining the signature information, and writing the signature information and the signature algorithm into the newly created cube file and the reverse detailed description are as follows:

[0114] S20. Sign each module in the binary file using the signature algorithm to obtain signature information of each module.

[0115] Specifically, the phthon source code includes various modules. When the phthon source code is compiled into a binary file, the binary file also contains various modules.

[0116] Based on this, the same signature algorithm can be used to sign each module separately to generate signature information for each module.

[0117] S21. Write the signature algorithm and the signature information of each module into the newly created cube file according to the module.

[0118] Specifically, the signature algorithm used can be written into the cube file, and the generated signature information can be stored by module, so that the signature information between modules will not affect each other.

[0119] The area of ​​each module can be divided in the cube file, and the signature information of each module can be written into the corresponding module area.

[0120] Based on this, considering that there are various modules in the binary file, each module can also be encrypted. Therefore, the process of encrypting the binary file using the encryption method and the encryption key to obtain the ciphertext in step S4 is described in detail, and the steps are as follows:

[0121] S42: Encrypt each module of the binary file using the encryption method, the encryption key, the developer information and the current timestamp to obtain a ciphertext of each module.

[0122] Specifically, each module in the binary file may be encrypted using an encryption method, an encryption key, developer information, and a current timestamp to generate a ciphertext for each module.

[0123] Based on this, considering that there are ciphertexts corresponding to each module, the generated ciphertexts can also be stored in modules. Therefore, the process of writing the ciphertext into the cube file to obtain an executable cube file in step S5 is described in detail, and the steps are as follows:

[0124] S50, writing the ciphertext of each module into the cube file according to the module.

[0125] Specifically, the ciphertext of each module can be written into the cube file by module. If the module area has been divided in the cube file, the ciphertext of each module can be written into the corresponding area.

[0126] At this time, there are multiple module areas in the cube file, and the signature information and ciphertext corresponding to the module are recorded in each module area. The signature information in all module areas constitutes the signature information of the binary file, and the ciphertext in all module areas constitutes the ciphertext of the binary file.

[0127] It can be seen from the above technical solution that this embodiment provides an optional way to write signature information and ciphertext modules into a cube file. Through the above technical means, the signature information and ciphertext modules are stored in the cube file. On this basis, when the client reads the cube file, it can decrypt the ciphertext by module, and sign the plaintext obtained after decryption to obtain the signature information of the plaintext. At this time, by comparing with the signature information corresponding to the module, it can be confirmed whether the ciphertext in the module has been modified, that is, whether the python source code has been modified. Therefore, the modified module can be corrected in a targeted manner. Therefore, through this embodiment, each module of the python source code can be protected more accurately.

[0128] In addition, this application writes the signature information and ciphertext of each module into the same cube file, so that others cannot modify the module by replacing the file, further protecting the Python source code.

[0129] In some embodiments of the present application, taking into account that different packaging scenarios have different requirements, in the silent packaging scenario, it may be necessary to write the name of the company that develops the Python source code. Therefore, the information that needs to be written can be stored in the cube file, such as the company name, location, weather information, etc. The type of the Python source code, fully qualified name and other information can also be written in the cube file.

[0130] Considering that when a user's client opens a certain software, it needs to run the cube file corresponding to the software, but the client may store multiple cube files, so it is necessary to identify which cube files correspond to the software. Based on this, in some embodiments of the present application, an attempt is made to write a custom file format mark header in the cube file to distinguish cube files.

[0131] Specifically, during the packaging process, a file format header can be written into the cube file according to the needs of the actual scenario. The same software can correspond to a unified file format header, or the same function of the same software can correspond to a unified file format header, and different functions of the same software can correspond to different file format headers.

[0132] For example, the file format marker header may be set to: 0x04034b50, which is 4 bytes. The advantage of using the file format marker header instead of the file suffix is ​​that the file suffix and the content are not necessarily strongly related, but the file format marker header can be strongly related to the content.

[0133] It can be seen from the above technical solution that this embodiment provides a file format mark header for writing files into a cube file. Through the above implementation, each cube file can be distinguished and a matching cube file can be identified among multiple cube files.

[0134] Next, the Python source code packaging device provided by this application will be introduced. The Python source code packaging device below can be referenced with the Python source code packaging method above.

[0135] See also Figure 2 , Figure 2 This is a structural block diagram of a Python source code packaging device disclosed in this application.

[0136] Python source code packaging device can include:

[0137] Compilation unit 1, used to obtain executable Python source code and compile the Python source code into a binary file;

[0138] Signature unit 2, used to obtain a signature algorithm, and use the signature algorithm to sign the binary file to obtain signature information, and write the signature information and the signature algorithm into a newly created cube file;

[0139] The acquisition unit 3 is used to acquire the encryption method and the encryption key corresponding to the encryption method, and write the encryption method into the cube file;

[0140] The encryption unit 4 is used to encrypt the binary file using the encryption method and the encryption key to obtain a ciphertext;

[0141] The writing unit 5 is used to write the ciphertext into the cube file to obtain an executable cube file.

[0142] Furthermore, the acquisition unit may include:

[0143] A hiding mode acquisition unit, used for acquiring a hiding mode;

[0144] A hidden encryption method acquisition unit, used to acquire an encryption key corresponding to the encryption method, and use the hidden method to hide the encryption method to obtain the hidden encryption method;

[0145] The hidden encryption method writing unit is used to write the hidden encryption method into the cube file.

[0146] Furthermore, the above-mentioned Python source code packaging device may also include:

[0147] A decryption key acquisition unit, used to acquire a decryption key corresponding to the encryption method;

[0148] A hidden decryption key acquisition unit, used to hide the decryption key in the hiding manner to obtain a hidden decryption key;

[0149] The hidden decryption key writing unit is used to write the hidden decryption key into the cube file.

[0150] Furthermore, the above-mentioned Python source code packaging device may also include:

[0151] A hidden mode writing unit, used for writing the hidden mode at the setting byte of the cube file;

[0152] A target hiding method acquisition unit, used to randomly select one or more target hiding methods other than the hiding method from a preset hiding method library;

[0153] The target hiding mode writing unit is used to write the target hiding mode into the remaining bytes of the cube file except the set bytes.

[0154] Furthermore, the above-mentioned Python source code packaging device may also include:

[0155] An information and time acquisition unit, used for acquiring the developer information and current timestamp of the Python source code, and writing the developer information and the current timestamp into the cube file;

[0156] Based on this, the above encryption unit may include:

[0157] The information and time using unit is used to encrypt the binary file using the encryption method, the encryption key, the developer information and the current timestamp to obtain a ciphertext.

[0158] Furthermore, the above-mentioned signature unit may include:

[0159] A module signature information acquisition unit, used to sign each module in the binary file using the signature algorithm to obtain signature information of each module;

[0160] The module signature information writing unit is used to write the signature algorithm and the signature information of each module into the newly created cube file according to the module.

[0161] Furthermore, the above-mentioned information and time usage unit may include:

[0162] The module ciphertext obtaining unit is used to encrypt each module of the binary file using the encryption method, the encryption key, the developer information and the current timestamp to obtain the ciphertext of each module.

[0163] Based on this, the above-mentioned writing unit may include:

[0164] The module ciphertext writing unit is used to write the ciphertext of each module into the cube file according to the module.

[0165] Furthermore, the above-mentioned Python source code packaging device may also include:

[0166] The file format tag header writing unit is used to write a custom file format tag header into the cube file.

[0167] The python source code packaging device provided in the embodiment of the present application can be applied to python source code packaging devices, such as mobile terminals, PC terminals, cloud platforms, servers and server clusters. Figure 3The hardware structure diagram of the Python source code packaging device is shown in Figure 1. Figure 3 The hardware structure of the Python source code packaging device may include: at least one processor 1, at least one communication interface 2, at least one memory 3 and at least one communication bus 4.

[0168] In the embodiment of the present application, the number of the processor 1, the communication interface 2, the memory 3, and the communication bus 4 is at least one, and the processor 1, the communication interface 2, and the memory 3 communicate with each other through the communication bus 4;

[0169] The processor 1 may be a central processing unit CPU, or an application-specific integrated circuit ASIC (Application Specific Integrated Circuit), or one or more integrated circuits configured to implement the embodiments of the present invention, etc.;

[0170] The memory 3 may include a high-speed RAM memory, and may also include a non-volatile memory, such as at least one disk memory;

[0171] The memory stores a program, and the processor can call the program stored in the memory, wherein the program is used to:

[0172] Obtain executable Python source code and compile the Python source code into a binary file;

[0173] Obtain a signature algorithm, and use the signature algorithm to sign the binary file to obtain signature information, and write the signature information and the signature algorithm into the newly created cube file;

[0174] Obtain an encryption method, obtain an encryption key corresponding to the encryption method, and write the encryption method into the cube file;

[0175] Encrypt the binary file using the encryption method and the encryption key to obtain a ciphertext;

[0176] The ciphertext is written into the cube file to obtain an executable cube file.

[0177] Optionally, the detailed functions and extended functions of the program may refer to the above description.

[0178] The embodiment of the present application further provides a readable storage medium, which may store a program suitable for execution by a processor, wherein the program is used to:

[0179] Obtain executable Python source code and compile the Python source code into a binary file;

[0180] Obtain a signature algorithm, and use the signature algorithm to sign the binary file to obtain signature information, and write the signature information and the signature algorithm into the newly created cube file;

[0181] Obtain an encryption method, obtain an encryption key corresponding to the encryption method, and write the encryption method into the cube file;

[0182] Encrypt the binary file using the encryption method and the encryption key to obtain a ciphertext;

[0183] The ciphertext is written into the cube file to obtain an executable cube file.

[0184] Optionally, the detailed functions and extended functions of the program may refer to the above description.

[0185] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0186] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0187] The above description of the disclosed embodiments enables professionals and technicians in the field to implement or use the present application. Various modifications to these embodiments will be apparent to professionals and technicians in the field, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. The various embodiments of the present application can be combined with each other. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A python source code packaging method, characterized in that: include: Obtain executable Python source code and compile the Python source code into a binary file; Obtain a signature algorithm, and use the signature algorithm to sign the binary file to obtain signature information, and write the signature information and the signature algorithm into the newly created cube file; Get encryption and hiding methods; Obtaining an encryption key corresponding to the encryption method, and hiding the encryption method using the hiding method to obtain the hidden encryption method; Encrypt the binary file using the encryption method and the encryption key to obtain a ciphertext; Writing the ciphertext and the hidden encryption method into the cube file to obtain an executable cube file; After obtaining the hidden method, it also includes: Write the hidden mode at the setting byte of the cube file; Randomly select one or more target hiding methods other than the hiding method from a preset hiding method library; The target hiding mode is written into the remaining bytes of the cube file except the set bytes.

2. The method according to claim 1, characterized in that After obtaining the hidden method, it also includes: Obtaining a decryption key corresponding to the encryption method; The decryption key is hidden by using the hiding method to obtain the hidden decryption key; The hidden decryption key is written into the cube file.

3. The method according to claim 1, characterized in that Before using the encryption method and the encryption key to encrypt the binary file, the method further includes: Obtain the developer information and current timestamp of the Python source code, and write the developer information and the current timestamp into the cube file; The step of encrypting the binary file using the encryption method and the encryption key to obtain a ciphertext includes: The binary file is encrypted using the encryption method, the encryption key, the developer information and the current timestamp to obtain a ciphertext.

4. The method according to claim 3, characterized in that The binary file contains various modules; Signing the binary file using the signature algorithm to obtain signature information, and writing the signature information and the signature algorithm into the newly created cube file, including: Signing each module in the binary file using the signature algorithm to obtain signature information of each module; Write the signature algorithm and the signature information of each module into the newly created cube file according to the module; The binary file is encrypted using the encryption method, the encryption key, the developer information and the current timestamp to obtain a ciphertext, including: Encrypting each module of the binary file using the encryption method, the encryption key, the developer information and the current timestamp to obtain ciphertext of each module; Writing the ciphertext into the cube file includes: The ciphertext of each module is written into the cube file according to the module.

5. The method according to any one of claims 1 to 4, characterized in that: The method further includes: Write a custom file format tag header into the cube file.

6. A python source code packaging device, characterized in that: include: A compilation unit, used to obtain executable Python source code and compile the Python source code into a binary file; A signature unit, used to obtain a signature algorithm, and use the signature algorithm to sign the binary file to obtain signature information, and write the signature information and the signature algorithm into a newly created cube file; An acquisition unit, used for acquiring an encryption method and a hiding method, and acquiring an encryption key corresponding to the encryption method, and using the hiding method to hide the encryption method to obtain the hidden encryption method, and writing the hidden encryption method into the cube file; An encryption unit, used to encrypt the binary file using the encryption method and the encryption key to obtain a ciphertext; A writing unit, used for writing the ciphertext into the cube file to obtain an executable cube file; A hidden mode writing unit, used for writing the hidden mode at a set byte of a cube file; A target hiding method acquisition unit, used to randomly select one or more target hiding methods other than the hiding method from a preset hiding method library; The target hiding mode writing unit is used to write the target hiding mode into the remaining bytes of the cube file except the set bytes.

7. A python source code packaging device, characterized in that: including memory and processor; The memory is used to store programs; The processor is used to execute the program to implement each step of the Python source code packaging method according to any one of claims 1 to 5.

8. A readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, each step of the Python source code packaging method according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Python byte code file protection method based on module hook

    CN106599628A

  • Software installation package, and generation and upgrade methods and systems thereof

    CN108304722A