Electronic device and method for authenticating software based on blockchain

A method for authenticating a software based on a blockchain implemented in an electronic device. The method includes obtaining a first identification code and a first hash value of a first software; generating a first authentication code; writing the first identification code, the first hash value, and the first authentication code into a blockchain; obtaining a second identification code of a second software to be identified and calculating a second hash value of the second software; determining whether the second hash value of the second software is the same as the first hash value; if the second hash value is the same as the first hash value, generating a second authentication code; determine whether the second authentication code is the same as the first authentication code; and if so determining that the second software is copyrighted.

CROSS-REFERENCE TO RELATED APPLICATIONS

This application claims priority to Chinese Patent Application No. 202010773973.4 filed on Aug. 4, 2020, the contents of which are incorporated by reference herein.

FIELD

The subject matter herein generally relates to blockchain, and particularly to an electronic device and a method for authenticating software based on blockchain.

BACKGROUND

Block chains serves as shared databases, having features of decentralization, cannot be forged, and are easily traceable. The block chains are used for recording important and confidential information. Many software companies record important and confidential information, such as unique identification codes, and hash values of their developed software, on a blockchain. Important and confidential information on the blockchain can identify whether a software is copyrighted. However, unauthorized persons or companies may obtain the hash value through the copyrighted software, and write the information of an uncopyrighted software into the block chain using counterfeit unique identification codes, so that the uncopyrighted software can also be portrayed as valid, thereby causing great loss to the software company that has developed the software.

DETAILED DESCRIPTION

The presented disclosure, including the accompanying drawings, is illustrated by way of examples and not by way of limitation. Several definitions that apply throughout this disclosure will now be presented. It should be noted that references to “an” or “one” embodiment in this disclosure are not necessarily to the same embodiment, and such references mean “at least one.”

Referring toFIG.1, an electronic device (electronic device1) communicates with at least one terminal device2through a network. In one embodiment, the network can be wired network or wireless network. The wireless network can be radio, WI-FI, cellular, satellite, broadcast, etc.

In one embodiment, the electronic device1can be a personal computer, a server, and the like, the server can be a single server, a server cluster, or a cloud server. The terminal device2can be a smart phone or a personal computer.

FIG.2illustrates the electronic device1in one embodiment. The electronic device1includes, but is not limited to, a processor10, a storage device20, and a computer program30. The processor10can execute the computer program30to implement athemethod for authenticating software based on a blockchain.FIG.2illustrates only one example of the electronic device1. Other examples can include more or fewer components than as illustrated or have a different configuration of the various components in other embodiments.

The processor10can be a central processing unit (CPU), a microprocessor, or other data processor chip that performs functions in the electronic device1.

In one embodiment, the storage device20can include various types of non-transitory computer-readable storage mediums. For example, the storage device20can be an internal storage system, such as a flash memory, a random access memory (RAM) for the temporary storage of information, and/or a read-only memory (ROM) for permanent storage of information. The storage device20can also be an external storage system, such as a hard disk, a storage card, or a data storage medium.

As illustrated inFIG.3, the electronic device1runs a software authenticating system100. The software authenticating100at least includes an obtaining module101, a generating module102, a recording module103, a first determining module104, a second determining module105, a transmitting module106, and a downloading module107. The modules101-107can be collections of software instructions stored in the storage device20of the electronic device1and executed by the processor10. The modules101-107also can include functionality represented by hardware or integrated circuits, or by software and hardware combinations, such as a special-purpose processor or a general-purpose processor with special-purpose firmware.

The obtaining module101is configured to obtain a first identification code and a first hash value of a first software.

In one embodiment, the first software can be a software product or program developed and copyrighted by a developer. The first identification code can be a unique identification code of the first software, and the first hash value is calculated by performing a hash algorithm on program files of the first software. The hash algorithm can be a direct addressing method, a digital analysis method, a middle-square method, a folding method, or a random number method. The first identification code and the first hash value are both hexadecimal numbers.

The generating module102is configured to generate a first authentication code by performing an encryption operation on the first identification code and the first hash value.

In one embodiment, the encryption operation can be an exclusive OR operation. The generating module102performs the exclusive OR operation on the first identification code and the first hash value to generate the first authentication code. For example, if the first identification code ID1 is 0x123456, the first hash value Hash1 is 0x0d0d0d, and the exclusive OR operation function is XOR, the first authentication code CK1=(ID1)XOR(Hash1)=0x1f395b.

In other embodiments, the encryption operation includes adding two values and taking last 16 bits of a sum of the two values, that is, the generating module102adds the first identification code and the first hash value, and then takes the last 16 bits of a sum of the first identification code and the first hash value to generate the first authentication code. For example, if the first identification code ID1 is 0x123456 and the first hash value Hash1 is 0x0d0d0d, the first authentication code CK1=[(ID1)+(Hash1)]&0xffff=0x4163.

In one embodiment, the generating module102further encodes the encryption operation into a two-dimensional code algorithm, and performs the two-dimensional code algorithm on the first identification code and the first hash value, to generate the first authentication code, thereby establishing an association between the unique identification code and the hash value of the first software, so as to increase difficulty of breaking the identification code, and further increase difficulty of breaking the first software. In one embodiment, the first identification code can be a two-dimensional code.

