CN104866738A - Program code protection method and device - Google Patents

Program code protection method and device Download PDF

Info

Publication number
CN104866738A
CN104866738A CN201410064972.7A CN201410064972A CN104866738A CN 104866738 A CN104866738 A CN 104866738A CN 201410064972 A CN201410064972 A CN 201410064972A CN 104866738 A CN104866738 A CN 104866738A
Authority
CN
China
Prior art keywords
code
program code
encipheror
key
module
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.)
Granted
Application number
CN201410064972.7A
Other languages
Chinese (zh)
Other versions
CN104866738B (en
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.)
Beijing Na Jia Development Of Information Science And Technology Co Ltd
Original Assignee
Beijing Na Jia Development Of Information Science And Technology 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 Beijing Na Jia Development Of Information Science And Technology Co Ltd filed Critical Beijing Na Jia Development Of Information Science And Technology Co Ltd
Priority to CN201410064972.7A priority Critical patent/CN104866738B/en
Publication of CN104866738A publication Critical patent/CN104866738A/en
Application granted granted Critical
Publication of CN104866738B publication Critical patent/CN104866738B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Storage Device Security (AREA)

Abstract

The invention discloses a program code protection method and device, belongs to the technical field of computer terminals and solves the problem that program codes are tampered easily. The method mainly comprises steps as follows: acquiring to-be-protected program codes and key program codes for encrypting the to-be-protected program codes; performing Hash calculation on the key program codes with a preset algorithm to acquire encryption keys; encrypting the to-be-protected program codes by the encryption keys to acquire encrypted program codes. The program code protection method and device are mainly applied to program code tampering prevention processes.

Description

A kind of program code guard method and device
Technical field
The present invention relates to terminal technical field, be specifically related to security of system field, particularly relate to a kind of program code guard method and device.
Background technology
Android is half open source operating system based on Linux, and Linux is a kind of class Unix operating system of free and open source code, so cracker is easy to use dynamic code implantttion technique, destroy the code logic that android system is original, add malicious code logic, android system can not normally be run.
Summary of the invention
In view of this, the embodiment of the present invention provides a kind of program code guard method and device, solves the technical matters that above background technology part is mentioned.
On the one hand, embodiments provide a kind of program code guard method, described method comprises:
Obtain and need the program code of protection and the cipher key procedures code for encrypting the program code that described needs are protected;
According to pre-defined algorithm, Hash calculation is carried out to described cipher key procedures code, obtain encryption key;
Utilize the program code of described encryption key to described needs protection to be encrypted and obtain encipheror code.
On the other hand, the embodiment of the present invention also proposed a kind of program code protective device, and described device comprises:
Acquisition module, for obtaining the program code of needs protection and the cipher key procedures code for encrypting the program code that described needs are protected;
Hash calculation module, for carrying out Hash calculation according to pre-defined algorithm to described cipher key procedures code, obtains encryption key;
Encrypting module, obtains encipheror code for utilizing the program code of described encryption key to described needs protection to be encrypted.
The program code guard method that the embodiment of the present invention proposes and device; when protecting the program code of needs protection; its encryption key draws by carrying out Hash calculation to other program codes; namely a kind of dependence to object is devised as secret key encryption object; then in dependence, any one link is tampered; all cannot decrypt original object, need the program code of protection not to be tampered so can be good at protecting.
Accompanying drawing explanation
By reading the detailed description done non-limiting example done with reference to the following drawings, other features, objects and advantages of the present invention will become more obvious:
Fig. 1 is the process flow diagram of a kind of program code guard method in the embodiment of the present invention;
Fig. 2 is the schematic diagram of a kind of program code guard method in the embodiment of the present invention;
Fig. 3 is a kind of process flow diagram realizing the deciphering of encipheror code in the embodiment of the present invention;
Fig. 4 is the composition frame chart of a kind of program code protective device in the embodiment of the present invention;
Fig. 5 is the composition frame chart of another kind of program code protective device in the embodiment of the present invention;
Fig. 6 is the composition frame chart of another kind of program code protective device in the embodiment of the present invention;
Fig. 7 is the composition frame chart of another kind of program code protective device in the embodiment of the present invention.
Embodiment
Below in conjunction with drawings and Examples, the present invention is described in further detail.Be understandable that, specific embodiment described herein is only for explaining the present invention, but not limitation of the invention.It also should be noted that, for convenience of description, illustrate only part related to the present invention in accompanying drawing but not full content.
Embodiments provide a kind of program code guard method, as shown in Figure 1, the method comprises:
101, the program code needing to protect and the cipher key procedures code for encrypting the program code that described needs are protected is obtained.
Wherein, this secret key code program obtains encryption, the decruption key of the program code of encryption needs protection for carrying out Hash calculation; it also can be able to be the program code not having to encrypt (namely not needing to protect) for the program code of encryption, and the embodiment of the present invention does not limit this.This cipher key procedures code can be a program code, and also can be multiple program code, the concrete embodiment of the present invention limit this.
102, according to pre-defined algorithm, Hash calculation is carried out to described cipher key procedures code, obtain encryption key.
Wherein, this cipher key procedures code carries out the pre-defined algorithm of Hash calculation, can to comprise in MD2, MD4, MD5 and SHA-1 any number of for algorithm, the embodiment of the present invention does not limit this, and the existing Hash calculation method of any one can be applied in embodiments of the invention.And when encrypting and decrypting, use can be same algorithm, the encryption key drawn and decruption key are identical, namely adopt symmetric encipherment algorithm; Can certainly use rivest, shamir, adelman, although the encryption key drawn is different with decruption key, it is that pairing uses.
103, utilize the program code of described encryption key to described needs protection to be encrypted and obtain encipheror code.
Program code guard method is stated below in conjunction with instantiation; as shown in Figure 2; one section of program code comprises three functions; the corresponding one section of program code block of each function; these three functions are respectively A function, B function, C function; the program code will protected in Original program code block is B function, and cipher key procedures code is unprotected A function and C function.According to pre-defined algorithm, Hash calculation is carried out to A function and C function, obtain encryption key; Utilize described encryption key to be encrypted B function and obtain encipheror code.
Further, after the program code of needs protection is encrypted, when program code execution, need first to be decrypted the program code of encryption, obtain Original program code, perform again afterwards.But because the cipher key procedures code calculating encryption key may be positioned at before this encipheror code; also after may being; so; in order to can program code perform in; the decruption key of smooth acquisition encipheror code, needs, while utilizing described encryption key to be encrypted the program code that described needs are protected to obtain encipheror code, to arrange the address link obtaining decruption key; so that during executive routine code, obtain the decruption key of described encipheror code.
Further, based on the setting of address above mentioned link, when executive routine code, when performing encipheror code, the invention provides program code guard method, to realize the deciphering of encipheror code, as shown in Figure 3, the method comprises:
201, perform described address chain to obtain and get described cipher key procedures code.
202, according to pre-defined algorithm, Hash calculation is carried out to described cipher key procedures code, obtain decruption key.
203, described decruption key is utilized to be decrypted described encipheror code; If successful decryption, then perform 204; If decipher unsuccessful, then perform 205.
Wherein, if successful decryption, illustrate that the cipher key procedures code obtaining decruption key relevant was not tampered; If decipher unsuccessful, illustrate that the cipher key procedures code obtaining decruption key relevant was tampered.
204, the program code after deciphering is performed.
205, the information that written-out program code is tampered is pointed out.
Wherein, the embodiment of the present invention is when carrying out the information prompting that program code is tampered, and can pass through but be not limited to following mode to realize, which be a kind of or any number of combination of following form, and this form comprises: word, sound, figure, video.
Based on the ciphering process that Fig. 2 describes, when program code performs the B function after encryption, the address chain that execution pre-sets is obtained and is got A function and C function, carries out Hash calculation, obtain decruption key according to pre-defined algorithm to A function and C function; The B function of decruption key to encryption is utilized to be decrypted; If rogue program has distorted the code of A function or C function, then, when carrying out Hash calculation according to pre-defined algorithm to A function and C function, the decruption key obtained will change, then normally can not decipher B function ciphertext, cause program to perform.So only have when A and C code block data integrity, when not distorted by rogue program, just can normally perform B-code block.Such as, in android system, the encryption key obtained by the Hash calculation of SO file is encrypted by DEX file, exists, so DEX data cannot be distorted with ciphertext form; The Hash of SO file can as the key of deciphering DEX file.If so distort SO file content, then DEX can not normally decipher, DEX will be caused to perform.
Based on said method, the embodiment of the present invention also provides a kind of program code protective device, and as shown in Figure 4, this device comprises:
Acquisition module 31, for obtaining the program code of needs protection and the cipher key procedures code for encrypting the program code that described needs are protected.Wherein, this secret key code program obtains encryption, the decruption key of the program code of encryption needs protection for carrying out Hash calculation; it also can be able to be the program code not having to encrypt (namely not needing to protect) for the program code of encryption, and the embodiment of the present invention does not limit this.This cipher key procedures code can be a program code, and also can be multiple program code, the concrete embodiment of the present invention limit this.
Hash calculation module 32, for carrying out Hash calculation according to pre-defined algorithm to described cipher key procedures code, obtains encryption key.Wherein, this cipher key procedures code is carried out to the pre-defined algorithm of Hash calculation, the embodiment of the present invention does not limit this, and the existing Hash calculation method of any one can be applied in embodiments of the invention.And when encrypting and decrypting, use can be same algorithm, the encryption key drawn and decruption key are identical, namely adopt symmetric encipherment algorithm; Can certainly use rivest, shamir, adelman, although the encryption key drawn is different with decruption key, it is that pairing uses.
Encrypting module 33, obtains encipheror code for utilizing the program code of described encryption key to described needs protection to be encrypted.
Further, after the program code of needs protection is encrypted, when program code execution, need first to be decrypted the program code of encryption, obtain Original program code, perform again afterwards.But because the cipher key procedures code calculating encryption key may be positioned at before this encipheror code; also after may being; so; in order to can program code perform in; the decruption key of smooth acquisition encipheror code, needs, while utilizing described encryption key to be encrypted the program code that described needs are protected to obtain encipheror code, also to need to arrange the instruction obtaining cipher key procedures code; as shown in Figure 5, this device also comprises:
Module 34 is set; for utilize at described encrypting module 33 described encryption key to described need the program code of protection to be encrypted and to obtain encipheror code while; the address link obtaining decruption key is set; so that during executive routine code, obtain the decruption key of described encipheror code.
Further, as shown in Figure 6, this device also comprises:
Instruct execution module 35, during for performing described encipheror code place when program code, performs described address chain and obtains and get described cipher key procedures code.
Described Hash calculation module 32 also for, according to pre-defined algorithm, Hash calculation is carried out to described cipher key procedures code, obtains decruption key.
Deciphering module 36, is decrypted described encipheror code for utilizing described decruption key.
Program code execution module 37, for when described deciphering module 36 is to described encipheror code decryption success, performs the program code after deciphering.
Further, as shown in Figure 7, this device also comprises:
Message output module 38, for when described deciphering module 36 is unsuccessful to described encipheror code decryption, the information prompting that written-out program code is tampered.Wherein, the embodiment of the present invention is when carrying out the information prompting that program code is tampered, and can pass through but be not limited to following mode to realize, which be a kind of or any number of combination of following form, and this form comprises: word, sound, figure, video.
The program code guard method that the embodiment of the present invention proposes and device; when protecting the program code of needs protection; its encryption, decruption key draw by carrying out Hash calculation to other program codes; namely a kind of dependence to object is devised as secret key encryption object; then in dependence, any one link is tampered; all cannot decrypt original object, need the program code of protection not to be tampered so can be good at protecting.
Further, whether the embodiment of the present invention can also well be tampered by trace routine code, if be tampered, then can export information, informs that user knows that plant maintenance person processes timely.
The above; be only the specific embodiment of the present invention, but protection scope of the present invention is not limited thereto, is anyly familiar with those skilled in the art in the technical scope that the present invention discloses; change can be expected easily or replace, all should be encompassed within protection scope of the present invention.Therefore, protection scope of the present invention should described be as the criterion with the protection domain of claim.

