Master key encryption method, master key decryption method, electronic device and storage medium

The creation of the database primary key timestamp intercepts the string and the generation of the primary keys for update values ​​for encryption processing, which solves the problem of insufficient security of the self-increment primary key in network transmission, and realizes efficient encryption and decryption of the primary keys, improving security.

CN114201774BActive Publication Date: 2024-11-22SHENZHEN PUDU TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111525522.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-14
Publication Date
2024-11-22
Estimated Expiration
2041-12-14

AI Technical Summary

Technical Problem

The primary key set by the self-increment method in the database is easily crawled during network transmission, resulting in insufficient security.

Method used

By obtaining the creation timestamp of the database primary key, intercepting a string of preset length, and generating the primary key update value based on the string and the primary key, encrypting the encryption value of the primary key to improve the security of the primary key.

Benefits of technology

Through secondary encryption processing, the plaintext of the primary key is discrete and disordered enough, improving the security of the primary key and preventing it from being cracked by crawlers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114201774B_ABST
    Figure CN114201774B_ABST
Patent Text Reader

Abstract

The present application discloses a master key encryption method, a master key decryption method, an electronic device, and a storage medium. When encrypting the master key in the database, the present application uses part of the characters in the creation timestamp as the encryption factor to obtain the master key update value. Due to the effect of the encryption factor, the characters in the master key update value are sufficiently discrete and irregular, so the security of the primary key can be guaranteed. After that, the master key update value and the encryption factor are encrypted separately, which is equivalent to a secondary guarantee of the security of the primary key. It can be seen that this scheme can make the encrypted plaintext sufficiently discrete and disordered. Even if the master key encryption value is decrypted to obtain the relevant plaintext, the primary key cannot be directly obtained based on the plaintext, so the security of the primary key can be improved. Correspondingly, the master key decryption method, electronic device, and storage medium provided by the present application also have the above-mentioned technical effects.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a master key encryption method, a master key decryption method, an electronic device and a storage medium. Background Art

[0002] At present, the primary keys of various databases in the database are generally set in an auto-incremental manner, such as: the primary keys in a certain database are: 1, 2, 3, 4, 5, 6... The primary key is the ID of each field in the database. In the database reading and writing scenario, the primary key inevitably needs to be transmitted over the network, and the primary key in the auto-incremental manner is easily crawled, so the security of the primary key needs to be improved.

[0003] Therefore, how to improve the security of the primary key is a problem that those skilled in the art need to solve. Summary of the invention

[0004] In view of this, the purpose of this application is to provide a master key encryption method, a master key decryption method, an electronic device and a storage medium to improve the security of the master key. The specific scheme is as follows:

[0005] In a first aspect, the present application provides a master key encryption method, comprising:

[0006] Obtain the primary key in the target database and the creation timestamp of the primary key;

[0007] Extracting a character string of a preset length from the creation timestamp, and generating a primary key update value based on the character string and the primary key;

[0008] Encrypting the primary key update value and the string respectively to obtain a primary key ciphertext and a string ciphertext;

[0009] The primary key ciphertext and the string ciphertext are concatenated to obtain the encrypted value of the primary key.

[0010] Optionally, the extracting a character string of a preset length from the creation timestamp includes:

[0011] Determine whether the last N bits of the creation timestamp are all 0; N is not greater than the total length of the creation timestamp;

[0012] If the last N digits of the creation timestamp are not all 0, the last N digits of the creation timestamp are intercepted as the character string;

[0013] If the last N bits of the creation timestamp are all 0, the first N bits of the creation timestamp are intercepted as the character string.

[0014] Optionally, generating a primary key update value based on the string and the primary key includes:

[0015] The product of the string and the primary key is used as the primary key update value.

[0016] Optionally, the encrypting the primary key update value and the string respectively to obtain a primary key ciphertext and a string ciphertext includes:

[0017] The primary key update value and the string are respectively used as encryption objects, and the encryption objects are encrypted using the EncodeDec function to obtain the primary key ciphertext and the string ciphertext.

[0018] Optionally, encrypting the encrypted object using an EncodeDec function includes:

[0019] Convert the encrypted object into a hexadecimal number, and intercept the first M characters or the last M characters of the hexadecimal number to obtain intercepted characters; M is not greater than the total length of the hexadecimal number;

[0020] Convert each character in the intercepted characters into a binary number to obtain M binary numbers;

[0021] Concatenate the M binary numbers, and divide the concatenated binary numbers into a target number of binary numbers;

[0022] Convert the target number of binary numbers into decimal numbers respectively to obtain the target number of decimal numbers;

[0023] Taking each decimal number as a position mark, determining the target character corresponding to each position mark in the key character, and recording the target characters in sequence; the key character is intercepted from the randomly generated key according to the preset offset value;

[0024] Delete the truncated characters from the hexadecimal number, and when the length of the hexadecimal number after deletion is greater than 0, use the hexadecimal number after deletion as a new hexadecimal number, and repeat the step of truncating the first M characters or the last M characters of the hexadecimal number to obtain the truncated characters, until the length of the hexadecimal number after deletion is not greater than 0, and use all the recorded target characters as the ciphertext of the encryption object.

[0025] Optionally, it also includes:

[0026] If the target database and the object database are merged, each primary key in the target database and the object database is used as an update object, and different prefixes are added to the update objects belonging to different databases, or different suffixes are added to the update objects belonging to different databases.

[0027] Optionally, it also includes:

[0028] If the target database and the object database are merged and the merged database needs to be transmitted over the network, different prefixes are added to the encrypted values ​​of the update objects belonging to different libraries, or different suffixes are added to the encrypted values ​​of the update objects belonging to different libraries.

[0029] In a second aspect, the present application provides a master key decryption method, comprising:

[0030] Obtaining an encrypted value of a primary key, and splitting the encrypted value to obtain a primary key ciphertext and a string ciphertext;

[0031] Decrypting the primary key ciphertext and the string ciphertext respectively to obtain a primary key update value and a string;

[0032] The primary key is determined based on the primary key update value and the string.

[0033] Optionally, the decrypting the primary key ciphertext and the string ciphertext respectively to obtain the primary key update value and the string includes:

[0034] The primary key ciphertext and the string ciphertext are respectively used as decryption objects, and the decryption objects are decrypted using the DecodeString function to obtain the primary key update value and the string.

[0035] Optionally, decrypting the decryption object by using a DecodeString function includes:

[0036] intercepting the last target number of target characters or the first target number of target characters of the decryption object;

[0037] Determine the position mark of each target character in the key character to obtain a target number of position marks; the key character is intercepted from the randomly generated key according to a preset offset value;

[0038] Convert the target number of position marks into binary numbers respectively to obtain the target number of binary numbers;

[0039] Splicing the target number of binary numbers, and dividing the spliced ​​binary numbers into M binary numbers;

[0040] Convert the M binary numbers into hexadecimal numbers respectively to obtain M hexadecimal characters;

[0041] Delete the target characters from the decrypted object. When the length of the decrypted object after deletion is greater than 0, use the decrypted object after deletion as a new decrypted object, and repeat the step of intercepting the rear target number of target characters or the front target number of target characters of the decrypted object until the length of the decrypted object after deletion is not greater than 0, and use all the obtained hexadecimal characters as the plaintext of the decrypted object.

[0042] Optionally, determining the primary key based on the primary key update value and the string includes:

[0043] The ratio of the primary key update value to the character string is used as the primary key.

[0044] In a third aspect, the present application provides an electronic device, including:

[0045] Memory for storing computer programs;

[0046] The processor is used to call and execute the computer program to implement the method disclosed above.

[0047] In a fourth aspect, the present application provides a readable storage medium for storing a computer program, wherein the computer program implements the aforementioned disclosed method when called and executed by a processor.

[0048] From the above scheme, it can be seen that the present application provides a primary key encryption method, including: obtaining the primary key in the target database and the creation timestamp of the primary key; intercepting a character string of a preset length from the creation timestamp, and generating a primary key update value based on the character string and the primary key; encrypting the primary key update value and the character string respectively to obtain a primary key ciphertext and a character string ciphertext; concatenating the primary key ciphertext and the character string ciphertext to obtain the encrypted value of the primary key.

[0049] It can be seen that when encrypting the primary key in the database, the present application uses part of the characters in its creation timestamp as the encryption factor (i.e., a character string of preset length) to obtain the primary key update value. Due to the effect of the encryption factor, the characters in the primary key update value are sufficiently discrete and irregular, so the security of the primary key can be guaranteed. After that, the primary key update value and the encryption factor are encrypted separately, which is equivalent to a secondary guarantee of the primary key security. It can be seen that this scheme can make the encrypted plaintext sufficiently discrete and disordered. Even if the primary key encrypted value is decrypted to obtain the related plaintext, the primary key cannot be directly obtained based on the plaintext, so the security of the primary key can be improved.