The recording module103is configured to write the first identification code, the first hash value, and the first authentication code into a blockchain as authentication information of the first software.

In one embodiment, the recording module103calculates a transaction hash value of the authentication information, that is, re-applies a hash algorithm on the first identification code, the first hash value, and the first authentication code to calculate the transaction hash value. The recording module103further packages the authentication information and the transaction hash value into a transaction block, and writes the transaction block into the blockchain according to an intelligent contact. The block where the identification information is located includes a transaction hash value of a previous written block, the transaction hash value calculated by the recording module103, and a transaction record.

The obtaining module101is further configured to obtain a second identification code of a second software to be authenticated, and calculate a second hash value of the second software.

In one embodiment, when the user downloads the second software through the terminal device2, the obtaining module101determines that the second software is a software product or program to be authenticated, obtains the second identification code of the second software, and calculates the second hash value of the second software. In one embodiment, the second software to be downloaded by the user can be published on a network platform such as a website or an application market by a person other than the developer, and the name and function of the second software are the same as the first software developed by the developer.

When the terminal device2requests a download of the second software, the terminal device2reads the name of the second software. If the name of the second software is the same as the name of the first software, the terminal device2transmits a request for authentication to the electronic device1. When the electronic device1receives the authentication request, the obtaining module101obtains program files of the second software from the terminal device2. When the terminal device2requests the download of the second software, the terminal device2can temporarily download the program files of the second software from a server storing the second software.

The obtaining module101calculates the second hash value of the second software according to the hash algorithm used in calculating the first hash value and the obtained program files of the second software.

The first determining module104is configured to determine whether the second hash value of the second software is the same as the first hash value.

In one embodiment, the second identification code of the second software may be counterfeit or authorized to be the same as the first identification code. The first determining module104can obtain the transaction record corresponding to the first identification code, which is the same as the second identification code from the blockchain. The transaction record includes the first identification code, the first hash value, and the first authentication code. The determining module104further determines whether the second hash value is the same as the first hash value.

In other embodiments, the first determining module104determines whether any transaction record corresponding to the second identification code is recorded in the blockchain. If the first determining module104determines that there is no transaction record corresponding to the second identification code being recorded in the blockchain, the first determining module104determines that the second software is uncopyrighted. If the first determining module104determines that there is at least one transaction record corresponding to the second identification code being recorded in the blockchain, the first determining module104determines whether the second hash value is the same as the first hash value.

If the first determining module104determines that the second hash value of the second software is the same as the first hash value, the generating module102further generates a second authentication code by performing the encryption operation on the second identification code and the second hash value.

It should be noted that, the encryption operation for generating the second authentication code is the same as the encryption operation for generating the first authentication code. In one embodiment, the second authentication code can also be a two-dimensional code.

The first determining module104further determines whether the second authentication code is the same as the first authentication code.

If the first determining module104determines that the second authentication code is the same as the first authentication code, the second determining module105is configured to determine that the second software is copyrighted.

In one embodiment, if the first determining module104determines that the second authentication code is the same as the first authentication code, an association between the second identification code and the hash value of the second software is the same as the association between the first identification code and the hash value of the first software, the second software is thus determined to be copyrighted.

If the first determining module104determines that the second hash value of the second software is different from the first hash value, or determines that the second authentication code is different from the first authentication code, the second determining module105further determines that the second software is uncopyrighted.

If the second determining module105determines that the second software is uncopyrighted, the transmitting module106is configured to issue alarm to the developer of the first software.

In one embodiment, the transmitting module106issues the alarm to a mailbox of a designated person of the developer. The information in the alarm at least includes a network bit address of the second software, publisher information, and text information confirming that the second software is uncopyrighted. In other embodiments, the transmitting module106can also notify the developer of the alarm by telephone.

If the determining module105determines that the second software is copyrighted, the downloading module107is configured to transmit a download instruction to the terminal device2, so as to allow the second software to be stored into the terminal device2.

FIG.4illustrates a flowchart of an embodiment of a method for authenticating a software based on a blockchain. The method is provided by way of example, as there are a variety of ways to carry out the method. The method described below can be carried out using the configurations illustrated inFIGS.1-3, for example, and various elements of these figures are referenced in explaining the example method. Each block shown inFIG.4represents one or more processes, methods, or subroutines carried out in the example method. Furthermore, the illustrated order of blocks is by example only and the order of the blocks can be changed. Additional blocks may be added or fewer blocks may be utilized, without departing from this disclosure. The example method can begin at block401.

At block401, the obtaining module101obtains a first identification code and a first hash value of a first software.

In one embodiment, the first software can be a software product or program developed and copyrighted by a developer. The first identification code can be a unique identification code of the first software, and the first hash value is calculated by performing a hash algorithm on program files of the first software. The hash algorithm can be a direct addressing method, a digital analysis method, a middle-square method, a folding method, or a random number method. The first identification code and the first hash value are both hexadecimal numbers.