Claims (10)

1. a program code guard method, is characterized in that, described method comprises:
Obtain and need the program code of protection and the cipher key procedures code for encrypting the program code that described needs are protected;
According to pre-defined algorithm, Hash calculation is carried out to described cipher key procedures code, obtain encryption key;
Utilize the program code of described encryption key to described needs protection to be encrypted and obtain encipheror code.
2. program code guard method according to claim 1, is characterized in that, utilize described encryption key to described need the program code of protection to be encrypted and to obtain encipheror code while, also comprise:
The address link obtaining decruption key is set, so that during executive routine code, obtains the decruption key of described encipheror code.
3. program code guard method according to claim 2, is characterized in that, when program code performs described encipheror code place, also comprises:
Perform described address chain to obtain and get described cipher key procedures code;
According to pre-defined algorithm, Hash calculation is carried out to described cipher key procedures code, obtain decruption key;
Described decruption key is utilized to be decrypted described encipheror code;
If successful decryption, then perform the program code after deciphering.
4. program code guard method according to claim 3, is characterized in that, also comprise:
If decipher unsuccessful, then the information that written-out program code is tampered is pointed out.
5. program code guard method according to claim 4, is characterized in that, described information prompting can be a kind of or any number of combination of following form, and this form comprises: word, sound, figure, video.
6. a program code protective device, is characterized in that, described device comprises:
Acquisition module, for obtaining the program code of needs protection and the cipher key procedures code for encrypting the program code that described needs are protected;
Hash calculation module, for carrying out Hash calculation according to pre-defined algorithm to described cipher key procedures code, obtains encryption key;
Encrypting module, obtains encipheror code for utilizing the program code of described encryption key to described needs protection to be encrypted.
7. program code protective device according to claim 6, is characterized in that, also comprise:
Module is set; for utilize at described encrypting module described encryption key to described need the program code of protection to be encrypted and to obtain encipheror code while; the address link obtaining decruption key is set, so that during executive routine code, obtains the decruption key of described encipheror code.
8. program code protective device according to claim 7, is characterized in that, also comprise:
Instruct execution module, during for performing described encipheror code place when program code, performs described address chain and obtains and get described cipher key procedures code;
Described Hash calculation module also for, according to pre-defined algorithm, Hash calculation is carried out to described cipher key procedures code, obtains decruption key;
Deciphering module, is decrypted described encipheror code for utilizing described decruption key;
Program code execution module, for when described deciphering module is to described encipheror code decryption success, performs the program code after deciphering.
9. program code protective device according to claim 8, is characterized in that, also comprise:
Message output module, for when described deciphering module is unsuccessful to described encipheror code decryption, the information prompting that written-out program code is tampered.
10. program code protective device according to claim 9, is characterized in that, described information prompting can be a kind of or any number of combination of following form, and this form comprises: word, sound, figure, video.
CN201410064972.7A 2014-02-25 2014-02-25 A kind of program code guard method and device Active CN104866738B (en)

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 true CN104866738A (en) 2015-08-26
CN104866738B 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)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105450662A (en) * 2015-12-25 2016-03-30 小米科技有限责任公司 Encryption method and device
CN108256346A (en) * 2016-12-28 2018-07-06 中移(杭州)信息技术有限公司 Guard method, encipherment protection device and the embedded system device of critical data
CN108390759A (en) * 2018-03-21 2018-08-10 平安普惠企业管理有限公司 Code encryption, decryption method, device, computer equipment and storage medium
CN111523128A (en) * 2020-04-03 2020-08-11 咪咕文化科技有限公司 Information protection method, system, electronic device and medium

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060123025A1 (en) * 2000-06-27 2006-06-08 Microsoft Corporation System and method for activating a rendering device in a multi-level rights-management architecture
CN101976322A (en) * 2010-11-11 2011-02-16 清华大学 Safety metadata management method based on integrality checking
CN102236757A (en) * 2011-06-30 2011-11-09 北京邮电大学 Software protection method and system applicable to Android system
CN102291237A (en) * 2010-06-10 2011-12-21 株式会社理光 Information protection apparatus, information protection method, and storage medium
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
CN102567688A (en) * 2011-11-30 2012-07-11 中标软件有限公司 File confidentiality keeping system and file confidentiality keeping method on Android operating system
CN103530201A (en) * 2013-07-17 2014-01-22 华中科技大学 Safety data repetition removing method and system applicable to backup system

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060123025A1 (en) * 2000-06-27 2006-06-08 Microsoft Corporation System and method for activating a rendering device in a multi-level rights-management architecture
US8091125B1 (en) * 2002-01-14 2012-01-03 Fs Networks, Inc. Method and system for performing asynchronous cryptographic operations
CN102291237A (en) * 2010-06-10 2011-12-21 株式会社理光 Information protection apparatus, information protection method, and storage medium
CN101976322A (en) * 2010-11-11 2011-02-16 清华大学 Safety metadata management method based on integrality checking
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
CN102567688A (en) * 2011-11-30 2012-07-11 中标软件有限公司 File confidentiality keeping system and file confidentiality keeping method on Android operating system
CN103530201A (en) * 2013-07-17 2014-01-22 华中科技大学 Safety data repetition removing method and system applicable to backup system

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
李琴: ""利用DES加密算法保护Java源代码"", 《计算机与信息技术》 *

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105450662A (en) * 2015-12-25 2016-03-30 小米科技有限责任公司 Encryption method and device
CN108256346A (en) * 2016-12-28 2018-07-06 中移(杭州)信息技术有限公司 Guard method, encipherment protection device and the embedded system device of critical data
CN108390759A (en) * 2018-03-21 2018-08-10 平安普惠企业管理有限公司 Code encryption, decryption method, device, computer equipment and storage medium
CN111523128A (en) * 2020-04-03 2020-08-11 咪咕文化科技有限公司 Information protection method, system, electronic device and medium
CN111523128B (en) * 2020-04-03 2023-12-08 咪咕文化科技有限公司 Information protection method, system, electronic equipment and medium

