CN117093964A - Encryption method and device of source code, storage medium and electronic equipment - Google Patents
Encryption method and device of source code, storage medium and electronic equipment Download PDFInfo
- Publication number
- CN117093964A CN117093964A CN202310891178.9A CN202310891178A CN117093964A CN 117093964 A CN117093964 A CN 117093964A CN 202310891178 A CN202310891178 A CN 202310891178A CN 117093964 A CN117093964 A CN 117093964A
- Authority
- CN
- China
- Prior art keywords
- code
- code block
- source code
- encrypted
- target source
- 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
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F21/00—Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
- G06F21/10—Protecting distributed programs or content, e.g. vending or licensing of copyrighted material ; Digital rights management [DRM]
- G06F21/12—Protecting executable software
- G06F21/14—Protecting executable software against software analysis or reverse engineering, e.g. by obfuscation
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F40/00—Handling natural language data
- G06F40/10—Text processing
- G06F40/12—Use of codes for handling textual entities
- G06F40/126—Character encoding
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/42—Syntactic analysis
- G06F8/427—Parsing
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/40—Transformation of program code
- G06F8/41—Compilation
- G06F8/44—Encoding
- G06F8/447—Target code generation
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- Software Systems (AREA)
- General Physics & Mathematics (AREA)
- Computer Hardware Design (AREA)
- Computer Security & Cryptography (AREA)
- Technology Law (AREA)
- Multimedia (AREA)
- Health & Medical Sciences (AREA)
- Artificial Intelligence (AREA)
- Audiology, Speech & Language Pathology (AREA)
- Computational Linguistics (AREA)
- General Health & Medical Sciences (AREA)
- Stored Programmes (AREA)
Abstract
The application relates to the technical field of source code protection, and discloses a source code encryption method, a source code encryption device, a storage medium and electronic equipment, wherein the source code encryption method comprises the following steps: acquiring a target source code, and determining the method name of an encrypted code block in the target source code according to the target source code; inputting the target source code to a compiler to generate an abstract syntax tree of the target source code; determining a code block corresponding to the method name of the encrypted code block according to the method name of the encrypted code block and the abstract syntax tree; encrypting the code block based on a predefined encryption method to generate an encrypted code block; and continuously compiling the encrypted code blocks and the unencrypted code blocks through a compiler to generate target machine codes corresponding to the target source codes. By the method, the safety coefficient of the source code can be further improved, and the risk of source code stealing and leakage is reduced.
Description
Technical Field
The present application relates to the field of source code protection technologies, and in particular, to a method and apparatus for encrypting a source code, a storage medium, and an electronic device.
Background
Source code refers to an uncompiled text file written according to a certain programming language specification, and is a series of human-readable computer language instructions. Source code is the basis for a computer program and is also the original logical representation of the computer program. Source code is an important property of a developer as an important intellectual property of the developer.
At present, a technical means for protecting the source code is mainly to directly encrypt the source code to protect the source code. For example, a method such as symmetric encryption or asymmetric encryption is adopted to encrypt the source code as a whole, and then ciphertext of the source code is formed. When the source code is needed, the source code is decrypted according to the corresponding decryption method. However, the above encryption method is vulnerable to hacking if the selected encryption algorithm is inadequate. Moreover, the encryption efficiency of the encryption method is low. Therefore, a technical solution is needed to solve the above technical problems, further ensure the security of the source code, and reduce the risk of source code theft and leakage.
Disclosure of Invention
The application provides a source code encryption method, a source code encryption device, a storage medium and electronic equipment, and aims to solve the technical problem that in the prior art, the security of source codes is not high.
In a first aspect, there is provided a method for encrypting source code, including:
acquiring a target source code, and determining the method name of an encrypted code block in the target source code according to the target source code;
inputting the target source code to a compiler to generate an abstract syntax tree of the target source code;
determining a code block corresponding to the method name of the encrypted code block according to the method name of the encrypted code block and the abstract syntax tree;
encrypting the code block based on a predefined encryption method to generate an encrypted code block;
and continuously compiling the encrypted code blocks and the unencrypted code blocks through a compiler to generate target machine codes corresponding to the target source codes.
In one possible implementation manner, the abstract syntax tree includes method names of a plurality of code blocks, and the determining, according to the method names of the encrypted code blocks and the abstract syntax tree, the code block corresponding to the method name of the encrypted code block includes:
sequentially judging whether the method names of the code blocks are the same as the method names of the encrypted code blocks;
and if the code blocks are the same, determining the code blocks corresponding to the same method names as the code blocks corresponding to the method names of the encrypted code blocks.
In one possible implementation manner, the code block is a character string formed by a plurality of characters, the encrypting the code block based on a predefined encryption method, and generating an encrypted code block includes:
acquiring a character string corresponding to the code block;
and converting the character strings corresponding to the code blocks into second character strings corresponding to the code blocks through UTF16 coding operation.
In one possible implementation manner, the converting, by the UTF16 encoding operation, the character string corresponding to the code block into the second character string corresponding to the code block includes:
decomposing the character string corresponding to the code block into a plurality of characters;
and sequentially converting the plurality of characters into unified codes corresponding to UTF16, and combining and connecting the unified codes corresponding to UTF16 to generate a second character string corresponding to the code block.
In one possible implementation manner, after the converting, by the UTF16 encoding operation, the character string corresponding to the code block into the second character string corresponding to the code block, the method further includes:
and converting the second character string corresponding to the code block into a third character string corresponding to the code block through a Base64 coding operation.
In one possible implementation manner, the converting, by a Base64 encoding operation, the second string corresponding to the code block into the third string corresponding to the code block includes:
decomposing a second character string corresponding to the code block into a plurality of characters;
and sequentially converting the plurality of characters into unified codes corresponding to the Base64, and combining and connecting the unified codes corresponding to the Base64 to generate a third character string corresponding to the code block.
In one possible implementation manner, after the compiling is performed on the encrypted code block and the unencrypted code block by the compiler, generating the target machine code corresponding to the target source code, the method further includes:
acquiring a target machine code corresponding to a target source code;
and after decrypting the encrypted code block based on a predefined decryption method, running the target machine code.
In a second aspect, there is provided an encryption apparatus for source code, comprising:
the acquisition module is used for: the method comprises the steps of obtaining a target source code, and determining the method name of an encrypted code block in the target source code according to the target source code;
a first generation module: the abstract syntax tree is used for inputting the target source code to the compiler and generating the target source code;
and a determination module: the code block corresponding to the method name of the encrypted code block is determined according to the method name of the encrypted code block and the abstract syntax tree;
an encryption module: the encryption method comprises the steps of encrypting the code blocks based on a predefined encryption method to generate encrypted code blocks;
and a second generation module: and the compiler is used for continuously compiling the encrypted code blocks and the unencrypted code blocks to generate target machine codes corresponding to the target source codes.
In a third aspect, a computer readable storage medium is provided, the computer readable storage medium storing a computer program which, when executed by a processor, implements the steps of the encryption method of source code described above.
In a fourth aspect, an electronic device is provided, comprising a memory, a processor and a computer program stored in the memory and executable on the processor, the processor executing the steps of the method for encrypting source code as described above.
The encryption method, the encryption device, the storage medium and the electronic equipment of the source code are characterized in that firstly, a target source code is obtained, and the method name of an encryption code block in the target source code is determined according to the target source code; then, inputting the target source code to a compiler to generate an abstract syntax tree of the target source code; secondly, determining a code block corresponding to the method name of the encrypted code block according to the method name of the encrypted code block and the abstract syntax tree, and encrypting the code block based on a predefined encryption method to generate an encrypted code block; finally, continuously compiling the encrypted code block and the unencrypted code block through a compiler to generate a target machine code corresponding to the target source code 。
In the application, in the compiling process of the source code, key code blocks in the source code are encrypted by adopting various technical means through the generated abstract syntax tree, and finally, machine codes corresponding to the source code are generated. Since the machine code is a binary code that can be directly executed by a computer, the computer program can be run after the user obtains the machine code. Meanwhile, in the application, the machine code finally generated by the source code can not restore the real source code through a common debugging tool because part of code blocks in the source code are encrypted in the compiling process, thereby further improving the safety of the source code. Meanwhile, key code blocks in the source code are encrypted through the generated abstract syntax tree, instead of all code blocks in the source code, so that the encryption efficiency of the source code is improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the description of the embodiments of the present application will be briefly described below, it being obvious that the drawings in the following description are only some embodiments of the present application, and that other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a schematic view of an application environment of a source code encryption method according to an embodiment of the present application;
FIG. 2 is a flow chart of an encryption method of source code according to an embodiment of the application;
FIG. 3 is a flowchart illustrating the step S30 in FIG. 2;
FIG. 4 is a flowchart illustrating the step S40 in FIG. 2;
FIG. 5 is a flowchart illustrating a step S40 in FIG. 2;
FIG. 6 is a schematic diagram of an encryption device for source code according to an embodiment of the present application;
FIG. 7 is a schematic diagram of another configuration of an encryption device for source code according to an embodiment of the present application;
FIG. 8 is a schematic diagram of a computer device according to an embodiment of the application.
Detailed Description
The following description of the embodiments of the present application will be made clearly and fully with reference to the accompanying drawings, in which it is evident that the embodiments described are some, but not all embodiments of the application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
Before the technical scheme in the embodiment of the application is introduced, an application loop in the technical scheme is introduced.
The encryption method of the source code provided by the embodiment of the application can be applied to an application environment as shown in fig. 1, wherein a client communicates with a server through a local network. Firstly, acquiring a target source code through a client, and determining the method name of an encrypted code block in the target source code according to the target source code; secondly, inputting the target source code to a compiler of a server side to generate an abstract syntax tree of the target source code; thirdly, determining a code block corresponding to the method name of the encrypted code block at a server according to the method name of the encrypted code block and the abstract syntax tree, and encrypting the code block at the server based on a predefined encryption method to generate an encrypted code block; and finally, continuously compiling the encrypted code blocks and the unencrypted code blocks through a compiler to generate target machine codes corresponding to the target source codes.
According to the encryption method of the source code, in the source code compiling process, part of key code blocks in the source code are encrypted to generate the machine code corresponding to the source code, so that the safety of the source code is further improved, and the encryption efficiency of the source code is improved. The clients may be, but are not limited to, various personal computers, notebook computers, smart phones, tablet computers, and portable wearable devices. The server may be implemented by a stand-alone server or a server cluster formed by a plurality of servers. The present application will be described in detail with reference to specific examples.
Referring to fig. 2, fig. 2 is a flow chart of an encryption method of source code according to an embodiment of the application, which includes the following steps:
s10: and acquiring the target source code, and determining the method name of the encrypted code block in the target source code according to the target source code.
The target source code in the embodiment of the application refers to an uncompiled text file written according to a certain programming language specification, wherein the programming language can be any one of Java language, python language, C language and the like. For example, in one embodiment, the object source code is Java source code written in Java language. The Java source code includes a plurality of Java method code blocks, and the Java method code blocks are code sets with special functions by organizing the code blocks with independent functions into a whole. Thus, a Java method code block is used to implement a function of a computer program. Meanwhile, in order to distinguish between different functions implemented by different Java method code blocks, the distinction is made in the computer program by naming the methods of the Java method code blocks.
Thousands of pieces of code may be included in Java source code, but not all of the code is core code, which is only concentrated in a portion of the code segments. According to the embodiment of the application, after the target source code is acquired, the core code to be protected can be determined according to the name or type attribute of the target source code. The determination mode of the core code is mainly determined by a method name. In one embodiment, the method names corresponding to the core codes may be stored in a core code method name database, and the method names of the encrypted code blocks in the target source code may be determined by searching the database. For example, in the embodiment of the present application, the Java source code includes first, second, third, fourth, and other method names, and the second and fourth method names are stored in the core code method name database, so that the second and fourth method names are the method names of the encrypted code blocks in the Java source code. It should be noted that, different source codes have different names of methods for encrypting code blocks in the source codes due to different functions.
S20: target source code is input to a compiler, and an abstract syntax tree of the target source code is generated.
An abstract syntax tree is an abstract representation of the syntax structure of source code, representing the syntax structure of a programming language in the form of a tree, each node on the tree representing a structure in the source code. In the embodiment of the application, java source codes are input into a Babel compiler, and the Babel compiler comprises a component of a grammar analyzer, so that an abstract grammar tree of the Java source codes can be generated through the grammar analyzer.
S30: and determining the code block corresponding to the method name of the encrypted code block according to the method name of the encrypted code block and the abstract syntax tree.
In one embodiment, the abstract syntax tree comprises method names of a plurality of code blocks, i.e. each node on the abstract syntax tree comprises method names of a plurality of code blocks. Referring to fig. 3, fig. 3 is a flowchart of a specific embodiment of step S30 in fig. 2, including the following steps:
s31: sequentially judging whether the method names of the code blocks are the same as the method names of the encrypted code blocks;
s32: and if the code blocks are the same, determining the code blocks corresponding to the same method names as the code blocks corresponding to the method names of the encrypted code blocks.
For example, the names of the methods in the nodes of the abstract syntax tree are sequentially sixth, second, first, second, fifth, fourth, third and other methods. And if the method names are the same, determining the code block corresponding to the same method name as the code block corresponding to the method name of the encrypted code block. That is, the code blocks corresponding to the second and fourth method names on the abstract syntax tree are determined as encrypted code blocks.
S40: and encrypting the code block based on a predefined encryption method to generate an encrypted code block.
In one embodiment, the code block is a string composed of a plurality of characters, as shown in fig. 4, fig. 4 is a flowchart of a specific embodiment of step S40 in fig. 2, which includes the following steps:
s1-41: acquiring a character string corresponding to the code block;
s1-42: and converting the character strings corresponding to the code blocks into second character strings corresponding to the code blocks through UTF16 coding operation.
In one embodiment, the steps S1 to 42 include the following steps:
a1: decomposing the character string corresponding to the code block into a plurality of characters;
a2: and sequentially converting the plurality of characters into unified codes corresponding to UTF16, and combining and connecting the unified codes corresponding to UTF16 to generate a second character string corresponding to the code block.
UTF (Unicode Transfer Format) 16 is a way of using Unicode, capable of mapping abstract code bits of Unicode character sets into a sequence of integers of 16 bits long for data storage or transfer. According to the embodiment of the application, the source code character string which is easy to identify can be converted into the new character string through UTF16 coding operation, so that the original character string is subjected to confusion encryption, and the security of a core code block in the source code is improved.
In one embodiment, referring to fig. 5, fig. 5 is a flowchart illustrating another embodiment of step S40 in fig. 2, including the following steps:
s2-41: acquiring a character string corresponding to the code block;
s2-42: converting the character strings corresponding to the code blocks into second character strings corresponding to the code blocks through UTF16 coding operation;
s2-43: and converting the second character string corresponding to the code block into a third character string corresponding to the code block through a Base64 coding operation.
In order to further improve the security of the core code block in the source code, after the above steps S1-42, the second string is further subjected to the Base64 encoding operation to generate a third string by performing the obfuscation encryption. In one embodiment, the steps S2 to 43 include the following steps:
b1: decomposing a second character string corresponding to the code block into a plurality of characters;
b2: and sequentially converting the plurality of characters into unified codes corresponding to the Base64, and combining and connecting the unified codes corresponding to the Base64 to generate a third character string corresponding to the code block.
The Base64 comprises a character set of 64 characters, namely lower case letters a-Z, upper case letters A-Z, numbers 0-9, symbols "+", "/", and the embodiment of the application can convert the second character string into the characters in the character set to generate a third character string by the Base64 coding operation, thereby increasing the confusion of the character strings in the source code and improving the safety coefficient of the core code block.
S50: and continuously compiling the encrypted code blocks and the unencrypted code blocks through a compiler to generate target machine codes corresponding to the target source codes.
In the embodiment of the application, the finally generated machine code is a binary code which can be directly executed by a computer, and the computer program can be run after a user obtains the machine code. It should be noted that, in the technical solution of the embodiment of the present application, since encryption operation is performed on a part of code blocks in the source code in the compiling process. Therefore, even after the target machine code is obtained, the real source code cannot be restored through a common debugging tool, so that the safety of the source code is further improved. Meanwhile, according to the technical scheme in the embodiment of the application, only the core code block is encrypted. Thus, both encrypted code blocks and unencrypted code blocks may be generated during compilation of the target source code. In addition, in the compiling process, the technical means for encrypting only the core code blocks can improve the encryption efficiency on the basis of ensuring the security of the source code.
In one embodiment, after the step S50, the method further includes:
c1: acquiring a target machine code corresponding to a target source code;
c2: and after decrypting the encrypted code block based on a predefined decryption method, running the target machine code.
As described above, if the target machine code needs to be run, a decryption method corresponding to the above encryption method needs to be obtained, and after the encrypted code block is decrypted, the logic program in the source code can be restored.
In the embodiment of the application, firstly, a target source code is acquired, and the method name of an encrypted code block in the target source code is determined according to the target source code; then, inputting the target source code to a compiler to generate an abstract syntax tree of the target source code; secondly, determining a code block corresponding to the method name of the encrypted code block according to the method name of the encrypted code block and the abstract syntax tree, and encrypting the code block based on a predefined encryption method to generate an encrypted code block; and finally, continuously compiling the encrypted code blocks and the unencrypted code blocks through a compiler to generate target machine codes corresponding to the target source codes.
In the embodiment of the application, in the compiling process of the source code, key code blocks in the source code are encrypted by adopting various technical means through the generated abstract syntax tree, and finally machine codes corresponding to the source code are generated. Since the machine code is a binary code that can be directly executed by a computer, the computer program can be run after the user obtains the machine code. Meanwhile, in the embodiment of the application, the machine code finally generated by the source code can not restore the real source code through a common debugging tool because part of code blocks in the source code are encrypted in the compiling process, so that the safety of the source code is further improved. Meanwhile, key code blocks in the source code are encrypted through the generated abstract syntax tree, instead of all code blocks in the source code, so that the encryption efficiency of the source code is improved.
It should be understood that the sequence number of each step in the foregoing embodiment does not mean that the execution sequence of each process should be determined by the function and the internal logic, and should not limit the implementation process of the embodiment of the present application. Furthermore, the terms "include" and variations thereof are to be interpreted as open-ended terms that include, but are not limited to.
In one embodiment, an encryption device for source code is provided, where the encryption device corresponds to the encryption method for source code in the above embodiment one by one. As shown in fig. 6, the encryption apparatus includes: an acquisition module 301, a first generation module 302, a determination module 303, an encryption module 304 and a second generation module 305. The functional modules are described in detail as follows:
the acquisition module 301: the method is used for acquiring the target source code and determining the method name of the encrypted code block in the target source code according to the target source code.
The first generation module 302: the abstract syntax tree is used for inputting the target source code to the compiler and generating the target source code.
Determination module 303: and determining the code block corresponding to the method name of the encrypted code block according to the method name of the encrypted code block and the abstract syntax tree.
Encryption module 304: for encrypting the code blocks based on a predefined encryption method, generating encrypted code blocks.
The second generation module 305: and the compiler is used for continuously compiling the encrypted code blocks and the unencrypted code blocks to generate target machine codes corresponding to the target source codes.
One possible implementation manner is provided in the embodiment of the present application, as shown in fig. 7, where the encryption device further includes an operation module 406. Wherein, the operation module 406 is configured to:
acquiring a target machine code corresponding to a target source code;
and after decrypting the encrypted code block based on a predefined decryption method, running the target machine code.
In an embodiment of the present application, a possible implementation manner is provided, where the abstract syntax tree includes method names of a plurality of code blocks, and the determining module 303 is further configured to:
sequentially judging whether the method names of the code blocks are the same as the method names of the encrypted code blocks;
and if the code blocks are the same, determining the code blocks corresponding to the same method names as the code blocks corresponding to the method names of the encrypted code blocks.
In an embodiment of the present application, a possible implementation manner is provided, where the code block is a string composed of a plurality of characters, and the encryption module 304 is further configured to:
acquiring a character string corresponding to the code block;
and converting the character strings corresponding to the code blocks into second character strings corresponding to the code blocks through UTF16 coding operation.
In an embodiment of the present application, a possible implementation manner is provided, where the encryption module 304 is further configured to:
decomposing the character string corresponding to the code block into a plurality of characters;
and sequentially converting the plurality of characters into unified codes corresponding to UTF16, and combining and connecting the unified codes corresponding to UTF16 to generate a second character string corresponding to the code block.
In an embodiment of the present application, a possible implementation manner is provided, where the encryption module 304 is further configured to:
and converting the second character string corresponding to the code block into a third character string corresponding to the code block through a Base64 coding operation.
In an embodiment of the present application, a possible implementation manner is provided, where the encryption module 304 is further configured to:
decomposing a second character string corresponding to the code block into a plurality of characters;
and sequentially converting the plurality of characters into unified codes corresponding to the Base64, and combining and connecting the unified codes corresponding to the Base64 to generate a third character string corresponding to the code block.
The embodiment of the application provides an encryption device of a source code, which comprises the steps of firstly, acquiring a target source code, and determining the method name of an encryption code block in the target source code according to the target source code; then, inputting the target source code to a compiler to generate an abstract syntax tree of the target source code; secondly, determining a code block corresponding to the method name of the encrypted code block according to the method name of the encrypted code block and the abstract syntax tree, and encrypting the code block based on a predefined encryption method to generate an encrypted code block; and finally, continuously compiling the encrypted code blocks and the unencrypted code blocks through a compiler to generate target machine codes corresponding to the target source codes.
In the embodiment of the application, in the compiling process of the source code, key code blocks in the source code are encrypted by adopting various technical means through the generated abstract syntax tree, and finally machine codes corresponding to the source code are generated. Since the machine code is a binary code that can be directly executed by a computer, the computer program can be run after the user obtains the machine code. Meanwhile, in the embodiment of the application, the machine code finally generated by the source code can not restore the real source code through a common debugging tool because part of code blocks in the source code are encrypted in the compiling process, so that the safety of the source code is further improved. Meanwhile, key code blocks in the source code are encrypted through the generated abstract syntax tree, instead of all code blocks in the source code, so that the encryption efficiency of the source code is improved.
For specific limitations of the encryption device of the source code, reference may be made to the above limitations of the encryption method of the source code, and no further description is given here. The respective modules in the encryption device of the source code described above may be implemented in whole or in part by software, hardware, or a combination thereof. The above modules may be embedded in hardware or may be independent of a processor in the computer device, or may be stored in software in a memory in the computer device, so that the processor may call and execute operations corresponding to the above modules.
In one embodiment, a computer device is provided, the internal structure of which may be as shown in FIG. 8. The computer device includes a processor, a memory, a network interface, a display screen, and an input device connected by a system bus. Wherein the processor of the computer device is configured 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 computer programs in the non-volatile storage media. The network interface of the computer device is for communicating with an external server via a network connection. The computer program is executed by a processor to perform the functions or steps of a method of encrypting source code.
In one embodiment, a computer device is provided comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, the processor implementing the steps of when executing the computer program:
acquiring a target source code, and determining the method name of an encrypted code block in the target source code according to the target source code;
inputting the target source code to a compiler to generate an abstract syntax tree of the target source code;
determining a code block corresponding to the method name of the encrypted code block according to the method name of the encrypted code block and the abstract syntax tree;
encrypting the code block based on a predefined encryption method to generate an encrypted code block;
and continuously compiling the encrypted code blocks and the unencrypted code blocks through a compiler to generate target machine codes corresponding to the target source codes.
In one embodiment, a computer readable storage medium is provided, storing a computer program which when executed by a processor performs the steps of:
acquiring a target source code, and determining the method name of an encrypted code block in the target source code according to the target source code;
inputting the target source code to a compiler to generate an abstract syntax tree of the target source code;
determining a code block corresponding to the method name of the encrypted code block according to the method name of the encrypted code block and the abstract syntax tree;
encrypting the code block based on a predefined encryption method to generate an encrypted code block;
and continuously compiling the encrypted code blocks and the unencrypted code blocks through a compiler to generate target machine codes corresponding to the target source codes.
It should be noted that, the functions or steps that can be implemented by the computer device may be correspondingly referred to the related descriptions in the foregoing method embodiments, and will not be described herein for avoiding repetition.
Those skilled in the art will appreciate that implementing all or part of the above described methods may be accomplished by way of a computer program stored on a non-transitory computer readable storage medium, which when executed, may comprise the steps of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in embodiments provided herein may include non-volatile and/or volatile memory. The nonvolatile memory can include Read Only Memory (ROM), programmable ROM (PROM), electrically Programmable ROM (EPROM), electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double Data Rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous Link DRAM (SLDRAM), memory bus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), among others.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-described division of the functional units and modules is illustrated, and in practical application, the above-described functional distribution may be performed by different functional units and modules according to needs, i.e. the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-described functions.
The above embodiments are only for illustrating the technical solution of the present application, and not for limiting the same; although the application has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present application, and are intended to be included in the scope of the present application.
Claims (10)
1. A method for encrypting source code, comprising:
acquiring a target source code, and determining the method name of an encrypted code block in the target source code according to the target source code;
inputting the target source code to a compiler to generate an abstract syntax tree of the target source code;
determining a code block corresponding to the method name of the encrypted code block according to the method name of the encrypted code block and the abstract syntax tree;
encrypting the code block based on a predefined encryption method to generate an encrypted code block;
and continuously compiling the encrypted code blocks and the unencrypted code blocks through a compiler to generate target machine codes corresponding to the target source codes.
2. The method according to claim 1, wherein the abstract syntax tree comprises method names of a plurality of code blocks, and wherein the determining the code block corresponding to the method name of the encrypted code block according to the method name of the encrypted code block and the abstract syntax tree comprises:
sequentially judging whether the method names of the code blocks are the same as the method names of the encrypted code blocks;
and if the code blocks are the same, determining the code blocks corresponding to the same method names as the code blocks corresponding to the method names of the encrypted code blocks.
3. The method of claim 1, wherein the code block is a string of a plurality of characters, and wherein encrypting the code block based on the predefined encryption method generates an encrypted code block comprises:
acquiring a character string corresponding to the code block;
and converting the character strings corresponding to the code blocks into second character strings corresponding to the code blocks through UTF16 coding operation.
4. The method of claim 3, wherein converting the string corresponding to the code block into the second string corresponding to the code block by a UTF16 encoding operation comprises:
decomposing the character string corresponding to the code block into a plurality of characters;
and sequentially converting the plurality of characters into unified codes corresponding to UTF16, and combining and connecting the unified codes corresponding to UTF16 to generate a second character string corresponding to the code block.
5. The method of claim 3, wherein after converting the character string corresponding to the code block into the second character string corresponding to the code block through the UTF16 encoding operation, further comprising:
and converting the second character string corresponding to the code block into a third character string corresponding to the code block through a Base64 coding operation.
6. The method of claim 5, wherein converting the second string corresponding to the code block into the third string corresponding to the code block by a Base64 encoding operation comprises:
decomposing a second character string corresponding to the code block into a plurality of characters;
and sequentially converting the plurality of characters into unified codes corresponding to the Base64, and combining and connecting the unified codes corresponding to the Base64 to generate a third character string corresponding to the code block.
7. The method according to any one of claims 1 to 6, wherein the compiling, by the compiler, of the encrypted code block and the unencrypted code block is continued, and after generating the target machine code corresponding to the target source code, further comprises:
acquiring a target machine code corresponding to a target source code;
and after decrypting the encrypted code block based on a predefined decryption method, running the target machine code.
8. An encryption apparatus for source code, comprising:
the acquisition module is used for: the method comprises the steps of obtaining a target source code, and determining the method name of an encrypted code block in the target source code according to the target source code;
a first generation module: the abstract syntax tree is used for inputting the target source code to the compiler and generating the target source code;
and a determination module: the code block corresponding to the method name of the encrypted code block is determined according to the method name of the encrypted code block and the abstract syntax tree;
an encryption module: the encryption method comprises the steps of encrypting the code blocks based on a predefined encryption method to generate encrypted code blocks;
and a second generation module: and the compiler is used for continuously compiling the encrypted code blocks and the unencrypted code blocks to generate target machine codes corresponding to the target source codes.
9. A storage medium having a computer program stored therein, wherein the computer program is configured to perform the method of any of claims 1 to 7 when run.
10. An electronic device comprising a processor and a memory, wherein the memory has stored therein a computer program, the processor being configured to run the computer program to perform the method of any of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310891178.9A CN117093964A (en) | 2023-07-19 | 2023-07-19 | Encryption method and device of source code, storage medium and electronic equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310891178.9A CN117093964A (en) | 2023-07-19 | 2023-07-19 | Encryption method and device of source code, storage medium and electronic equipment |
Publications (1)
Publication Number | Publication Date |
---|---|
CN117093964A true CN117093964A (en) | 2023-11-21 |
Family
ID=88772619
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202310891178.9A Pending CN117093964A (en) | 2023-07-19 | 2023-07-19 | Encryption method and device of source code, storage medium and electronic equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN117093964A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN118041534A (en) * | 2024-04-12 | 2024-05-14 | 浙江金网信息产业股份有限公司 | Encryption method for dynamic operator of source code |
-
2023
- 2023-07-19 CN CN202310891178.9A patent/CN117093964A/en active Pending
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN118041534A (en) * | 2024-04-12 | 2024-05-14 | 浙江金网信息产业股份有限公司 | Encryption method for dynamic operator of source code |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
JP6257754B2 (en) | Data protection | |
JP5996810B2 (en) | Self-rewriting platform application code obfuscation device and method | |
US8681976B2 (en) | System and method for device dependent and rate limited key generation | |
KR101216995B1 (en) | A code encryption and decryption device against reverse engineering based on indexed table and the method thereof | |
US11934539B2 (en) | Method and apparatus for storing and processing application program information | |
CN110084599B (en) | Key processing method, device, equipment and storage medium | |
CN112966227A (en) | Code encryption and decryption method and device and storage medium | |
CN110855433A (en) | Data encryption method and device based on encryption algorithm and computer equipment | |
CN109948309A (en) | A code protection method, apparatus, computer equipment and storage medium | |
CN114139117A (en) | Application program reinforcing method and device, electronic equipment and storage medium | |
CN113420313A (en) | Program safe operation and encryption method and device, equipment and medium thereof | |
CN117093964A (en) | Encryption method and device of source code, storage medium and electronic equipment | |
CN106209346A (en) | Whitepack cryptographic technique is interlocked look-up table | |
CN111291333A (en) | Java application program encryption method and device | |
CN105447398A (en) | Data safety protection method and device | |
KR101699176B1 (en) | Hadoop Distributed File System Data Encryption and Decryption Method | |
CN108376212B (en) | Execution code security protection method and device and electronic device | |
CN116226881A (en) | Source code encryption method based on compiling language | |
EP3876119A1 (en) | Method for protecting a data in a software application | |
CN114039743A (en) | Data encryption method, device, storage medium and terminal | |
EP4154135A1 (en) | Method to secure computer code | |
CN117828555B (en) | Low-cost Java source code protection method and device | |
CN118627090B (en) | Method for generating and running executable files | |
US12362907B2 (en) | Format-preserving data encryption | |
CN109145622A (en) | Tune-up data output control method, mobile terminal and computer readable storage medium |
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 |