At block402, the generating module102generates a first authentication code by performing an encryption operation on the first identification code and the first hash value.

In one embodiment, the encryption operation can be an exclusive OR operation. The generating module102performs the exclusive OR operation on the first identification code and the first hash value to generate the first authentication code. For example, if the first identification code ID1 is 0x123456, the first hash value Hash1 is 0x0d0d0d, and the exclusive OR operation function is XOR, the first authentication code CK1=(ID1)XOR(Hash1)=0x1f395b.

In other embodiments, the encryption operation includes adding two values and taking last 16 bits of a sum of the two values, that is, the generating module102adds the first identification code and the first hash value, and then takes the last 16 bits of a sum of the first identification code and the first hash value to generate the first authentication code. For example, if the first identification code ID1 is 0x123456 and the first hash value Hash1 is 0x0d0d0d, the first authentication code CK1=[(ID1)+(Hash1)]&0xffff=0x4163.

In one embodiment, the generating module102further adds the encryption operation into a two-dimensional code algorithm, and performs the two-dimensional code algorithm on the first identification code and the first hash value, to generate the first authentication code, thereby establishing an association between the unique identification code and the hash value of the first software, so as to increase difficulty of breaking the identification code, and further increase difficulty of breaking the first software. In one embodiment, the first identification code can be a two-dimensional code.

At block403, the recording module103writes the first identification code, the first hash value, and the first authentication code into a blockchain as authentication information of the first software.

In one embodiment, the recording module103calculates a transaction hash value of the authentication information, that is, re-applies a hash algorithm on the first identification code, the first hash value, and the first authentication code to calculate the transaction hash value. The recording module103further packages the authentication information and the transaction hash value into a transaction record, and writes the transaction record into the blockchain according to an intelligent contact. The block where the identification information is located includes a transaction hash value of a previous written block, the transaction hash value calculated by the recording module103, and a transaction record.

At block404, the obtaining module101further obtains a second identification code of a second software to be authenticated, and calculate a second hash value of the second software.

In one embodiment, when the user downloads the second software through the terminal device2, the obtaining module101determines that the second software is a software product or program to be authenticated, obtains the second identification code of the second software, and calculates the second hash value of the second software. In one embodiment, the second software to be downloaded by the user can be published on a network platform such as a website or an application market by a person other than the developer, and the name and function of the second software are the same as the first software developed by the developer.

When the terminal device2requests a download of the second software, the terminal device2reads the name of the second software. If the name of the second software is the same as the name of the first software, the terminal device2transmits a request for authentication to the electronic device1. When the electronic device1receives the authentication request, the obtaining module101obtains program files of the second software from the terminal device2. When the terminal device2requests a download of the second software, the terminal device2can temporarily download the program files of the second software from a server storing the second software.

The obtaining module101calculates the second hash value of the second software according to the hash algorithm used in calculating the first hash value and the obtained program files of the second software.

At block405, the first determining module104determines whether the second hash value of the second software is the same as the first hash value. If the first determining module104determines that the second hash value of the second software is the same as the first hash value, the process goes to block406. If the first determining module104determines that the second hash value of the second software is not the same as the first hash value, the process goes to block410.

In one embodiment, the second identification code of the second software may be counterfeit or authorized to be the same as the first identification code. The first determining module104can obtain the transaction record corresponding to the first identification code, which is the same as the second identification code from the blockchain. The transaction record includes the first identification code, the first hash value, and the first authentication code. The determining module104further determines whether the second hash value is the same as the first hash value.

In other embodiments, the first determining module104determines whether any transaction record corresponding to the second identification code is recorded in the blockchain. If the first determining module104determines that there is no transaction record corresponding to the second identification code being recorded in the blockchain, the first determining module104determines that the second software is uncopyrighted. If the first determining module104determines that there is at least one transaction record corresponding to the second identification code being recorded in the blockchain, the first determining module104determines whether the second hash value is the same as the first hash value.

At block406, the generating module102further generates a second authentication code by performing the encryption operation on the second identification code and the second hash value.

It should be noted that, the encryption operation for generating the second authentication code is the same as the encryption operation for generating the first authentication code. In one embodiment, the second authentication code can also be a two-dimensional code.

At block407, the first determining module104further determines whether the second authentication code is the same as the first authentication code. If the first determining module104determines that the second authentication code is the same as the first authentication code, the process goes to block408. If the first determining module104determines that the second authentication code is not the same as the first authentication code, the process goes to block410.

At block408, the second determining module105determines that the second software is copyrighted.

At block409, the downloading module107transmits a download instruction to the terminal device2, so as to allow the second software to be stored into the terminal device2.

At block410, the second determining module105determines that the second software is uncopyrighted.

At block411, the transmitting module106issues alarm to the developer of the first software.

In one embodiment, the transmitting module106issues the alarm to a mailbox of a designated person of the developer. The information in the alarm at least includes a network bit address of the second software, publisher information, and text information confirming that the second software is uncopyrighted. In other embodiments, the transmitting module106can also notify the developer of the alarm by telephone.