Movatterモバイル変換


[0]ホーム

URL:


CN104866738B - A kind of program code guard method and device - Google Patents

A kind of program code guard method and device
Download PDF

Info

Publication number
CN104866738B
CN104866738BCN201410064972.7ACN201410064972ACN104866738BCN 104866738 BCN104866738 BCN 104866738BCN 201410064972 ACN201410064972 ACN 201410064972ACN 104866738 BCN104866738 BCN 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
Application number
CN201410064972.7A
Other languages
Chinese (zh)
Other versions
CN104866738A (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 LtdfiledCriticalBeijing Na Jia Development Of Information Science And Technology Co Ltd
Priority to CN201410064972.7ApriorityCriticalpatent/CN104866738B/en
Publication of CN104866738ApublicationCriticalpatent/CN104866738A/en
Application grantedgrantedCritical
Publication of CN104866738BpublicationCriticalpatent/CN104866738B/en
Activelegal-statusCriticalCurrent
Anticipated expirationlegal-statusCritical

Links

Landscapes

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

A kind of program code guard method and device
Technical field
The present invention relates to terminal technical fields, and in particular to system security fields more particularly to a kind of program generationCode 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 sourceThe class Unix operating system of code, so cracker is easy to that it is original to destroy android system using dynamic code injection techniqueMalicious 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 skillThe 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 protectedCode;
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 obtainingCipher key procedures code;
Hash calculation module is encrypted for carrying out Hash calculation to the cipher key procedures code according to pre-defined algorithmKey;
Encrypting module, for being encrypted using the encryption key to the need program code to be protectedProgram code.
The program code guard method and device that the embodiment of the present invention proposes are protected to need program code to be protectedWhen shield, encryption key be by other program codes carry out Hash calculation obtain, that is, devise a kind of pair of object according toThe 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 otherFeature, 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 retouchedThe 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 justIn 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 protectedSequence 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 encryptionBright 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 andAny number of in SHA-1, it is not limited by the embodiments of the present invention, and any existing Hash calculation method can answerWith in an embodiment of the present invention.And when being encrypted and decrypted, what is used can be the same algorithm, the encryption obtainedKey and decruption key be it is identical, that is, use symmetric encipherment algorithm;Rivest, shamir, adelman can certainly be used, is obtainedAlthough 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 threeA function, the corresponding one section of program code block of each function, which is respectively A function, B function, C function, original programProgram 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 calculationMethod carries out Hash calculation to A function and C function, obtains encryption key;B function is encrypted to obtain using the encryption keyEncipheror code.
Further, it after to needing program code to be protected to encrypt, in program code execution, needs to encryptionProgram code be first decrypted, obtain Original program code, execute again later.But the key journey due to calculating encryption keySequence code is likely located at before the encipheror code, it is also possible to below, so, in order to what is executed in program codeWhen, the decruption key of encipheror code is smoothly obtained, is needed to be protected to the need using the encryption keyWhile program code is encrypted to obtain encipheror code, setting obtains the address link of decruption key, to execute journeyWhen 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 codeWhen, the present invention provides program code guard method, to realize the decryption of encipheror code, as shown in figure 3, this methodInclude:
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 decryptionIt 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 toMode below realizes which is one kind or any number of combination of following form, which includes: text, sound, figureShape, video.
Based on the ciphering process of Fig. 2 description, when program code goes to encrypted B function, execute pre-setAddress 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, pressingWhen 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 BFunction 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 fileEncryption key is encrypted, and is existed with ciphertext form, so DEX data can not distort;The Hash of SO file can be as decryption DEXThe 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 deviceInclude:
Module 31 is obtained, needs program code to be protected and for encrypting the need program generation to be protected for obtainingThe cipher key procedures code of code.Wherein, which needs program generation to be protected for carrying out Hash calculation acquisition encryptionThe encryption of code, decruption key can may be the program for not encrypting and (not needing to protect) for the program code of encryptionCode, 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 multipleProgram 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 algorithmKey.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 limitSystem, any existing Hash calculation method can be using in an embodiment of the present invention.And carrying out encryption reconciliationWhen 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 calculateMethod;Rivest, shamir, adelman can certainly be used, although the encryption key and decruption key obtained is different, it is pairingIt uses.
Encrypting module 33 is added for being encrypted using the encryption key to the need program code to be protectedClose program code.
Further, it after to needing program code to be protected to encrypt, in program code execution, needs to encryptionProgram code be first decrypted, obtain Original program code, execute again later.But the key journey due to calculating encryption keySequence code is likely located at before the encipheror code, it is also possible to below, so, in order to what is executed in program codeWhen, the decruption key of encipheror code is smoothly obtained, is needed to be protected to the need using the encryption keyWhile 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. 5It 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 33While code is encrypted to obtain encipheror code, setting obtains the address link of decruption key, to execute program codeWhen, 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 codeLink 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, defeatedThe 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 formIt 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 protectedWhen shield, encryption, decruption key are obtained by carrying out Hash calculation to other program codes, that is, devise a kind of pair of objectDependence as key encrypted object, then any one link is tampered in dependence, can not all be decrypted originalObject 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 withPrompt 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, anyThose 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 containLid 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)