Also Published As

Publication number Publication date
CN104866738B (en) 2019-04-26

Similar Documents

Publication Publication Date Title
US8767959B2 (en) Block encryption
CN104573528B (en) A kind of anti-copy Soc starting method and chip
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
CN107896223A (en) A kind of data processing method and system, data collecting system and data receiving system
CN103378971A (en) Data encryption system and method
CN102594549B (en) Multistage data encryption and decryption methods
CN104866784A (en) BIOS encryption-based safety hard disk, and data encryption and decryption method
CN105468935A (en) Method, sending end, tool end and burning end for guaranteeing safe burning of KEY
CN108270574B (en) Safe loading method and device for white list library file
CN104660590A (en) Cloud storage scheme for file encryption security
CN112653719A (en) Automobile information safety storage method and device, electronic equipment and storage medium
CN105184181A (en) File encryption method, file decryption method and file encryption device
CN104866738B (en) A kind of program code guard method and device
CN104601820A (en) Mobile terminal information protection method based on TF password card
CN109510702A (en) A method of it key storage based on computer characteristic code and uses
CN105915345B (en) The implementation method of licensed-type production and restructuring in a kind of family gateway equipment production test
CN104038828A (en) RSA hash signature content protection optimizing method based on AES encryption
CN109857421A (en) The encryption upgrade method and system of embedded device
CN109495255A (en) Digital cryptographic key protection method and its system based on android system
CN104954362A (en) Serial number encryption-decryption method and device
CN104717213A (en) Encryption and decryption method and system for network data transmission
CN103605927A (en) Encryption and decryption method based on embedded Linux system
CN102546151A (en) Data encryption and decryption method
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