[0050] Correspondingly, the master key decryption method, electronic device and storage medium provided by the present application also have the above-mentioned technical effects. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.

[0052] Figure 1 A flow chart of a master key encryption method disclosed in this application;

[0053] Figure 2 This is a flow chart of another master key encryption method disclosed in this application;

[0054] Figure 3 for Figure 2 The corresponding specific encryption flow chart;

[0055] Figure 4 A flow chart of a master key decryption method disclosed in this application;

[0056] Figure 5 This is a flow chart of another master key decryption method disclosed in this application;

[0057] Figure 6 for Figure 5 The corresponding specific decryption flow chart;

[0058] Figure 7 A schematic diagram of a master key encryption device disclosed in this application;

[0059] Figure 8 A schematic diagram of a master key decryption device disclosed in this application;

[0060] Fig. 9 This is a schematic diagram of an electronic device disclosed in this application. DETAILED DESCRIPTION

[0061] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0062] At present, the primary keys of each database in the database are generally set in a self-incrementing manner, such as: the primary keys in a certain database are: 1, 2, 3, 4, 5, 6... The primary key is the ID of each field in the database. In the database reading and writing scenario, the primary key inevitably needs to be transmitted over the network, and the self-incrementing primary key is easily crawled, so the security of the primary key needs to be improved. To this end, the present application provides a primary key encryption scheme that can improve the security of the primary key.

[0063] The following is an introduction to a master key encryption method provided in an embodiment of the present application. Figure 1 As shown, the embodiment of the present application discloses a master key encryption method, including:

[0064] S101. Obtain a primary key in a target database and a creation timestamp of the primary key.

[0065] In this embodiment, the target database can be any type of database, such as a MySQL database. The primary key in the target database is generated in an auto-incremental manner, and its creation timestamp is recorded in year, month, day, hour, minute, and second, such as: December 11, 2021 23:56:38 is recorded as: 20211211235638.

[0066] The primary key in the target database is the ID of each field in the database.

[0067] S102: extract a character string of a preset length from the creation timestamp, and generate a primary key update value based on the character string and the primary key.

[0068] The preset length must not be greater than the total length of the creation timestamp. For example, when the creation timestamp is 20211211235638, the preset length must not be greater than 14. Generally, the preset length is 5.

[0069] In a specific implementation, extracting a character string of a preset length from a creation timestamp includes: determining whether the last N digits of the creation timestamp are all 0; N is not greater than the total length of the creation timestamp; if the last N digits of the creation timestamp are not all 0, extracting the last N digits of the creation timestamp as a character string; if the last N digits of the creation timestamp are all 0, extracting the first N digits of the creation timestamp as a character string, so that the character strings determined for different primary keys can be as different as possible. N is the preset length.

[0070] In a specific implementation, generating a primary key update value based on a string and a primary key includes: taking the product of the string and the primary key as the primary key update value. Of course, the string and the primary key may also be subjected to other operations to obtain the primary key update value, such as: concatenating the string and the primary key, performing a logical operation (such as an exclusive OR operation) on the string and the primary key, etc.

[0071] S103. Encrypt the primary key update value and the character string respectively to obtain the primary key ciphertext and the character string ciphertext.

[0072] In a specific implementation, the primary key update value and the string are encrypted respectively to obtain the primary key ciphertext and the string ciphertext, including: taking the primary key update value and the string as encryption objects respectively, and encrypting the encryption objects using the EncodeDec function to obtain the primary key ciphertext and the string ciphertext.

[0073] In a specific implementation, the encryption object is encrypted using the EncodeDec function, including: converting the encryption object into a hexadecimal number, and intercepting the first M characters or the last M characters of the hexadecimal number to obtain intercepted characters; M is not greater than the total length of the hexadecimal number; converting each character in the intercepted characters into a binary number to obtain M binary numbers; splicing the M binary numbers, and cutting the spliced ​​binary numbers into a target number of binary numbers; converting the target number of binary numbers into decimal numbers to obtain a target number of decimal numbers; using each decimal number as a position mark, determining the target character corresponding to each position mark in the key character, and recording the target characters in sequence; the key character (i.e. Figure 3 The key in the hexadecimal number is obtained by intercepting the character from the randomly generated key according to the preset offset value; deleting the intercepted character from the hexadecimal number, and when the length of the hexadecimal number after the deletion is greater than 0, using the hexadecimal number after the deletion as the new hexadecimal number, and repeatedly executing the step of intercepting the first M characters or the last M characters of the hexadecimal number to obtain the intercepted character, until the length of the hexadecimal number after the deletion is not greater than 0, using all the recorded target characters as the ciphertext of the encryption object.

[0074] In one implementation, M takes a value of 3 and the target number takes a value of 2.

[0075] S104: Concatenate the primary key ciphertext and the string ciphertext to obtain the encrypted value of the primary key.

[0076] Specifically, when concatenating the master key ciphertext and the string ciphertext, you can concatenate them directly or use symbols. For example, if A represents the master key ciphertext and B represents the string ciphertext, the encrypted value of the master key can be AB, A+B, AB, A_B, etc.

[0077] According to the scheme provided in this embodiment, any primary key in any database can be encrypted. When encrypting the primary key in the database, some characters in its creation timestamp are used as encryption factors (i.e., a character string of preset length) to obtain the primary key update value. Due to the effect of the encryption factor, the characters in the primary key update value are sufficiently discrete and irregular, so the security of the primary key can be guaranteed. After that, the primary key update value and the encryption factor are encrypted separately, which is equivalent to twice guaranteeing the security of the primary key.

[0078] It can be seen that this embodiment can make the encrypted plaintext sufficiently discrete and disordered. Even if the primary key encryption value is decrypted to obtain the related plaintext, the primary key cannot be directly obtained based on the plaintext, thereby improving the security of the primary key.

[0079] Based on the above embodiment, it should be noted that if different databases generate primary keys in an auto-incremental manner, primary key conflicts will occur when these databases are merged. For example, if the primary keys in database A are 1, 2, 3, 4, and the primary keys in database B are 1, 2, 3, 4, 5, then after database A and database B are merged, the merged database will have two 1s, two 2s, two 3s, and two 4s, causing a primary key conflict.

[0080] To this end, in a specific implementation, it also includes: if the target database and the object database are merged, each primary key in the target database and the object database is used as an update object, and different prefixes are added to the update objects belonging to different libraries, or different suffixes are added to the update objects belonging to different libraries.

[0081] Still taking the above example, assuming that the prefix of each primary key in database A is A, and the prefix of each primary key in database B is B, then the merged database will have: A-1, A-2, A-3, A-4, B-1, B-2, B-3, B-4, B-5. In this way, the same primary keys in different databases can be distinguished.

[0082] In a specific implementation, if the target database and the object database are merged, and the merged database needs to be transmitted over the network, different prefixes are added to the encrypted values ​​of the updated objects belonging to different libraries, or different suffixes are added to the encrypted values ​​of the updated objects belonging to different libraries, so that each primary key is transmitted in the network in ciphertext form to ensure its security.

[0083] The following is an introduction to another embodiment of the master key encryption method provided by the embodiment of the present application. Figure 2 , another embodiment of the master key encryption method includes:

[0084] Step 1: Enter the prefix prefix, an id in the database (that is, a primary key in the database), and its creation time createTime.

[0085] Step 2: Convert the creation time createTime into a timestamp, and extract the last 5 digits from the timestamp as the time factor timeFactor (i.e., encryption factor). If the last five digits are all 0, extract the first five digits of the timestamp.

[0086] Step 3: Encode the product of id and time factor timeFactor using EncodeDec function to obtain the encrypted value idCode. Encrypting the product of id and time factor timeFactor can make the plain text characters before encryption sufficiently dispersed and not easily traversed by crawlers.

[0087] Step 4: Use the EncodeDec function to encrypt the time factor timeFactor and obtain the encrypted value timeCode.

[0088] Step 5: Concatenate the prefix prefix, the encrypted value idCode, and the encrypted value timeCode with “_” to get the encrypted value idStr of the id in the database.

[0089] It can be seen that idStr consists of three parts: prefix, idCode, and timeCode, and different parts are connected by underscores “_”.

[0090] The specific encryption process in step 3 and step 4 is exactly the same. For details, please refer to Figure 3 .

[0091] exist Figure 3 In the encryption, the encrypted value dec is the product of id and time factor timeFactor, or the time factor timeFactor itself. That is, the product of id and time factor timeFactor and time factor timeFactor are used as encryption objects to execute Figure 3 The encryption process shown in FIG. 1 is a flow chart showing the encryption process. The encrypted value string str finally obtained is the ciphertext of the encrypted object. The specific encryption steps can be referred to the relevant introduction of the above embodiment, which will not be repeated here.

[0092] In this embodiment, prefix is ​​a prefix string parameter, which is of string type. Different databases have different prefixes to distinguish different libraries and avoid primary key conflicts when merging libraries. id is the auto-increment ID in any database, which is of int64 type. The time factor timeFactor consists of 5 digits. The key is of string type, which is composed of 64 different characters randomly, and may contain uppercase and lowercase letters, numbers, underscores and other characters. It is a global constant. The offset offset is of digital type, which is used to offset the key to make the encrypted data more diverse and less regular. The offset value is between 0 and 64. When the offset exceeds this range, the offset is 0, that is, the key is not offset. The specific value can be defined by yourself.

[0093] It can be seen that this embodiment encrypts the ID based on the EncodeDec function, which can ensure the security of the database ID. The EncodeDec function can convert the decimal number into Figure 3The encryption process of this solution is convenient and flexible. It can merge databases and solve primary key conflicts without modifying the source data. The encryption method can convert the auto-increment ID into an irregular string for transmission, which increases the difficulty of being crawled. The encryption method also introduces a key and creation time, which can increase the difficulty of being cracked and has higher security.

[0094] The following is an introduction to a master key decryption method provided in an embodiment of the present application. Figure 4 , a master key decryption method includes:

[0095] S401. Obtain the encrypted value of the primary key, and split the encrypted value to obtain the primary key ciphertext and the string ciphertext.

[0096] The encrypted value is encrypted according to the method described in any of the above embodiments. If the encrypted value of the primary key is AB, A+B, AB or A_B, then A can be determined as the primary key ciphertext and B as the string ciphertext.

[0097] S402: Decrypt the primary key ciphertext and the character string ciphertext respectively to obtain the primary key update value and the character string.

[0098] The decryption process is the reverse of the encryption process, so the decryption steps in this embodiment can be understood by referring to the encryption steps introduced in the previous embodiment.

[0099] In a specific implementation, the primary key ciphertext and the string ciphertext are decrypted respectively to obtain the primary key update value and the string, including: taking the primary key ciphertext and the string ciphertext as decryption objects respectively, and using the DecodeString function to decrypt the decryption objects to obtain the primary key update value and the string.

[0100] In a specific implementation, the DecodeString function is used to decrypt the decryption object, including: intercepting the target number of target characters or the target number of target characters of the decryption object; determining the position mark of each target character in the key character to obtain the target number of position marks; the key character is intercepted from the randomly generated key according to the preset offset value; converting the target number of position marks into binary numbers respectively to obtain the target number of binary numbers; splicing the target number of binary numbers, and dividing the spliced ​​binary numbers into M binary numbers; converting the M binary numbers into hexadecimal numbers respectively to obtain M hexadecimal characters; deleting the target character from the decryption object, and when the length of the decryption object after deletion is greater than 0, using the decryption object after deletion as a new decryption object, and repeatedly executing the step of intercepting the target number of target characters or the target number of target characters of the decryption object until the length of the decryption object after deletion is not greater than 0, using all the obtained hexadecimal characters as the plaintext of the decryption object.

[0101] S403: Determine the primary key based on the primary key update value and the character string.

[0102] S403 in this embodiment is the reverse process of "generating a primary key update value based on a string and a primary key" in the aforementioned embodiment. Therefore, when the product of a string and a primary key is used as the primary key update value, in a specific implementation, the primary key is determined based on the primary key update value and the string, including: using the ratio of the primary key update value to the string as the primary key.

[0103] According to the solution provided in this embodiment, the encrypted value of any primary key in any database can be decrypted to obtain the primary key plaintext.

[0104] The following is an introduction to another embodiment of the master key decryption method provided by the embodiment of the present application. Figure 5 , a master key decryption method of another embodiment includes:

[0105] Step 1: Enter the prefix prefix, encrypted string idStr, and offset offset.

[0106] Step 2: Split the encrypted string idStr into three parts: prefix prefix, time factor encrypted value timeCode, and id encrypted value idCode.

[0107] Step 3: Use the DecodeString function to decrypt the encrypted value timeCode into the time factor timeFactor.

[0108] Step 4: Use the DecodeString function to decrypt the encrypted value idCode into the product of id and timeFactor.

[0109] Step 5: Multiply the product of id and timeFactor by the time factor to obtain the final auto-increment id.

[0110] The specific decryption process in step 3 and step 4 is exactly the same. For details, please refer to Figure 6 .

[0111] exist Figure 6 In the example, the encrypted value string str is the encrypted value timeCode or the encrypted value idCode. That is, the encrypted value timeCode and the encrypted value idCode are used as decryption objects to execute Figure 6 The encryption process shown in the figure, the decimal dec finally obtained is the time factor timeFactor or the product. The specific decryption steps can refer to the relevant introduction of the above embodiment, which will not be repeated here.

[0112] It can be seen that this embodiment is flexible and convenient to decrypt the id based on the DecodeString function. The DecodeString function can decrypt the ciphertext string into a corresponding decimal number.

[0113] The following is an introduction to a master key encryption device according to an embodiment of the present application. The master key encryption device according to an embodiment described below and the master key encryption method according to an embodiment described above can be referenced to each other.

[0114] See also Figure 7 As shown, the embodiment of the present application discloses a master key encryption device, including:

[0115] The acquisition module 701 is used to acquire the primary key in the target database and the creation timestamp of the primary key;

[0116] A generating module 702, configured to extract a character string of a preset length from the creation timestamp, and generate a primary key update value based on the character string and the primary key;

[0117] The encryption module 703 is used to encrypt the primary key update value and the string respectively to obtain the primary key ciphertext and the string ciphertext;

[0118] The concatenation module 704 is used to concatenate the primary key ciphertext and the string ciphertext to obtain the encrypted value of the primary key.

[0119] In a specific implementation, the generation module is specifically used to:

[0120] Determine whether the last N bits of the creation timestamp are all 0; N is not greater than the total length of the creation timestamp;

[0121] If the last N digits of the creation timestamp are not all 0, the last N digits of the creation timestamp are truncated as a string;

[0122] If the last N digits of the creation timestamp are all 0, the first N digits of the creation timestamp are truncated as a string.

[0123] In a specific implementation, the generation module is specifically used to:

[0124] Updates the value with the product of the string and the primary key as the primary key.

[0125] In a specific implementation, the encryption module includes:

[0126] The encryption unit is used to take the primary key update value and the string as encryption objects respectively, and use the EncodeDec function to encrypt the encryption objects to obtain the primary key ciphertext and the string ciphertext.

[0127] In a specific implementation, the encryption unit is specifically used for:

[0128] Convert the encrypted object into a hexadecimal number, and intercept the first M characters or the last M characters of the hexadecimal number to obtain intercepted characters; M is not greater than the total length of the hexadecimal number;

[0129] Convert each character in the intercepted characters into a binary number to obtain M binary numbers;

[0130] Concatenate M binary numbers, and divide the concatenated binary numbers into a target number of binary numbers;

[0131] Convert the target number of binary numbers into decimal numbers respectively to obtain the target number of decimal numbers;

[0132] Using each decimal number as a position marker, determining the target character corresponding to each position marker in the key character, and recording the target characters in sequence; the key character is intercepted from the randomly generated key according to the preset offset value;

[0133] Delete the intercepted characters from the hexadecimal number. When the length of the deleted hexadecimal number is greater than 0, use the deleted hexadecimal number as a new hexadecimal number, and repeat the steps of intercepting the first M characters or the last M characters of the hexadecimal number to obtain the intercepted characters until the length of the deleted hexadecimal number is not greater than 0, and use all the recorded target characters as the ciphertext of the encryption object.

[0134] In a specific embodiment, it also includes:

[0135] The merging module is used to take each primary key in the target database and the object database as an update object when merging the target database and the object database, and to add different prefixes or suffixes to the update objects belonging to different databases.

[0136] In a specific embodiment, it also includes:

[0137] The transmission module is used to add different prefixes to the encrypted values ​​of the updated objects belonging to different libraries, or to add different suffixes to the encrypted values ​​of the updated objects belonging to different libraries if the target database and the object database are merged and the merged database needs to be transmitted over the network.

[0138] Among them, for more specific working processes of each module and unit in this embodiment, reference can be made to the corresponding contents disclosed in the aforementioned embodiments, which will not be repeated here.

[0139] It can be seen that this embodiment provides a master key encryption device, which can make the encrypted plaintext sufficiently discrete and disordered. Even if the master key encryption value is decrypted to obtain the related plaintext, the master key cannot be directly obtained based on the plaintext, thereby improving the security of the master key.

[0140] A master key decryption device provided in an embodiment of the present application is introduced below. The master key decryption device described below and the master key decryption method described above can be referenced to each other.

[0141] See also Figure 8 As shown, the embodiment of the present application discloses a master key decryption device, including:

[0142] The splitting module 801 is used to obtain the encrypted value of the primary key, and split the encrypted value to obtain the primary key ciphertext and the string ciphertext;

[0143] The decryption module 802 is used to decrypt the primary key ciphertext and the string ciphertext respectively to obtain the primary key update value and the string;

[0144] The determination module 803 is used to determine the primary key based on the primary key update value and the character string.

[0145] In a specific implementation, the decryption module includes:

[0146] The decryption unit is used to take the primary key ciphertext and the string ciphertext as decryption objects respectively, and use the DecodeString function to decrypt the decryption objects to obtain the primary key update value and the string.

[0147] In a specific implementation, the decryption unit is specifically used for:

[0148] Intercept the last target number of target characters or the first target number of target characters of the decryption object;

[0149] Determine the position mark of each target character in the key character to obtain a target number of position marks; the key character is intercepted from the randomly generated key according to a preset offset value;

[0150] Convert the target number of position marks into binary numbers respectively to obtain the target number of binary numbers;

[0151] Concatenate a target number of binary numbers, and divide the concatenated binary numbers into M binary numbers;

[0152] Convert M binary numbers into hexadecimal numbers respectively to obtain M hexadecimal characters;

[0153] Delete the target characters from the decrypted object. When the length of the decrypted object after deletion is greater than 0, use the decrypted object after deletion as a new decrypted object, and repeat the step of intercepting the last target number of target characters or the first target number of target characters of the decrypted object until the length of the decrypted object after deletion is not greater than 0, and use all the obtained hexadecimal characters as the plaintext of the decrypted object.

[0154] In a specific implementation, the determination module is specifically used to:

[0155] The ratio of the primary key update value to the string is used as the primary key.

[0156] Among them, for more specific working processes of each module and unit in this embodiment, reference can be made to the corresponding contents disclosed in the aforementioned embodiments, which will not be repeated here.

[0157] It can be seen that this embodiment provides a primary key decryption device, which can decrypt the encrypted value of any primary key in any database to obtain the primary key plaintext.

[0158] An electronic device provided in an embodiment of the present application is introduced below. The electronic device described below and the master key encryption method and device, and the master key decryption method and device described above can refer to each other.

[0159] See also Fig. 9 As shown, the embodiment of the present application discloses an electronic device, including:

[0160] Memory 901, used for storing computer programs;

[0161] The processor 902 is used to call and execute the computer program to implement the method disclosed in any of the above embodiments.

[0162] A readable storage medium provided in an embodiment of the present application is introduced below. The readable storage medium described below and the master key encryption method, device and equipment, and the master key decryption method, device and equipment described above can refer to each other.

[0163] A readable storage medium for storing a computer program, wherein the computer program, when called and executed by a processor, implements the master key encryption or master key decryption method disclosed in the aforementioned embodiment. The specific steps of the method can refer to the corresponding contents disclosed in the aforementioned embodiment, and will not be repeated here.

[0164] The "first", "second", "third", "fourth", etc. (if any) referred to in this application are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods or devices.

[0165] It should be noted that the descriptions involving "first", "second", etc. in this application are only for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in this field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by this application.

[0166] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0167] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of readable storage medium known in the art.

[0168] Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for those skilled in the art, according to the idea of ​​the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A master key encryption method, characterized in that: include: Obtain the primary key in the target database and the creation timestamp of the primary key; Extracting a character string of a preset length from the creation timestamp, and generating a primary key update value based on the character string and the primary key; Encrypting the primary key update value and the string respectively to obtain a primary key ciphertext and a string ciphertext; Concatenate the primary key ciphertext and the string ciphertext to obtain the encrypted value of the primary key; The step of encrypting the primary key update value and the string to obtain the primary key ciphertext and the string ciphertext comprises: The primary key update value and the string are respectively used as encryption objects, and the encryption objects are encrypting by using the EncodeDec function to obtain the primary key ciphertext and the string ciphertext; The step of encrypting the encrypted object by using the EncodeDec function includes: Convert the encrypted object into a hexadecimal number, and intercept the first M characters or the last M characters of the hexadecimal number to obtain intercepted characters; M is not greater than the total length of the hexadecimal number; Convert each character in the intercepted characters into a binary number to obtain M binary numbers; Concatenate the M binary numbers, and divide the concatenated binary numbers into a target number of binary numbers; Convert the target number of binary numbers into decimal numbers respectively to obtain the target number of decimal numbers; Taking each decimal number as a position mark, determining the target character corresponding to each position mark in the key character, and recording the target characters in sequence; the key character is intercepted from the randomly generated key according to the preset offset value; Delete the truncated characters from the hexadecimal number, and when the length of the hexadecimal number after deletion is greater than 0, use the hexadecimal number after deletion as a new hexadecimal number, and repeat the step of truncating the first M characters or the last M characters of the hexadecimal number to obtain the truncated characters, until the length of the hexadecimal number after deletion is not greater than 0, and use all the recorded target characters as the ciphertext of the encryption object.

2. The method according to claim 1, characterized in that The step of extracting a character string of a preset length from the creation timestamp includes: Determine whether the last N bits of the creation timestamp are all 0; N is not greater than the total length of the creation timestamp; If the last N digits of the creation timestamp are not all 0, the last N digits of the creation timestamp are intercepted as the character string; If the last N bits of the creation timestamp are all 0, the first N bits of the creation timestamp are intercepted as the character string.

3. The method according to claim 1, characterized in that The generating a primary key update value based on the character string and the primary key comprises: The product of the string and the primary key is used as the primary key update value.

4. The method according to any one of claims 1 to 3, characterized in that: Also includes: If the target database and the object database are merged, each primary key in the target database and the object database is used as an update object, and different prefixes are added to the update objects belonging to different databases, or different suffixes are added to the update objects belonging to different databases.

5. The method according to any one of claims 1 to 3, characterized in that: Also includes: If the target database and the object database are merged and the merged database needs to be transmitted over the network, different prefixes are added to the encrypted values ​​of the update objects belonging to different databases, or different suffixes are added to the encrypted values ​​of the update objects belonging to different databases.

6. A master key decryption method, characterized in that: include: Obtaining an encrypted value of a primary key, and splitting the encrypted value to obtain a primary key ciphertext and a string ciphertext; Decrypting the master key ciphertext and the string ciphertext respectively to obtain a master key update value and a string; the string is a string of a preset length intercepted from the creation timestamp of the master key; determining the primary key based on the primary key update value and the string; The decrypting of the primary key ciphertext and the string ciphertext to obtain the primary key update value and the string respectively includes: The primary key ciphertext and the string ciphertext are respectively used as decryption objects, and the decryption objects are decrypted using the DecodeString function to obtain the primary key update value and the string; The decryption object is decrypted by using the DecodeString function, including: intercepting the last target number of target characters or the first target number of target characters of the decryption object; Determine the position mark of each target character in the key character to obtain a target number of position marks; the key character is intercepted from the randomly generated key according to a preset offset value; Convert the target number of position marks into binary numbers respectively to obtain the target number of binary numbers; Splicing the target number of binary numbers, and dividing the spliced ​​binary numbers into M binary numbers; Convert the M binary numbers into hexadecimal numbers respectively to obtain M hexadecimal characters; Delete the target characters from the decrypted object. When the length of the decrypted object after deletion is greater than 0, use the decrypted object after deletion as a new decrypted object, and repeat the step of intercepting the rear target number of target characters or the front target number of target characters of the decrypted object until the length of the decrypted object after deletion is not greater than 0, and use all the obtained hexadecimal characters as the plaintext of the decrypted object.

7. The method according to claim 6, characterized in that The determining the primary key based on the primary key update value and the character string comprises: The ratio of the primary key update value to the character string is used as the primary key.

8. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to call and execute the computer program to implement the method according to any one of claims 1 to 7.

9. A readable storage medium, characterized in that: Used to store a computer program, wherein the computer program implements the method according to any one of claims 1 to 7 when called and executed by a processor.