CN201410064972.7A2014-02-252014-02-25A kind of program code guard method and deviceActiveCN104866738B (en)

Priority Applications (1)

Application NumberPriority DateFiling DateTitle
CN201410064972.7ACN104866738B (en)2014-02-252014-02-25A kind of program code guard method and device

Applications Claiming Priority (1)

Application NumberPriority DateFiling DateTitle
CN201410064972.7ACN104866738B (en)2014-02-252014-02-25A kind of program code guard method and device

Publications (2)

Publication NumberPublication Date
CN104866738A CN104866738A (en)2015-08-26
CN104866738Btrue CN104866738B (en)2019-04-26

Family

ID=53912562

Family Applications (1)

Application NumberTitlePriority DateFiling Date
CN201410064972.7AActiveCN104866738B (en)2014-02-252014-02-25A kind of program code guard method and device

Country Status (1)

CountryLink
CN (1)CN104866738B (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN105450662A (en)*2015-12-252016-03-30小米科技有限责任公司Encryption method and device
CN108256346B (en)*2016-12-282020-12-01中移(杭州)信息技术有限公司 Key data protection method, encryption protection device and embedded system device
CN108390759A (en)*2018-03-212018-08-10平安普惠企业管理有限公司Code encryption, decryption method, device, computer equipment and storage medium
CN111523128B (en)*2020-04-032023-12-08咪咕文化科技有限公司Information protection method, system, electronic equipment and medium

Citations (3)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
CN102236757A (en)*2011-06-302011-11-09北京邮电大学Software protection method and system applicable to Android system
US8091125B1 (en)*2002-01-142012-01-03Fs Networks, Inc.Method and system for performing asynchronous cryptographic operations
CN102509047A (en)*2011-11-092012-06-20北京赛科世纪数码科技有限公司Method and system for verifying program code in set-top box

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
US7017189B1 (en)*2000-06-272006-03-21Microsoft CorporationSystem and method for activating a rendering device in a multi-level rights-management architecture
JP5644194B2 (en)*2010-06-102014-12-24株式会社リコー Information protection device and information protection program
CN101976322B (en)*2010-11-112012-05-23清华大学Safety metadata management method based on integrality checking
CN102567688B (en)*2011-11-302015-05-20中标软件有限公司File confidentiality keeping system and file confidentiality keeping method on Android operating system
CN103530201B (en)*2013-07-172016-03-02华中科技大学A kind of secure data De-weight method and system being applicable to standby system

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication numberPriority datePublication dateAssigneeTitle
US8091125B1 (en)*2002-01-142012-01-03Fs Networks, Inc.Method and system for performing asynchronous cryptographic operations
CN102236757A (en)*2011-06-302011-11-09北京邮电大学Software protection method and system applicable to Android system
CN102509047A (en)*2011-11-092012-06-20北京赛科世纪数码科技有限公司Method and system for verifying program code in set-top box

Non-Patent Citations (1)

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

Also Published As

Publication numberPublication date
CN104866738A (en)2015-08-26

Similar Documents

PublicationPublication DateTitle
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
CN101651543B (en)Creditable calculation platform key migration system and key migration method thereof
CN110889696A (en)Storage method, device, equipment and medium for alliance block chain secret key based on SGX technology
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
CN104866784A (en)BIOS encryption-based safety hard disk, and data encryption and decryption method
CN114124364B (en)Key security processing method, device, equipment and computer readable storage medium
CN109005184A (en)File encrypting method and device, storage medium, terminal
CN108270574B (en)Safe loading method and device for white list library file
CN109842589A (en)A kind of cloud storage encryption method, device, equipment and storage medium
CN109245905A (en)The method that message is digitally signed and is encrypted based on RSA and aes algorithm
CN105468935A (en)Method, sending end, tool end and burning end for guaranteeing safe burning of KEY
CN113890731A (en)Key management method, key management device, electronic equipment and storage medium
CN102624710B (en)Sensitive information transmission method and sensitive information transmission system
CN113722741A (en)Data encryption method and device and data decryption method and device
CN102594549A (en)Multistage data encryption and decryption methods
CN104038828B (en)RSA hash signature content protection optimizing method based on AES encryption
CN109495255A (en)Digital cryptographic key protection method and its system based on android system
EP3641219A1 (en)Puf based securing of device update
CN105915345B (en)The implementation method of licensed-type production and restructuring in a kind of family gateway equipment production test
CN109857421A (en)The encryption upgrade method and system of embedded device
CN106549927B (en)Key storage and acquisition method and device
CN103605927A (en)Encryption and decryption method based on embedded Linux system

Legal Events

DateCodeTitleDescription
C06Publication
PB01Publication
EXSBDecision made by sipo to initiate substantive examination
SE01Entry into force of request for substantive examination
GR01Patent grant
GR01Patent grant

[8]ページ先頭

©2009-2025 Movatter.jp