CN104866738B - A kind of program code guard method and device - Google Patents
A kind of program code guard method and device Download PDFInfo
- Publication number
- CN104866738B CN104866738B CN201410064972.7A CN201410064972A CN104866738B CN 104866738 B CN104866738 B CN 104866738B CN 201410064972 A CN201410064972 A CN 201410064972A CN 104866738 B CN104866738 B CN 104866738B
- Authority
- CN
- China
- Prior art keywords
- code
- program code
- key
- protected
- encipheror
- 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.)
- Active
Links
Abstract
The invention discloses a kind of program code guard method and devices, terminal technical field, solve the problems, such as that program code is easy to be tampered.Main method of the invention includes: to obtain to need program code to be protected and the cipher key procedures code for encrypting the need program code to be protected;Hash calculation is carried out to the cipher key procedures code according to pre-defined algorithm, obtains encryption key;The need program code to be protected is encrypted to obtain encipheror code using the encryption key.Present invention is mainly used for program code it is anti-tamper during.
Description
Technical field
The present invention relates to terminal technical fields, and in particular to system security fields more particularly to a kind of program generation
Code protection method and device.
Background technique
Android is half open source operating system based on Linux, and Linux is a kind of free and open source
The class Unix operating system of code, so cracker is easy to that it is original to destroy android system using dynamic code injection technique
Malicious code logic is added, so that android system is not normally functioning in code logic.
Summary of the invention
In view of this, the embodiment of the present invention provides a kind of program code guard method and device, to solve background above skill
The technical issues of art part is mentioned.
On the one hand, the embodiment of the invention provides a kind of program code guard methods, which comprises
Obtaining needs program code to be protected and the cipher key procedures generation for encrypting the need program code to be protected
Code;
Hash calculation is carried out to the cipher key procedures code according to pre-defined algorithm, obtains encryption key;
The need program code to be protected is encrypted to obtain encipheror code using the encryption key.
On the other hand, the embodiment of the present invention also proposed a kind of program code protective device, and described device includes:
Module is obtained, needs program code to be protected and for encrypting the need program code to be protected for obtaining
Cipher key procedures code;
Hash calculation module is encrypted for carrying out Hash calculation to the cipher key procedures code according to pre-defined algorithm
Key;
Encrypting module, for being encrypted using the encryption key to the need program code to be protected
Program code.
The program code guard method and device that the embodiment of the present invention proposes are protected to need program code to be protected
When shield, encryption key be by other program codes carry out Hash calculation obtain, that is, devise a kind of pair of object according to
The relationship of relying is as key encrypted object, then any one link is tampered in dependence, can not all decrypt original object,
Program code to be protected is needed not to be tampered so can be good at protection.
Detailed description of the invention
By reading a detailed description of non-restrictive embodiments in the light of the attached drawings below, of the invention other
Feature, objects and advantages will become more apparent upon:
Fig. 1 is a kind of flow chart of program code guard method in the embodiment of the present invention;
Fig. 2 is a kind of schematic diagram of program code guard method in the embodiment of the present invention;
Fig. 3 is a kind of flow chart for the decryption for realizing encipheror code in the embodiment of the present invention;
Fig. 4 is a kind of composition block diagram of program code protective device in the embodiment of the present invention;
Fig. 5 is the composition block diagram of another program code protective device in the embodiment of the present invention;
Fig. 6 is the composition block diagram of another program code protective device in the embodiment of the present invention;
Fig. 7 is the composition block diagram of another program code protective device in the embodiment of the present invention.
Specific embodiment
The present invention is described in further detail with reference to the accompanying drawings and examples.It is understood that this place is retouched
The specific embodiment stated is used only for explaining the present invention rather than limiting the invention.It also should be noted that in order to just
In description, only some but not all contents related to the present invention are shown in the drawings.
The embodiment of the invention provides a kind of program code guard methods, as shown in Figure 1, this method comprises:
101, obtaining needs program code to be protected and the key journey for encrypting the need program code to be protected
Sequence code.
Wherein, the secret cipher key code program be used to carry out Hash calculation obtain encryption need program code to be protected encryption,
Decruption key can may be the program code for not encrypting and (not needing to protect), this hair for the program code of encryption
Bright embodiment is not limited this.The cipher key procedures code can be a program code, be also possible to multiple program codes,
It is specific that it is not limited by the embodiments of the present invention.
102, Hash calculation is carried out to the cipher key procedures code according to pre-defined algorithm, obtains encryption key.
Wherein, the cipher key procedures code carry out Hash calculation pre-defined algorithm, can for algorithm include MD2, MD4, MD5 and
Any number of in SHA-1, it is not limited by the embodiments of the present invention, and any existing Hash calculation method can answer
With in an embodiment of the present invention.And when being encrypted and decrypted, what is used can be the same algorithm, the encryption obtained
Key and decruption key be it is identical, that is, use symmetric encipherment algorithm;Rivest, shamir, adelman can certainly be used, is obtained
Although encryption key and decruption key are different, its pairing is used.
103, the need program code to be protected is encrypted to obtain encipheror code using the encryption key.
Program code guard method is stated below in conjunction with specific example, as shown in Fig. 2, one section of program code includes three
A function, the corresponding one section of program code block of each function, which is respectively A function, B function, C function, original program
Program code to be protected is B function in code block, and cipher key procedures code is unprotected A function and C function.According to predetermined calculation
Method carries out Hash calculation to A function and C function, obtains encryption key;B function is encrypted to obtain using the encryption key
Encipheror code.
Further, it after to needing program code to be protected to encrypt, in program code execution, needs to encryption
Program code be first decrypted, obtain Original program code, execute again later.But the key journey due to calculating encryption key
Sequence code is likely located at before the encipheror code, it is also possible to below, so, in order to what is executed in program code
When, the decruption key of encipheror code is smoothly obtained, is needed to be protected to the need using the encryption key
While program code is encrypted to obtain encipheror code, setting obtains the address link of decruption key, to execute journey
When sequence code, the decruption key of the encipheror code is obtained.
Further, the setting based on address above mentioned link, when executing program code, when going to encipheror code
When, the present invention provides program code guard method, to realize the decryption of encipheror code, as shown in figure 3, this method
Include:
201, the execution address chain, which is obtained, takes the cipher key procedures code.
202, Hash calculation is carried out to the cipher key procedures code according to pre-defined algorithm, obtains decruption key.
203, the encipheror code is decrypted using the decruption key;If successful decryption executes 204;
If decryption is unsuccessful, 205 are executed.
Wherein, if successful decryption, illustrate that obtaining the relevant cipher key procedures code of decruption key was not tampered with;If decryption
It is unsuccessful, illustrate that obtaining the relevant cipher key procedures code of decruption key had been tampered with.
204, the program code after decryption is executed.
205, the information alert that output program code is tampered.
Wherein, the embodiment of the present invention carry out program code be tampered information alert when, can by but be not limited to
Mode below realizes which is one kind or any number of combination of following form, which includes: text, sound, figure
Shape, video.
Based on the ciphering process of Fig. 2 description, when program code goes to encrypted B function, execute pre-set
Address chain, which is obtained, takes A function and C function, carries out Hash calculation to A function and C function according to pre-defined algorithm, obtains decruption key;
It is decrypted using B function of the decruption key to encryption;If rogue program has distorted the code of A function or C function, pressing
When carrying out Hash calculation to A function and C function according to pre-defined algorithm, obtained decruption key will be changed, then cannot normally decrypt B
Function ciphertext causes program that can not execute.So only when A and C code block number evidence are complete, when not distorted by rogue program,
It just can normally execute B-code block.For example, in android system, DEX file will be obtained with the Hash calculation of SO file
Encryption key is encrypted, and is existed with ciphertext form, so DEX data can not distort;The Hash of SO file can be as decryption DEX
The key of file.So DEX cannot be decrypted normally if distorting SO file content, cause DEX that can not execute.
Based on the above method, the embodiment of the present invention also provides a kind of program code protective device, as shown in figure 4, the device
Include:
Module 31 is obtained, needs program code to be protected and for encrypting the need program generation to be protected for obtaining
The cipher key procedures code of code.Wherein, which needs program generation to be protected for carrying out Hash calculation acquisition encryption
The encryption of code, decruption key can may be the program for not encrypting and (not needing to protect) for the program code of encryption
Code, it is not limited by the embodiments of the present invention.The cipher key procedures code can be a program code, be also possible to multiple
Program code, specific it is not limited by the embodiments of the present invention.
Hash calculation module 32 is added for carrying out Hash calculation to the cipher key procedures code according to pre-defined algorithm
Key.Wherein, the pre-defined algorithm of Hash calculation is carried out to the cipher key procedures code, the embodiment of the present invention is to this without limit
System, any existing Hash calculation method can be using in an embodiment of the present invention.And carrying out encryption reconciliation
When close, what is used can be the same algorithm, the encryption key and decruption key obtained be it is identical, i.e., using symmetric cryptography calculate
Method;Rivest, shamir, adelman can certainly be used, although the encryption key and decruption key obtained is different, it is pairing
It uses.
Encrypting module 33 is added for being encrypted using the encryption key to the need program code to be protected
Close program code.
Further, it after to needing program code to be protected to encrypt, in program code execution, needs to encryption
Program code be first decrypted, obtain Original program code, execute again later.But the key journey due to calculating encryption key
Sequence code is likely located at before the encipheror code, it is also possible to below, so, in order to what is executed in program code
When, the decruption key of encipheror code is smoothly obtained, is needed to be protected to the need using the encryption key
While program code is encrypted to obtain encipheror code, it is also necessary to which setting obtains the instruction of cipher key procedures code, such as Fig. 5
It is shown, the device further include:
Setup module 34, for utilizing the encryption key to the need program generation to be protected in the encrypting module 33
While code is encrypted to obtain encipheror code, setting obtains the address link of decruption key, to execute program code
When, obtain the decruption key of the encipheror code.
Further, as shown in fig. 6, the device further include:
Instruction execution module 35, for executing the address when program code is gone at the encipheror code
Link obtains the cipher key procedures code.
The Hash calculation module 32 is also used to, and carries out Hash calculation to the cipher key procedures code according to pre-defined algorithm,
Obtain decruption key.
Deciphering module 36, for the encipheror code to be decrypted using the decruption key.
Program code execution module 37 is used for when the deciphering module 36 is to encipheror code decryption success,
Program code after executing decryption.
Further, as shown in fig. 7, the device further include:
Message output module 38 is used for when the deciphering module 36 is unsuccessful to the encipheror code decryption, defeated
The information alert that program code is tampered out.Wherein, the embodiment of the present invention carry out program code be tampered information alert when,
Can by but be not limited to mode below and realize, which is one kind or any number of combination of following form, the form
It include: text, sound, figure, video.
The program code guard method and device that the embodiment of the present invention proposes are protected to need program code to be protected
When shield, encryption, decruption key are obtained by carrying out Hash calculation to other program codes, that is, devise a kind of pair of object
Dependence as key encrypted object, then any one link is tampered in dependence, can not all be decrypted original
Object needs program code to be protected not to be tampered so can be good at protection.
Also, the embodiment of the present invention can also detect well whether program code is tampered, can be defeated if having been tampered with
Prompt information out informs that user knows that plant maintenance person is timely handled.
The above description is merely a specific embodiment, but scope of protection of the present invention is not limited thereto, any
Those familiar with the art in the technical scope disclosed by the present invention, can easily think of the change or the replacement, and should all contain
Lid is within protection scope of the present invention.Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.
Claims (10)
1. a kind of program code guard method, which is characterized in that the described method includes:
Obtaining needs program code to be protected and the cipher key procedures code for encrypting the need program code to be protected,
In, the cipher key procedures code is other program codes in addition to the need program code to be protected;
Hash calculation is carried out to the cipher key procedures code according to pre-defined algorithm, obtains encryption key;
The need program code to be protected is encrypted to obtain encipheror code using the encryption key.
2. program code guard method according to claim 1, which is characterized in that in the utilization encryption key to described
While needing program code to be protected to be encrypted to obtain encipheror code, further includes:
The address link for obtaining decruption key is set, when to execute program code, obtains the decryption of the encipheror code
Key.
3. program code guard method according to claim 2, which is characterized in that when program code goes to the encryption
When at program code, further includes:
It executes the address chain and obtains and take the cipher key procedures code;
Hash calculation is carried out to the cipher key procedures code according to pre-defined algorithm, obtains decruption key;
The encipheror code is decrypted using the decruption key;
Program code if successful decryption, after executing decryption.
4. program code guard method according to claim 3, which is characterized in that further include:
If decryption is unsuccessful, information alert that output program code is tampered.
5. program code guard method according to claim 4, which is characterized in that the information alert can be following shape
One kind of formula or any number of combination, the form include: text, sound, figure, video.
6. a kind of program code protective device, which is characterized in that described device includes:
Module is obtained, needs program code to be protected and for encrypting the close of the need program code to be protected for obtaining
Key program code, wherein the cipher key procedures code is other program codes in addition to the need program code to be protected;
Hash calculation module obtains encryption key for carrying out Hash calculation to the cipher key procedures code according to pre-defined algorithm;
Encrypting module, for being encrypted to obtain encipheror to the need program code to be protected using the encryption key
Code.
7. program code protective device according to claim 6, which is characterized in that further include:
Setup module, for being added using the encryption key to the need program code to be protected in the encrypting module
Close setting obtains the address link of decruption key while obtain encipheror code, when to execute program code, obtains institute
State the decruption key of encipheror code.
8. program code protective device according to claim 7, which is characterized in that further include:
Instruction execution module, for executing the address chain and obtaining when program code is gone at the encipheror code
Take the cipher key procedures code;
The Hash calculation module is also used to, and is carried out Hash calculation to the cipher key procedures code according to pre-defined algorithm, is solved
Key;
Deciphering module, for the encipheror code to be decrypted using the decruption key;
Program code execution module, for executing decryption when the deciphering module is to encipheror code decryption success
Program code afterwards.
9. program code protective device according to claim 8, which is characterized in that further include:
Message output module is used for the output program generation when the deciphering module is unsuccessful to the encipheror code decryption
The information alert that code is tampered.
10. program code protective device according to claim 9, which is characterized in that the information alert can be following
One kind of form or any number of combination, the form include: text, sound, figure, video.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410064972.7A CN104866738B (en) | 2014-02-25 | 2014-02-25 | A kind of program code guard method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201410064972.7A CN104866738B (en) | 2014-02-25 | 2014-02-25 | A kind of program code guard method and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN104866738A CN104866738A (en) | 2015-08-26 |
CN104866738B true CN104866738B (en) | 2019-04-26 |
Family
ID=53912562
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201410064972.7A Active CN104866738B (en) | 2014-02-25 | 2014-02-25 | A kind of program code guard method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN104866738B (en) |
Families Citing this family (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105450662A (en) * | 2015-12-25 | 2016-03-30 | 小米科技有限责任公司 | Encryption method and device |
CN108256346B (en) * | 2016-12-28 | 2020-12-01 | 中移(杭州)信息技术有限公司 | Key data protection method, encryption protection device and embedded system device |
CN108390759A (en) * | 2018-03-21 | 2018-08-10 | 平安普惠企业管理有限公司 | Code encryption, decryption method, device, computer equipment and storage medium |
CN111523128B (en) * | 2020-04-03 | 2023-12-08 | 咪咕文化科技有限公司 | Information protection method, system, electronic equipment and medium |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102236757A (en) * | 2011-06-30 | 2011-11-09 | 北京邮电大学 | Software protection method and system applicable to Android system |
US8091125B1 (en) * | 2002-01-14 | 2012-01-03 | Fs Networks, Inc. | Method and system for performing asynchronous cryptographic operations |
CN102509047A (en) * | 2011-11-09 | 2012-06-20 | 北京赛科世纪数码科技有限公司 | Method and system for verifying program code in set-top box |
Family Cites Families (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US7017189B1 (en) * | 2000-06-27 | 2006-03-21 | Microsoft Corporation | System and method for activating a rendering device in a multi-level rights-management architecture |
JP5644194B2 (en) * | 2010-06-10 | 2014-12-24 | 株式会社リコー | Information protection device and information protection program |
CN101976322B (en) * | 2010-11-11 | 2012-05-23 | 清华大学 | Safety metadata management method based on integrality checking |
CN102567688B (en) * | 2011-11-30 | 2015-05-20 | 中标软件有限公司 | File confidentiality keeping system and file confidentiality keeping method on Android operating system |
CN103530201B (en) * | 2013-07-17 | 2016-03-02 | 华中科技大学 | A kind of secure data De-weight method and system being applicable to standby system |
-
2014
- 2014-02-25 CN CN201410064972.7A patent/CN104866738B/en active Active
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US8091125B1 (en) * | 2002-01-14 | 2012-01-03 | Fs Networks, Inc. | Method and system for performing asynchronous cryptographic operations |
CN102236757A (en) * | 2011-06-30 | 2011-11-09 | 北京邮电大学 | Software protection method and system applicable to Android system |
CN102509047A (en) * | 2011-11-09 | 2012-06-20 | 北京赛科世纪数码科技有限公司 | Method and system for verifying program code in set-top box |
Non-Patent Citations (1)
Title |
---|
"利用DES加密算法保护Java源代码";李琴;《计算机与信息技术》;20051231;第64-65页 |
Also Published As
Publication number | Publication date |
---|---|
CN104866738A (en) | 2015-08-26 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN109034796B (en) | Alliance chain-based transaction supervision method, electronic device and readable storage medium | |
KR101744748B1 (en) | Contents protection, encryption and decryption apparatus using white-box cryptography | |
CN102509034B (en) | Software license control method of software license control device | |
CN110889696A (en) | Storage method, device, equipment and medium for alliance block chain secret key based on SGX technology | |
CN104506515A (en) | Firmware protection method and firmware protection device | |
CN104573528B (en) | A kind of anti-copy Soc starting method and chip | |
CN103248650A (en) | Document download method and system | |
CN104866738B (en) | A kind of program code guard method and device | |
CN103378971A (en) | Data encryption system and method | |
CN104866784A (en) | BIOS encryption-based safety hard disk, and data encryption and decryption method | |
CN109005184A (en) | File encrypting method and device, storage medium, terminal | |
CN105468935A (en) | Method, sending end, tool end and burning end for guaranteeing safe burning of KEY | |
CN109245905A (en) | The method that message is digitally signed and is encrypted based on RSA and aes algorithm | |
CN102624710B (en) | Sensitive information transmission method and sensitive information transmission system | |
CN109842589A (en) | A kind of cloud storage encryption method, device, equipment and storage medium | |
CN108270574B (en) | Safe loading method and device for white list library file | |
CN102594549A (en) | Multistage data encryption and decryption methods | |
CN114124364A (en) | Key security processing method, device, equipment and computer readable storage medium | |
CN104038828B (en) | RSA hash signature content protection optimizing method based on AES encryption | |
CN105915345B (en) | The implementation method of licensed-type production and restructuring in a kind of family gateway equipment production test | |
CN109495255A (en) | Digital cryptographic key protection method and its system based on android system | |
CN109857421A (en) | The encryption upgrade method and system of embedded device | |
CN103605927A (en) | Encryption and decryption method based on embedded Linux system | |
CN109510704A (en) | A kind of digital cipher protection system and method based on IOS system | |
CN106549927A (en) | Key preservation, acquisition methods and device |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
EXSB | Decision made by sipo to initiate substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |