CN116226881A - Source code encryption method based on compiling language - Google Patents

Source code encryption method based on compiling language Download PDF

Info

Publication number
CN116226881A
CN116226881A CN202310068929.7A CN202310068929A CN116226881A CN 116226881 A CN116226881 A CN 116226881A CN 202310068929 A CN202310068929 A CN 202310068929A CN 116226881 A CN116226881 A CN 116226881A
Authority
CN
China
Prior art keywords
source code
compiler
target source
target
encryption
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310068929.7A
Other languages
Chinese (zh)
Inventor
邹式论
秦放
吴汶泰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Chengdu 30javee Microelectronics Co ltd
Original Assignee
Chengdu 30javee Microelectronics Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Chengdu 30javee Microelectronics Co ltd filed Critical Chengdu 30javee Microelectronics Co ltd
Priority to CN202310068929.7A priority Critical patent/CN116226881A/en
Publication of CN116226881A publication Critical patent/CN116226881A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • G06F21/602Providing cryptographic facilities or services
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • G06F21/62Protecting access to data via a platform, e.g. using keys or access control rules
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Hardware Design (AREA)
  • Computer Security & Cryptography (AREA)
  • Health & Medical Sciences (AREA)
  • General Health & Medical Sciences (AREA)
  • Bioethics (AREA)
  • Stored Programmes (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

The invention discloses a source code encryption method based on a compiled language, which comprises the following steps: s1, generating an asymmetric key pair by using an opensl software library; s2, generating a code encryption tool according to the public key generated in the step S1; s3, encrypting the target source code by using a code encryption tool to obtain a source code encryption file with the same name; s4, modifying the source code of the compiler, adding an asymmetric algorithm, importing the private key generated in the step S1 into the source code of the compiler, and modifying the processing logic of the compiler to form an executable file; s5, exporting and publishing the encrypted files of the same name source codes generated in the step S3 and the modified executable files of the compiler in the step S4; s6, compiling the target source code by using the release package in the S5 step, and executing. In the whole source code encryption compiling process, the compiler executing process directly decrypts and compiles in the program address space, so that the aim of protecting the source code is achieved.

Description

Source code encryption method based on compiling language
Technical Field
The invention relates to the field of computer software information security, in particular to a source code encryption method based on a compiled language.
Background
The compiled language exists in contrast to interpreted languages, which first compile source code into machine language, and then run machine code (binary executable program) by the machine.
Unlike common computer application software, the source code compiled executable file can be issued to users for use, and the purpose of protecting the source code intellectual property can be achieved. Programs are often recompiled under different processor architectures or different operating system versions for proper use in cross-platform scenarios. Some special industries, such as the military, cannot deliver the plaintext source code of the user software due to the safety of intellectual property or special equipment.
At present, a code confusion mode is generally adopted based on source code protection, namely variable names and function names in codes are uniformly converted into character strings without logic significance, the purpose that the logic significance of the codes is not easy to read is achieved, the source codes are further protected, and meanwhile compiling is not influenced. However, the code may be cracked or the local data may be forcefully modified, so that the logic of the code may leak or run state or running error inconsistent with the design may be generated, and the system software may not modify the name of the system interface function as independent software, and the source code may not be modified and confused at will.
Disclosure of Invention
The invention provides a source code encryption method based on a compiled language, which comprises the following steps: s1, generating an asymmetric key pair by using an opensl software library; s2, generating a code encryption tool according to the public key generated in the step S1; s3, encrypting the target source code by using a code encryption tool to obtain a source code encryption file with the same name; s4, modifying the source code of the compiler, adding an asymmetric algorithm, importing the private key generated in the step S1 into the source code of the compiler, and modifying the processing logic of the compiler to form an executable file; s5, exporting and publishing the encrypted files of the same name source codes generated in the step S3 and the modified executable files of the compiler in the step S4; s6, compiling the target source code by using the release package in the S5 step, and executing.
Further, the step S4 includes the following substeps: s41, after the private key is encrypted, the private key is imported into an address space of an execution program of the compiler; s42, decrypting the encrypted private key to obtain an effective private key for decrypting the target source code; s43, reading the same-name file after the encryption of the target source code; s44, calculating a target source code ciphertext hash value, comparing the target source code ciphertext hash value with a hash check head, executing downwards if the target source code ciphertext hash value is correct, and ending the compiler operation if the target source code ciphertext hash value is incorrect; s45, decrypting the target source code to a compiler execution program address space by using an asymmetric algorithm; s46, compiling the decrypted target source code file.
Further, the code encryption tool generated in the step S2 is written in the language C.
Further, the steps S1 to S5 are all executed in a safe environment, and the step S6 is executed in a target environment; and the steps S1-S6 mainly adopt an asymmetric encryption algorithm.
The invention provides a source code encryption method based on a compiled language, which only has the process of encrypting source codes in the whole source code encryption and compiling process, does not have the process of decrypting into a plaintext source code file, and directly decrypts and compiles in a program address space in the execution process of a compiler, thereby achieving the aim of better source code protection.
Drawings
FIG. 1 is a flow chart of a source code encryption method based on a compiled language;
fig. 2 is a flowchart of a modified compiler of a source code encryption method based on a compiled language according to the present invention.
Detailed Description
The following detailed description of embodiments of the invention, taken in conjunction with the accompanying drawings, illustrates only some, but not all embodiments, and for the sake of clarity, illustration and description not related to the invention is omitted in the drawings and description.
Both the SM2 algorithm and the RSA algorithm are public key cryptographic algorithms, and the SM2 algorithm is a more advanced security algorithm that was used to replace the RSA algorithm in our national commercial cryptosystem. Along with the development of cryptographic technology and computer technology, the 1024-bit RSA algorithm commonly used at present faces serious security threat, and the national cryptographic management department decides to replace the RSA algorithm by adopting the SM2 elliptic curve algorithm through research, and the invention also adopts the SM2 algorithm.
As shown in fig. 1, a source code encryption method based on a compiled language includes the following steps: s1, generating an asymmetric key pair by using an opensl software library; s2, generating a code encryption tool according to the public key generated in the step S1; s3, encrypting the target source code by using a code encryption tool to obtain a source code encryption file with the same name; s4, modifying the source code of the compiler, adding an asymmetric algorithm, importing the private key generated in the step S1 into the source code of the compiler, and modifying the processing logic of the compiler to form an executable file; s5, exporting and publishing the encrypted files of the same name source codes generated in the step S3 and the modified executable files of the compiler in the step S4; s6, compiling the target source code by using the release package in the S5 step, and executing.
S1, in the step of: public and private key pairs are generated using an asymmetric algorithm. This key pair is used in a secure environment and is not issued externally. The asymmetric key pair generated using the opensl software library is not limited to this, and the symmetric key may be generated.
S2, in the step of: the code encryption tool implements an asymmetric algorithm and imports the public key in S1 for compiling the source code file. This tool is used in a secure environment, without publishing source code or executable files to the outside. The asymmetric soft algorithm is practically used, but not limited to this, and a symmetric algorithm may be practically used.
S3, in the step of: and encrypting the target source code by using the tool in S2 to obtain an encrypted file with the same name as the source code, wherein the encrypted file is not readable text, and the encrypted file cannot change the logic of the code and variables in the code although the encrypted file is the same name as the source code. The encrypted file comprises a hash check head and a source code ciphertext.
S4, in the step of: modifying the source code of the compiler, and adding a software asymmetric algorithm to the source code; meanwhile, the private key generated in the step S1 is encrypted and then is imported into the source code of the compiler; the compiler processing logic is modified to have the ability to directly compile encrypted source code files. The custom compiler generated at this time contains an asymmetric algorithm and an encrypted private key, and can directly compile encrypted source codes. Compiler source code will not be published, but only custom compiler executable files.
The step S4 comprises the following substeps: s41, after the private key is encrypted, the private key is imported into an address space of an execution program of the compiler; s42, decrypting the encrypted private key to obtain an effective private key for decrypting the target source code; s43, reading the same-name file after the encryption of the target source code; s44, calculating a target source code ciphertext hash value, comparing the target source code ciphertext hash value with a hash check head, executing downwards if the target source code ciphertext hash value is correct, and ending the compiler operation if the target source code ciphertext hash value is incorrect; s45, decrypting the target source code to a compiler execution program address space by using an asymmetric algorithm; s46, compiling the decrypted target source code file.
While the foregoing is directed to embodiments of the present invention, other and further details of the invention may be had by the present invention, it should be understood that the foregoing description is merely illustrative of the present invention and that no limitations are intended to the scope of the invention, except insofar as modifications, equivalents, improvements or modifications are within the spirit and principles of the invention.

Claims (4)

1. A source code encryption method based on a compiled language is characterized by comprising the following steps: s1, generating an asymmetric key pair by using an opensl software library;
s2, generating a code encryption tool according to the public key generated in the step S1;
s3, encrypting the target source code by using a code encryption tool to obtain a source code encryption file with the same name;
s4, modifying the source code of the compiler, adding an asymmetric algorithm, importing the private key generated in the step S1 into the source code of the compiler, and modifying the processing logic of the compiler to form an executable file;
s5, exporting and publishing the encrypted files of the same name source codes generated in the step S3 and the modified executable files of the compiler in the step S4;
s6, compiling the target source code by using the release package in the S5 step, and executing.
2. The source code encryption method based on a compiled language of claim 1, wherein the step S4 includes the sub-steps of: s41, after the private key is encrypted, the private key is imported into an address space of an execution program of the compiler;
s42, decrypting the encrypted private key to obtain an effective private key for decrypting the target source code;
s43, reading the same-name file after the encryption of the target source code;
s44, calculating a target source code ciphertext hash value, comparing the target source code ciphertext hash value with a hash check head, executing downwards if the target source code ciphertext hash value is correct, and ending the compiler operation if the target source code ciphertext hash value is incorrect;
s45, decrypting the target source code to a compiler execution program address space by using an asymmetric algorithm;
s46, compiling the decrypted target source code file.
3. The source code encryption method based on a compiled language according to claim 1, wherein the code encryption tool generated in the step S2 is written in C language.
4. The source code encryption method based on a compiled language of claim 1, wherein steps S1 to S5 are performed in a secure environment, and step S6 is performed in a target environment; and the steps S1-S6 mainly adopt an asymmetric encryption algorithm.
CN202310068929.7A 2023-02-06 2023-02-06 Source code encryption method based on compiling language Pending CN116226881A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310068929.7A CN116226881A (en) 2023-02-06 2023-02-06 Source code encryption method based on compiling language

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310068929.7A CN116226881A (en) 2023-02-06 2023-02-06 Source code encryption method based on compiling language

Publications (1)

Publication Number Publication Date
CN116226881A true CN116226881A (en) 2023-06-06

Family

ID=86576110

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310068929.7A Pending CN116226881A (en) 2023-02-06 2023-02-06 Source code encryption method based on compiling language

Country Status (1)

Country Link
CN (1) CN116226881A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117909939A (en) * 2024-03-19 2024-04-19 麒麟软件有限公司 Code text content-based code protection method and compiler text lock

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117909939A (en) * 2024-03-19 2024-04-19 麒麟软件有限公司 Code text content-based code protection method and compiler text lock
CN117909939B (en) * 2024-03-19 2024-06-07 麒麟软件有限公司 Code text content-based code protection method and compiler text lock

Similar Documents

Publication Publication Date Title
CN110069905A (en) A kind of device and method of Springboot program encryption and decryption
JP5851074B2 (en) A computing device storing a lookup table for calculating functions
KR101216995B1 (en) A code encryption and decryption device against reverse engineering based on indexed table and the method thereof
KR101687439B1 (en) A processor-implemented method for ensuring software integrity
JP7285850B2 (en) Compilation device and method
US9594769B2 (en) Computing device configured with a table network
CN104268444A (en) Cloud OS Java source code protection method
CN111512307B (en) Compiling apparatus and method
US10572635B2 (en) Automatic correction of cryptographic application program interfaces
CN107871066B (en) Code compiling method and device based on android system
KR20200136142A (en) Method of encoding and decoding memory data for software security, readable medium and apparatus for performing the method
Manikyam Program protection using software based hardware abstraction
CN116226881A (en) Source code encryption method based on compiling language
US12052348B2 (en) Computation device using shared shares
US20120204038A1 (en) Performing boolean logic operations using arithmetic operations by code obfuscation
CN117093964A (en) Encryption method and device of source code, storage medium and electronic equipment
CN117313046A (en) Code reinforcement method, code loading method, device and medium
CN114444028B (en) Method, device, computer equipment and storage medium for improving code security
EP2947590B1 (en) Program code obfuscation based upon recently executed program code
CN111291333A (en) Java application program encryption method and device
JP2011123229A (en) Program code encryption device and program
Cho et al. Secure and efficient code encryption scheme based on indexed table
CN116089983B (en) Reinforcing compiling method and device for py file
Yasin et al. Dynamic multi levels Java code obfuscation technique (DMLJCOT)
Otsuki et al. Overcoming the obfuscation method of the dynamic name resolution

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination