Disclosure of Invention
In order to solve the above problems, the present invention provides a block chain HD private key retrieving method to solve the problem that the block chain service private key cannot be retrieved when lost or damaged.
The invention provides a block chain HD private key retrieving method, which comprises the following steps:
creating a root key and a root chain code from the random number via the root seed;
generating a key tree according to the root key, the root chain code and the path identifier, wherein the key tree comprises a plurality of pairs of keys and chain codes;
acquiring a public key address of the secret key according to the path identifier;
creating an address table according to the address and the path identifier of the corresponding public key;
searching a path identifier of a public key address corresponding to the lost service private key based on the address table;
and calculating by using the root key, the root chain code and the path identifier to obtain the service private key.
According to a specific embodiment of the present invention, the root key includes a root private key and a root public key, and the creating the root key and the root chain code via the root seed according to the random number further includes:
calculating the root seed by adopting any one of HMAC-SHA512, HMAC-SHA256 and HMAC-SHA128 algorithms to obtain the root private key and the root chain code;
and calculating to obtain the root public key by adopting an asymmetric algorithm based on the root private key.
According to a specific embodiment of the present invention, the asymmetric algorithm includes any one of an RSA algorithm, an ECC algorithm, an ECDSA algorithm, an SM2 algorithm, and an SM9 algorithm.
According to an embodiment of the present invention, generating a key tree according to the root private key, the root chain code, and the path identifier includes:
calculating the root Key and the root chain code by using a CKD (Child Key Derivation function, or CKD function) algorithm to obtain a plurality of pairs of sub-chain codes and sub-keys;
repeating CKD calculation on the sub-secret keys and the sub-chain codes to obtain new multi-pair sub-secret keys and sub-chain codes;
and generating a key tree by using all the calculated key pairs, chain codes and path identifications.
According to a specific embodiment of the present invention, the obtaining the public key address of the secret key according to the path identifier includes:
carrying out Hash operation on the public key of the secret key to obtain a Hash value of the public key;
and visually encoding the hash value to obtain a visual ASCII code, namely the public key address of the secret key.
According to a specific embodiment of the present invention, the visually encoding the hash value includes:
and visually encoding the hash value by adopting a Base58 algorithm or a Base64 algorithm.
According to a specific embodiment of the present invention, the creating an address table according to the address and the path identifier of the corresponding public key includes:
acquiring the corresponding relation between each public key address and the path identifier;
and establishing the address table according to the corresponding relation.
According to a specific embodiment of the present invention, the calculating the service private key by using the root private key, the root chain code, and the path identifier includes:
and calculating the root private key, the root chain code and the path identifier by adopting a CKD algorithm to obtain a service private key.
The invention provides a block chain HD private key recovery method, which is characterized in that when a service private key is lost or damaged under the condition that a root private key is known, a path identifier corresponding to a public key address of the lost service private key is reversely inquired through a created address table, the service private key of any node can be calculated based on the root private key, a root chain code and the path identifier, and then the lost service private key is recovered, so that ownership and distribution rights and related operation functions of electronic files (including electronic judicial documents) and digital assets are ensured.
Detailed Description
The present invention is described in detail below with reference to specific embodiments in order to make the concept and idea of the present invention more clearly understood by those skilled in the art. It is to be understood that the embodiments presented herein are only a few of all embodiments that the present invention may have. Those skilled in the art who review this disclosure will readily appreciate that many modifications, variations, or alterations to the described embodiments, either in whole or in part, are possible and within the scope of the invention as claimed.
As used herein, the terms "first," "second," and the like are not intended to imply any order, quantity, or importance, but rather are used to distinguish one element from another. As used herein, the terms "a," "an," and the like are not intended to mean that there is only one of the described items, but rather that the description is directed to only one of the described items, which may have one or more. As used herein, the terms "comprises," "comprising," and other similar words are intended to refer to logical interrelationships, and are not to be construed as referring to spatial structural relationships. For example, "a includes B" is intended to mean that logically B belongs to a, and not that spatially B is located inside a. Furthermore, the terms "comprising," "including," and other similar words are to be construed as open-ended, rather than closed-ended. For example, "a includes B" is intended to mean that B belongs to a, but B does not necessarily constitute all of a, and a may also include C, D, E and other elements.
The terms "embodiment," "present embodiment," "an embodiment," "one embodiment," and "one embodiment" herein do not mean that the pertinent description applies to only one particular embodiment, but rather that the description may apply to yet another embodiment or embodiments. Those of skill in the art will understand that any of the descriptions given herein for one embodiment can be combined with, substituted for, or combined with the descriptions of one or more other embodiments to produce new embodiments, which are readily apparent to those of skill in the art and are intended to be within the scope of the present invention.
Example 1
Additional aspects and advantages of embodiments of the invention will be set forth in part in the description which follows and, in part, will be obvious from the description, or may be learned by practice of embodiments of the invention.
Fig. 1 is a flowchart of a method for retrieving a private key according to an embodiment of the present invention, as shown in fig. 1, the method includes the following steps:
s1: creating a root key and a root chain code from the random number via the root seed;
s2: generating a key tree according to the root key, the root chain code and the path identifier, wherein the key tree comprises a plurality of pairs of keys and chain codes;
s3: acquiring a public key address of the secret key according to the path identifier;
s4: creating an address table according to the address and the path identifier of the corresponding public key;
s5: searching a path identifier of a public key address corresponding to the lost service private key based on the address table;
s6: and calculating by using the root private key, the root chain code and the path identifier to obtain the service private key.
Specifically, fig. 2 is a flowchart of a method for creating a root key and a root chain code according to an embodiment of the present invention, and as shown in fig. 2, the creating a root key and a root chain code from a random number via a root seed in step S1 further includes:
s11: calculating the root seed by adopting any one of HMAC-SHA512, HMAC-SHA256 and HMAC-SHA128 algorithms to obtain the root private key and the root chain code;
s12: and calculating to obtain the root public key by adopting an asymmetric algorithm based on the root private key.
In this embodiment, under the condition that the root seed is known, firstly, the HMAC-SHA512 algorithm is adopted to perform hash operation on the root seed to generate a hash value, the first half of the hash value is a root private key, the second half of the hash value is a root chain code, then, based on the root private key, the root private key is operated by adopting an asymmetric encryption algorithm to obtain a root public key, and the root private key and the root public key form a root key, so that the root key and the root chain code are obtained. Wherein the asymmetric algorithms include, but are not limited to, RSA algorithm, ECC algorithm, ECDSA algorithm, SM2 algorithm, and SM9 algorithm.
Specifically, fig. 3 is a flowchart of a method for generating a key tree according to an embodiment of the present invention, and as shown in fig. 3, the step S2 of generating a key tree according to the root key, the root chain code, and the path identifier further includes:
s21: and calculating the root key and the root chain code by adopting a CKD algorithm to obtain a plurality of pairs of sub-pair keys and sub-chain codes.
S22: and repeating CKD calculation on the pairs of sub-pair keys and the sub-chain codes to obtain new pairs of sub-pair keys and sub-chain codes.
S23: and generating a key tree by using all the calculated key pairs, chain codes and path identifications.
For example, N pairs of sub-keys and sub-chain codes are generated by expanding a root key and a root chain code through a CKD algorithm, where N =2^ N, N is generally 32, and the algorithm is repeated by the sub-keys and the sub-chain codes to expand the sub-keys and the sub-chain codes of the next stage, and the repeating is performed for D times, so as to finally generate a key tree with a depth of D, each stage includes N pairs of sub-keys, the root of the tree is the root key, each pair of keys corresponds to a path identifier, in other words, a unique sub-key pair and a corresponding sub-chain code can be defined and calculated through the root key pair, the root chain code and the path identifier. In practice, the leaves of the key tree are leaf keys, end point keys or service keys, the branch points (including the tree root) of the key tree are branch point keys, fulcrum keys or management keys (which can also be used as service keys according to different application scenarios), the management private keys, the management chain codes and the path identifiers can calculate the service keys under the management nodes, and the root private keys, the root chain codes and the path identifiers can calculate any service keys and management keys in the whole tree (HD structure).
Specifically, fig. 4 is a flowchart of a method for obtaining a public key address according to an embodiment of the present invention, and as shown in fig. 4, the step S3 obtaining the public key address of the key according to the path identifier includes:
s31: carrying out Hash operation on the public key of the secret key to obtain a Hash value of the public key;
s32: and visually encoding the hash value to obtain a visual ASCII code, namely the public key address of the secret key. The hash value is visually encoded, for example, using the Base58 algorithm or the Base64 algorithm.
The public key address (also called node address, also called address or account number for short) is a visual ASCII code generated by hash operation of the public key to generate a hash value, which is used as an external representation form of the service public key to protect the privacy of the service public key. Although the service public key is disclosed to some extent, but is only disclosed to interested persons, but not to irrelevant persons, since the hash value is invisible binary, the hash value is generally subjected to visual coding operation, the embodiment of the invention adopts the Base58 or Base64 algorithm to perform visual coding, the visual coding operation is one-to-one reversible, that is, the binary input value can be converted into a visible and unique visual ASCII output value, and the input value can be restored by the output value.
Specifically, fig. 5 is a flowchart of a method for creating an address table according to an embodiment of the present invention, and as shown in fig. 5, the creating an address table according to the address and the path identifier of the corresponding public key in step S4 includes:
s41: acquiring the corresponding relation between each public key address and the path identifier;
s42: and establishing the address table according to the corresponding relation.
Specifically, step S5 finds the path id of the public key address corresponding to the lost service private key based on the address table,
since the path identifier is implicit to the user and the user sees the address, the user needs to look up the address table and reversely look up the corresponding path identifier from the corresponding relationship between the address recorded in the address table and the path identifier.
Specifically, in step S6, the service private key is obtained by calculation using the root private key, the root chain code, and the path identifier. The embodiment of the invention adopts HD algorithm to calculate the root private key, the root chain code and the path identifier to obtain the service private key.
In summary, the invention creates the address table to query the path identifier reversely, and then calculates the service private key from the root private key, the root chain code and the path identifier, thereby retrieving the lost or damaged service private key, and thus ensuring the security of the digital assets.
The concepts, principles and concepts of the invention have been described above in detail in connection with specific embodiments (including examples and illustrations). It will be appreciated by persons skilled in the art that embodiments of the invention are not limited to the specific forms disclosed above, and that many modifications, alterations and equivalents of the steps, methods, apparatus and components described in the above embodiments may be made by those skilled in the art after reading this specification, and that such modifications, alterations and equivalents are to be considered as falling within the scope of the invention. The scope of the invention is only limited by the claims.