WO2019085350A1 - Method and device for generating identifier, computer device, and storage medium - Google Patents

Method and device for generating identifier, computer device, and storage medium Download PDF

Info

Publication number
WO2019085350A1
WO2019085350A1 PCT/CN2018/077283 CN2018077283W WO2019085350A1 WO 2019085350 A1 WO2019085350 A1 WO 2019085350A1 CN 2018077283 W CN2018077283 W CN 2018077283W WO 2019085350 A1 WO2019085350 A1 WO 2019085350A1
Authority
WO
WIPO (PCT)
Prior art keywords
uuid
value
last
identification code
bit
Prior art date
Application number
PCT/CN2018/077283
Other languages
French (fr)
Chinese (zh)
Inventor
周泓宇
Original Assignee
平安科技(深圳)有限公司
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 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2019085350A1 publication Critical patent/WO2019085350A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/08Error detection or correction by redundancy in data representation, e.g. by using checking codes
    • G06F11/10Adding special bits or symbols to the coded information, e.g. parity check, casting out 9's or 11's

Definitions

  • the present application relates to the field of computer technology, and in particular, to a method and device for generating an identification code, a computer device, and a storage medium.
  • UUID refers to the Universally Unique Identifier.
  • the purpose of UUID is to make all elements in a distributed system uniquely identified without the need to identify the identification through the central console. In this way, each element in the distributed system can establish a UUID that does not conflict with other elements. In such a case, there is no need to consider the name duplication problem when the database is created.
  • UUID is a number generated on a machine that is guaranteed to be unique to all machines in the same time and space.
  • the platform provides an API (Application Programming Interface) that generates UUIDs. According to the standards developed by the Open Software Foundation (OSF), Ethernet card addresses, nanosecond time, chip ID codes, and many possible numbers are used.
  • OSF Open Software Foundation
  • the above UUID generation algorithm randomly generates a 32-bit hexadecimal number, but the rules are uniform and can be generated by anyone, and it is difficult to verify the identification code.
  • a method and apparatus for generating an identification code, a computer device, and a storage medium are provided.
  • a method for generating an identification code comprising: generating an UUID if an instruction to generate an identification code UUID is received; pre-specifying a value according to the UUID, according to a preset acquisition manner, in the UUID Obtaining an insertion position between the first position and the last position; and inserting a preset content for verifying the UUID at the insertion position to generate a new identification code, and the preset content is generated according to the first preset rule.
  • An apparatus for generating an identification code comprising: a generating module, configured to generate the UUID if an instruction to generate an identification code UUID is received; and an acquiring module, configured to pre-specify a value according to the UUID according to the UUID a preset acquisition mode, obtaining an insertion position between a first bit and a last bit of the UUID; and a generating module, configured to insert a preset content for verifying the UUID at the insertion position, and generate a new identification code, where the The content is generated according to the first preset rule.
  • a computer device comprising a memory and one or more processors, the memory storing computer readable instructions, the computer readable instructions being executed by the processor, causing the one or more processors to execute The following steps: if the instruction for generating the identifier UUID is received, the UUID is generated; the value at the location is pre-specified according to the UUID, and the insertion position is obtained between the first and last digits of the UUID according to a preset acquisition manner; And inserting a preset content for verifying the UUID at the insertion position, generating a new identification code, and the preset content is generated according to the first preset rule.
  • One or more non-transitory readable storage mediums storing computer readable instructions, when executed by one or more processors, cause the one or more processors to perform the following steps: Receiving an instruction to generate an identifier UUID, generating the UUID; pre-specifying a value according to the UUID, acquiring an insertion position between a first bit and a last bit of the UUID according to a preset acquisition manner; The insertion position is inserted to verify the preset content of the UUID, and a new identification code is generated, and the preset content is generated according to the first preset rule.
  • 1 is an application environment diagram of a method for generating an identification code in an embodiment
  • FIG. 2 is a flow chart of a method for generating an identification code in an embodiment
  • FIG. 3 is a structural diagram of an apparatus for generating an identification code in an embodiment
  • FIG. 4 is a diagram showing the internal structure of a computer device in an embodiment.
  • first may be used to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish the first element from another element.
  • first preset rule may be referred to as a second preset rule without departing from the scope of the present application, and similarly, the second preset rule may be referred to as a first preset rule. Both the first preset rule and the second preset rule are preset rules, but they are not the same preset rule.
  • FIG. 1 is an application environment diagram of a method for generating an identifier in an embodiment, where the application environment includes: a terminal 120, a connection network 140, and a server 160.
  • the terminal 120 includes an electronic device such as a mobile terminal, a tablet computer, a smart wearable device, a desktop computer, or a notebook.
  • the connection network 140 is a wired or wireless network, and the wireless connection method includes a mobile communication network or a connection method such as WIFI (WIreless-Fidelity).
  • the server 160 is a local server or a cloud server.
  • each component in the application environment is: the terminal 120 sends a request to the server 160 through the connection network 140, for example, the terminal 120 sends an account login request by scanning the two-dimensional code to the server 160 through the connection network 140, and the server 160 receives the terminal 120.
  • the server 160 invokes a module for generating the universal unique identifier UUID on the server 160.
  • the module After receiving the instruction to generate the identifier UUID, the module generates a UUID, and the server 160 pre-specifies the value according to the UUID, according to the pre-predetermined value.
  • the acquisition mode is set to obtain an insertion position between the first and last positions of the UUID, and the preset content of the verification UUID generated according to the first preset rule is inserted at the insertion position to generate a new identification code, and the server 160 will be universally unique and new.
  • the identification code is sent to the terminal 120 in the form of a two-dimensional code.
  • the terminal 120 performs account verification by using the new identification code, and logs in to the server 160.
  • the server 160 passes the new one.
  • the verification code contained in the identification code verifies the two-dimensional code, thereby implementing verification of the login account. .
  • FIG. 2 is a flowchart of an embodiment of a method for generating an identifier provided by the present application, where the method includes:
  • Step 200 If an instruction to generate the identification code UUID is received, a UUID is generated.
  • UUIDs are Microsoft's Globally Unique Identifiers (GUIDs), while other applications include Linux ext2/ext3 file systems, LUKS encryption partitions, GNOME, KDE, Mac OS X, etc.
  • GUIDs Microsoft's Globally Unique Identifiers
  • other applications include Linux ext2/ext3 file systems, LUKS encryption partitions, GNOME, KDE, Mac OS X, etc.
  • the computer equipment platform provides an API module (Application Programming Interface) that generates a UUID.
  • API module Application Programming Interface
  • the computer device receives the instruction to generate the identification code UUID, and the computer device generates an identification code UUID by calling the API interface of the UUID on the computer device, and the UUID is a 32-bit hexadecimal random number, which is converted into a binary, that is, 16 words. A 128-bit binary number.
  • the UUID can be generated as follows:
  • Java generated code UUID.randomUUID().toString().replace("-",”", generates a 32-bit hexadecimal random number, such as: 406fb0188d884cc3aff84b0f7ea2953c.
  • the UUID consists of the following parts:
  • the current date and time, the first part of the UUID is related to time. If a UUID is generated after a few seconds after generating a UUID, the first part is different and the others are the same.
  • Step 220 Pre-specify the value according to the UUID, and obtain the insertion position between the first position and the last position of the UUID according to the preset acquisition manner.
  • the computer device generates a UUID according to the received instruction for generating the UUID, pre-specifies the value according to the UUID, and obtains an insertion position between the first and last positions of the UUID according to the preset acquisition manner to ensure the first position of the identification code.
  • the value of the last bit and the value of the last bit are unchanged.
  • the reason why an insertion position is obtained between the first and last positions of the UUID is that the insertion position cannot be determined because the insertion position is not known, and the insertion content cannot be obtained, thereby ensuring that the identification code is not cracked or tampered, thereby ensuring that the identification code is not cracked or falsified.
  • UUID security is that the insertion position cannot be determined because the insertion position is not known, and the insertion content cannot be obtained, thereby ensuring that the identification code is not cracked or tampered, thereby ensuring that the identification code is not cracked or falsified.
  • Step 240 Insert a preset content of the verification UUID at the insertion position, generate a new identification code, and generate the preset content according to the first preset rule.
  • the first preset rule includes at least one of the following: generating a manner of generating a current time segment for verifying the validity of the UUID, and generating a check mode for verifying the authenticity of the UUID (or a check code).
  • the computer device acquires the insertion position in the UUID, inserts the preset content in the insertion position, and generates a new identification code. Since the original identification code when the preset content is not inserted is unique, the newly generated identification code is also based on the original unique identifier. It is unique, so as to ensure the uniqueness of the newly generated identification code, according to the insertion content of the new identification code, the verification of the new identification code is realized, and the generation method of the new identification code is simple, the calculation complexity is low, and the efficiency is high. Sex.
  • the insertion position is determined according to the first bit value on the first bit of the new identification code and the last bit value on the last bit, and the preset acquisition mode of the insertion position.
  • the first bit and the last bit of the newly generated identification code after the preset content is inserted are unchanged with respect to the first bit and the last bit of the original identifier, according to The first bit value of the first bit of the newly generated identification code and the last bit value of the last bit, and the preset acquisition mode of the insertion position, find the insertion position.
  • the current time segment of the generated identification code and the current time of the computer device can be compared, and the effective survival of the identification code set on the computer device can be performed.
  • Time verify the timeliness of the identification code, that is, verify that the identification code is still within the valid time. For example, if the effective duration of the identification code set on the computer device is 5 minutes, then the comparison time of the generation of the identification code to the current time on the computer device exceeds 5 minutes. If the identification code is less than 5 minutes, the identification code is within the valid time. The identification code is valid; if the identification code has exceeded the valid time for more than 5 minutes, the identification code is invalid.
  • the check digit It is also possible to verify the authenticity of the identification code by the check digit, that is, according to the verification rule of different verification methods adopted on the check digit, verify whether the check digit has consistency, and if the check digit has consistency, Indicates that the identification code is authentic. If there is an inconsistency in the check digit, it indicates that the identification code has been tampered with or cracked. For example, if the parity bit uses parity, the number of "1"s in the digits of the transmitted binary code is odd or even. The odd number is called odd parity, and the other is called even parity. Which calibration is used is prescribed in advance. Usually a parity bit is set specifically, which is used to make the number of "1"s in this group of codes odd or even. If odd parity is used, when the receiving end receives the set of codes, it is checked whether the number of "1" is an odd number, thereby determining the correctness of the transmission code.
  • a simple verification of the newly generated identification code can be implemented according to the inserted content with respect to the original UUID generated according to the unified rule.
  • the UUID pre-specified value includes at least one of the following: a first value on the first bit of the UUID and a last value on the last bit of the UUID.
  • the computer device generates an identification code UUID by calling an API interface that generates the UUID according to the instruction to generate the identification code UUID, and the identification code UUID generated by the computer device is a 32-bit hexadecimal random number, such as: 406fb0188d884cc3aff84b0f7ea2953c .
  • the computer device determines that the position range of each bit of the identification code UUID is 0 to 31 bits, and the value on each bit is a value between 0 and 15, according to the rules of the computer, the value at each position of the identification code UUID and The decimal correspondence is shown in Table 1 below:
  • the identification code 406fb0188d884cc3aff84b0f7ea2953c
  • the first digit is 4
  • the last digit is c
  • the first digit of the first digit of the identification code "406fb0188d884cc3aff84b0f7ea2953c" is 4
  • the last digit of the last digit is 12.
  • the step of obtaining the insertion position between the first bit and the last bit of the UUID according to the preset acquisition manner includes: according to the first bit value, the last bit value or the first bit value and the last bit position Value, get a positive integer; get the insertion position between the first and last digits of the UUID according to the positive integer, in order from left to right, or from UYID to right-to-left.
  • the computer device obtains the insertion position, and the insertion position is obtained according to the preset value of the pre-specified position and the insertion position of the UUID, and may be a positive integer obtained according to the first value or a positive integer obtained according to the last value. It is also possible to combine a first value with a last value to obtain a positive integer.
  • the above identification code 406fb0188d884cc3aff84b0f7ea2953c
  • the first digit of the first digit of the identification code is 4
  • the last digit of the last digit is c
  • the decimal of the hexadecimal c is 12
  • the computer device according to the first value of the identification code 4
  • the last digit is 12
  • the value 12 is obtained by pre-specifying the value according to the UUID and acquiring the insertion position according to the preset insertion position.
  • the obtained insertion position may be one of the following situations:
  • the value at the position is pre-specified according to the UUID, and the insertion position is obtained by acquiring the insertion position in order from the left to the right according to the identification code.
  • the insertion position is the first value of the identification code, since the first bit value of the identification code is 4, the insertion position is the 4th position of the identification code from left to right, that is, the first f after the identification code from left to right; Similarly, if the insertion position is the last value of the identification code, the insertion position is the 12th position of the identification code from left to right, that is, the 4th 8th from left to right in the identification code.
  • the value of the insertion position is obtained in advance according to the UUID, and the insertion position is obtained by acquiring the insertion position in order from right to left according to the identification code.
  • the insertion position is the first value of the identification code, since the first bit value of the identification code is 4, the insertion position is the 4th position of the identification code from right to left, that is, the position from the right to the left of the first 9 in the identification code. Similarly, if the insertion position is the last value of the identification code, the insertion position is the 12th position of the identification code, that is, the front of the first 4 from right to left in the identification code.
  • the step of obtaining a positive integer according to the first value and the last value includes:
  • a positive integer is obtained based on the sum of the first value on the first digit of the UUID and the last value on the last digit.
  • the computer device obtains a positive integer according to the sum of the first bit value on the first bit of the UUID and the last bit value on the last bit, and according to the obtained positive integer, according to the preset acquisition manner of the insertion position, the first and last positions of the UUID Get the insertion position between.
  • the computer device may use the sum of the first value 4 and the last value 12 of the identification code, in the order of the identification code from left to right, with the 16th position of the identification code as the preset content.
  • the insertion position that is, the preset content is inserted in the 16th position of the identification code: 406fb0188d884cc3 aff84b0f7ea2953c, that is, the space.
  • the step of obtaining a positive integer according to the first value and the last value includes:
  • a positive integer is obtained based on the absolute value of the difference between the first value and the last value of the UUID.
  • the computer device obtains a positive integer according to the absolute value of the difference between the first bit value on the first bit of the UUID and the last bit value on the last bit, and according to the obtained positive integer, according to the preset acquisition mode of the insertion position, the first position of the UUID Get the insertion position between the last bit and the last bit.
  • the computer device may use the absolute value 8 of the difference between the first value 4 and the last value 12 of the identification code, in the order of the identification code from left to right, and the eighth position of the identification code as a pre- Set the insertion position of the content, that is, insert the preset content in the eighth position of the identification code: 406fb018 8d884cc3aff84b0f7ea2953c, that is, the space.
  • the step of obtaining a positive integer based on the first value, the last value, or the first value and the last value includes:
  • the first value plus n1 the last value plus n2, the sum of the first value and the last value plus one, or the absolute value of the difference between the first value and the last value plus n3, obtain a positive integer, where 1 ⁇ n1 ⁇ 16, 1 ⁇ n2 ⁇ 16, 1 ⁇ n3 ⁇ 16.
  • the computer device obtains a positive integer according to one of the following situations, and further acquires the insertion position according to a preset acquisition manner of the positive integer and the insertion position:
  • n1 Add n1 according to the first value, 1 ⁇ n1 ⁇ 16. Since the UUID is a 32-bit natural number, the first value on the first digit is a maximum of 15 and the minimum is 0. To ensure that the insertion position is between the first and last digits, the first value is added to n1, and the range of n1 can only be 1 ⁇ n1. ⁇ 16.
  • n2 can only be 1 ⁇ n2 ⁇ 16.
  • the insertion position it is convenient to determine the insertion position when performing verification, and obtain the preset insertion content according to the insertion position. For example, taking the above identification code: 406fb0188d884cc3aff84b0f7ea2953c as an example, the insertion point position is: 406fb0188d884cc3a insertion point ff84b0f7ea2953c.
  • the absolute value of the difference between the first bit value on the first bit of the identification code and the last bit value on the last bit of the identification code is at most 15, that is, the first bit value on the first bit of the identification code and the last bit on the last bit of the identification code
  • the bit values are one for 0 and one for 15.
  • the absolute value of the difference is 0, which means that the insertion position is the first position of the identification code, the preset insertion content is in front of the identification code, the absolute value of the difference is 15, and there are 17 positions, which means that the insertion position is the identification code.
  • the preset insertion content is behind the identification code, regardless of whether the insertion position is in front of or behind the identification code. In this case, the identification code is easily recognized, so that the insertion position is in the middle of the first and last positions of the UUID.
  • the value of n3 can be up to 16 and the minimum is 1. This insertion mode can ensure that the values of the first and last digits are unchanged, which is convenient for determining the insertion position during verification, and obtaining the pre-position according to the insertion position. Set the insertion content.
  • the insertion point position is: 406fb0188 insertion point d884cc3a ff84b0f7ea2953c.
  • the step of inserting the preset content of the verification UUID at the insertion location comprises:
  • the current time segment refers to a time when the time stamp is acquired when the preset content is inserted at the insertion position, and is represented by a one-digit number, which is called a current time segment.
  • the current time segment can be obtained by taking JavaScript as an example. JavaScript uses new Date().getTime() to get the timestamp, and obtains the decimal timestamp in milliseconds. The decimal timestamp removes the high-order k. Bit (the bit farther from the production time when the time stamp is generated, the value is unchanged for a long time, and the survival time is not affected after the removal), and then the last 3 bits are removed (divided by 1000, intercepted from the second), converted into hexadecimal , get the current time segment.
  • 12345 removes the high level of 12345, that is, the number of bits shared with 12690 far from the production time, which does not affect the judgment of the validity of the survival time. Then, the high bit 12 of 12345 is removed, and the remaining number of bits is 345.
  • the decimal time stamp removes the upper k bits of the high order, which means that the first two bits 12 of the high order of the decimal time stamp 12345 are removed.
  • the obtained timestamp is a timestamp in seconds, which is directly converted into hexadecimal, and the current time segment is obtained by different methods.
  • the timestamp is converted into the required time unit according to the relationship between the unit of time unit milliseconds, seconds, etc., and converted into hexadecimal to obtain the current time segment.
  • the time stamp refers to the total number of seconds from 01:00 to 00:00 on January 01, 1970 (Beijing time, January 01, 1970, 08:00:00).
  • the time segment may also be acquired in units of minutes.
  • JavaScript is still used as an example. Since the timestamp generated by the terminal is calculated in milliseconds by default, since the second and milliseconds are multiples of 1000, if the time segment is acquired in seconds, the last 3 bits are removed, divided by 1000; if it is in minutes, it is divided by 60 ⁇ 1000.
  • the setting of the time segment can also be customized by reversing the order of the time segments, such as from front to back.
  • the time segment obtained by the above algorithm is 12345, and the sequence of 12345 can be reversed.
  • the time segment is represented by 54321, thereby obtaining the customization of the time segment.
  • the manner of obtaining the current time segment in the above manner is various, thereby realizing the flexibility of the current time segment customization, and further ensuring the security of the identification code.
  • the time-sensitive requirement of the identification code is based on the current time segment, and the survival time of the identification code can be defined by the server, and the survival time of the identification code, that is, the effective time of the identification code, During the survival time, the identification code is in a valid state, exceeding the survival time, and the identification code is in a failure state. For example, if the survival time of the identification code is 5 minutes, the identification code is valid within 5 minutes from the time when the identification code is generated. The identification code is invalid for more than 5 minutes.
  • the server compares the generation time of the identification code represented by the current time segment of the generated identification code with the current time, and determines that the identification code is valid within the defined survival time, and if the server determines that the identification code exceeds the identification If the code defines the lifetime, the identifier will be invalid. That is, the survival time of the identification code can be customized according to the needs of the server, for example, 5 minutes, 3 minutes, etc. In the survival time, the UUID is valid, and the UUID is invalid after the survival time is exceeded, thereby verifying the timeliness of the UUID and satisfying the actual situation.
  • the identification code In the case of need for the time-sensitive requirements of the identification code, such as scan code registration, scan code payment, etc., in order to ensure the security of the account, the identification code needs to meet certain timeliness requirements, scan code registration, set the identification code to 2 minutes, in Within 2 minutes, the identification code is valid. If it is more than 2 minutes, the identification code will automatically expire.
  • the check digit is parity, CRC check, and check or MD5 check.
  • Parity Check is a method to verify the correctness of code transmission. The check is performed based on whether the number of "1"s in the digits of the transmitted binary code is odd or even. The odd number is called odd parity, and the other is called even parity. Which calibration is used is prescribed in advance. Usually a parity bit is set specifically, which is used to make the number of "1"s in this group of codes odd or even. If odd parity is used, when the receiving end receives the set of codes, it is checked whether the number of "1" is an odd number, thereby determining the correctness of the transmission code.
  • CRC Cyclic Redundancy Check
  • Cyclic Redundancy Check CRC is the Cyclic Redundancy Check (Cyclic Redundancy Check): It is the most commonly used error checking code in the field of data communication. Its characteristic is that the length of the information field and the check field can be arbitrarily selected.
  • Cyclic Redundancy Check CRC is a data transmission error detection function that performs polynomial calculation on data and attaches the result to the back of the frame. The receiving device also performs a similar algorithm to ensure the correctness and completeness of the data transmission. Sex.
  • check is to verify that the sum of a set of data items is correct. Usually expressed in hexadecimal notation. If the value of the checksum exceeds the hexadecimal FF, it is 255.
  • MD5 The practical application of MD5 is to generate a fingerprint for a piece of Message (byte string) to prevent tampering.
  • the check digit is acquired by the current time segment according to a second preset rule.
  • the second preset rule is a manner of acquiring a check digit.
  • the value of the parity bit can take: (3 bits after the current time segment + insertion bit) %16.
  • the current time segment in the k-bit after the current time segment may be a current time segment expressed in hexadecimal or a current time segment expressed in decimal, thereby further implementing flexible diversity of the check bit acquisition manner.
  • the obtained check digit is also unique, and the authenticity of the identifier is verified according to whether the check digit corresponds to the current time segment.
  • the current time segment is inserted at the insertion position, and the time represented by the current time segment is compared with the current time when the server determines the identification code, and the identification code is determined according to whether the difference of the time exceeds the survival time of the server-defined identification code.
  • Timeliness by inserting a check digit at the insertion position, it is used to set the authenticity of the identification code. If the current time segment and the check digit are simultaneously inserted in the position, the timeliness and authenticity of the identification code can be verified at the same time.
  • the identification code adopts hexadecimal, the value at each position of the identification code is at most 15, so the insertion position obtained by (first value + last value) +1 is in the middle of the first and last bits of the identification code.
  • the current time segment can be intercepted from the second, remove the upper k position (bit far from the production time), and turn to hexadecimal, for example, the current time segment of the obtained hexadecimal is: 1d8b6f84.
  • the survival time of the identifier set by the server is 3 minutes.
  • Check digit 1 bit, the value is: (3 bits after the current time segment + insert bit) %16, for example, the current time segment is expressed in hexadecimal, the last 3 digits of the current time segment in decimal notation To obtain the check digit, the current time segment according to hexadecimal is: the check digit of the last 3 digits of the decimal representation of 1d8b6f84 is 5.
  • the new identifier generation result is as follows:
  • the 17th position of the insertion position is found, and according to the new UUID length -32 (the original UUID length), the insertion length 9 bits is acquired, and the insertion content 1d8b6f84 5 is intercepted from the insertion position.
  • the identification code generated by the above manner can verify the authenticity and timeliness of the identification code.
  • the newly generated identification code according to the above manner is also unique and can be verified according to the counter-evidence method:
  • the original UUID is unique
  • U1 is the same as the end of u2, and the insertion point is the same.
  • the improved new UUID has the following beneficial effects:
  • the generation and verification algorithm has low complexity and short time.
  • the current time segment and the check digit are inserted at the insertion position, wherein the current time segment is first, the parity bit is after, or the parity bit is first, and the current time segment is after.
  • the order of the current time segment and the check bit may be set to the current time segment first, or may be set to the check bit first.
  • a unique field is required to represent the two-dimensional code
  • a unique field UUID is used to represent the two-dimensional code, and the authenticity is verified by the uniqueness of the UUID.
  • the validity and failure of the two-dimensional code are ensured by the timeliness of the UUID.
  • the method for generating the identification code generates a UUID by receiving an instruction to generate the identification code UUID; pre-specifying the value according to the UUID, obtaining an insertion position between the first and last positions of the UUID; and inserting the verification UUID at the insertion position
  • the preset content is generated, a new identification code is generated, and the simple verification of the identification code is realized by the inserted preset content.
  • an embodiment of the present application further provides an apparatus for generating an identifier, where the apparatus includes:
  • the generating module 30 is configured to generate a UUID if receiving an instruction to generate the identification code UUID.
  • the computer device receives the instruction for generating the identifier UUID, and the computer device generates an identifier UUID by calling an API interface for generating the UUID on the computer device, and the UUID is a 32-bit hexadecimal random number, which is converted into a binary, It is a 16-byte 128-bit binary number.
  • the UUID can be generated as follows:
  • Java generated code UUID.randomUUID().toString().replace("-",”", generates a 32-bit hexadecimal random number, such as: 406fb0188d884cc3aff84b0f7ea2953c.
  • the obtaining module 32 is configured to obtain the insertion position between the first position and the last position of the UUID according to the preset acquisition manner according to the UUID.
  • the computer device generates a UUID according to the received instruction for generating the UUID, pre-specifies the value according to the UUID, and obtains an insertion position between the first and last positions of the UUID according to the preset acquisition manner to ensure the first position of the identification code.
  • the value of the last bit and the value of the last bit are unchanged.
  • the reason why an insertion position is obtained between the first and last positions of the UUID is that the insertion position cannot be determined because the insertion position is not known, and the insertion content cannot be obtained, thereby ensuring that the identification code is not cracked or tampered, thereby ensuring that the identification code is not cracked or falsified.
  • UUID security is that the insertion position cannot be determined because the insertion position is not known, and the insertion content cannot be obtained, thereby ensuring that the identification code is not cracked or tampered, thereby ensuring that the identification code is not cracked or falsified.
  • the generating module 34 is configured to insert a preset content of the verification UUID at the insertion position, generate a new identification code, and generate the preset content according to the first preset rule.
  • the first preset rule includes at least one of the following: generating a manner of generating a current time segment for verifying the validity of the UUID, and generating a check mode for verifying the authenticity of the UUID (or a check code).
  • the computer device acquires the insertion position in the UUID, inserts the preset content in the insertion position, and generates a new identification code. Since the original identification code when the preset content is not inserted is unique, the newly generated identification code is also based on the original unique identifier. It is unique, so as to ensure the uniqueness of the newly generated identification code, according to the insertion content of the new identification code, the verification of the new identification code is realized, and the generation method of the new identification code is simple, the calculation complexity is low, and the efficiency is high. Sex.
  • the current time segment of the generated identification code and the current time of the computer device can be compared, and the effective duration of the identification code set on the computer device can be verified.
  • the timeliness of the identification code that is, whether the identification code is still within the valid time. For example, if the effective duration of the identification code set on the computer device is 5 minutes, then the comparison time of the generation of the identification code to the current time on the computer device exceeds 5 minutes. If the identification code is less than 5 minutes, the identification code is within the valid time. The identification code is valid; if the identification code has exceeded the valid time for more than 5 minutes, the identification code is invalid.
  • the check digit It is also possible to verify the authenticity of the identification code by the check digit, that is, according to the verification rule of different verification methods adopted on the check digit, verify whether the check digit has consistency, and if the check digit has consistency, Indicates that the identification code is authentic. If there is an inconsistency in the check digit, it indicates that the identification code has been tampered with or cracked. For example, if the parity bit uses parity, the number of "1"s in the digits of the transmitted binary code is odd or even. The odd number is called odd parity, and the other is called even parity. Which calibration is used is prescribed in advance. Usually a parity bit is set specifically, which is used to make the number of "1"s in this group of codes odd or even. If odd parity is used, when the receiving end receives the set of codes, it is checked whether the number of "1" is an odd number, thereby determining the correctness of the transmission code.
  • a simple verification of the newly generated identification code can be implemented according to the inserted content with respect to the original UUID generated according to the unified rule.
  • the UUID pre-specified value includes at least one of the following: a first value on the first bit of the UUID and a last value on the last bit of the UUID.
  • the computer device generates an identification code UUID by calling an API interface that generates the UUID according to the instruction to generate the identification code UUID, and the identification code UUID generated by the computer device is a 32-bit hexadecimal random number, such as: 406fb0188d884cc3aff84b0f7ea2953c .
  • the computer device determines that the position range of each bit of the identification code UUID is 0 to 31 bits, and the value on each bit is a value between 0 and 15, according to the rules of the computer, the value at each position of the identification code UUID and The decimal correspondence is shown in Table 2 below:
  • the above identification code 406fb0188d884cc3aff84b0f7ea2953c, the first digit is 4, and the last digit is c, the first digit of the first digit of the identification code "406fb0188d884cc3aff84b0f7ea2953c" is 4, and the last digit of the last digit is 12.
  • the obtaining module 32 includes: a positive integer obtaining unit, configured to obtain a positive integer according to the first bit value, the last bit value or the first bit value and the last bit value; and an insertion position obtaining unit for using the UUID from left to right
  • the order of the insertion, or the order of the UUID from right to left, according to a positive integer obtains the insertion position between the first and last digits of the UUID.
  • the computer device obtains the insertion position, and the insertion position is obtained according to the preset value of the pre-specified position and the insertion position of the UUID, and may be a positive integer obtained according to the first value or a positive integer obtained according to the last value. It is also possible to combine a first value with a last value to obtain a positive integer.
  • the above identification code 406fb0188d884cc3aff84b0f7ea2953c, it can be seen that the first digit of the first digit of the identification code is 4, the last digit of the last digit is c, the decimal of the hexadecimal c is 12, and the computer device according to the first value of the identification code 4, and the last digit.
  • the value 12 is obtained by pre-specifying the value according to the UUID and acquiring the insertion position according to the preset insertion position.
  • the obtained insertion position may be one of the following situations:
  • the value at the position is pre-specified according to the UUID, and the insertion position is obtained by acquiring the insertion position in order from the left to the right according to the identification code.
  • the insertion position is the first value of the identification code, since the first bit value of the identification code is 4, the insertion position is the 4th position of the identification code from left to right, that is, the first f after the identification code from left to right; Similarly, if the insertion position is the last value of the identification code, the insertion position is the 12th position of the identification code from left to right, that is, the 4th 8th from left to right in the identification code.
  • the value of the insertion position is obtained in advance according to the UUID, and the insertion position is obtained by acquiring the insertion position in order from right to left according to the identification code.
  • the insertion position is the first value of the identification code, since the first bit value of the identification code is 4, the insertion position is the 4th position of the identification code from right to left, that is, the position from the right to the left of the first 9 in the identification code. Similarly, if the insertion position is the last value of the identification code, the insertion position is the 12th position of the identification code, that is, the front of the first 4 from right to left in the identification code.
  • the positive integer acquisition unit includes: for obtaining a positive integer based on the sum of the first bit value on the first bit of the UUID and the last bit value on the last bit.
  • the computer device obtains a positive integer according to the sum of the first bit value on the first bit of the UUID and the last bit value on the last bit, and according to the obtained positive integer, according to the preset acquisition manner of the insertion position, the first and last positions of the UUID Get the insertion position between.
  • the computer device may use the sum of the first value 4 and the last value 12 of the identification code, in the order of the identification code from left to right, with the 16th position of the identification code as the preset content.
  • the insertion position that is, the preset content is inserted in the 16th position of the identification code: 406fb0188d884cc3 aff84b0f7ea2953c, that is, the space.
  • the positive integer acquisition unit includes: for obtaining a positive integer based on the absolute value of the difference between the first value and the last value of the UUID.
  • the computer device obtains a positive integer according to the absolute value of the difference between the first bit value on the first bit of the UUID and the last bit value on the last bit, and according to the obtained positive integer, according to the preset acquisition mode of the insertion position, the first position of the UUID Get the insertion position between the last bit and the last bit.
  • the computer device may use the absolute value 8 of the difference between the first value 4 and the last value 12 of the identification code, in the order of the identification code from left to right, and the eighth position of the identification code as a pre- Set the insertion position of the content, that is, insert the preset content in the eighth position of the identification code: 406fb018 8d884cc3aff84b0f7ea2953c, that is, the space.
  • the positive integer obtaining unit includes: for adding n1 according to the first value, adding n2 for the last value, adding 1 to the sum of the first value and the last value, or adding the absolute value of the difference between the first value and the last value plus N3, obtaining a positive integer, where 1 ⁇ n1 ⁇ 16, 1 ⁇ n2 ⁇ 16, 1 ⁇ n3 ⁇ 16.
  • the computer device obtains a positive integer according to one of the following situations, and further acquires the insertion position according to a preset acquisition manner of the positive integer and the insertion position:
  • n1 Add n1 according to the first value, 1 ⁇ n1 ⁇ 16. Since the UUID is a 32-bit natural number, the first value on the first digit is a maximum of 15 and the minimum is 0. To ensure that the insertion position is between the first and last digits, the first value is added to n1, and the range of n1 can only be 1 ⁇ n1. ⁇ 16.
  • n2 can only be 1 ⁇ n2 ⁇ 16.
  • the insertion position it is convenient to determine the insertion position when performing verification, and obtain the preset insertion content according to the insertion position. For example, taking the above identification code: 406fb0188d884cc3aff84b0f7ea2953c as an example, the insertion point position is: 406fb0188d884cc3a insertion point ff84b0f7ea2953c.
  • the absolute value of the difference between the first bit value on the first bit of the identification code and the last bit value on the last bit of the identification code is at most 15, that is, the first bit value on the first bit of the identification code and the last bit on the last bit of the identification code
  • the bit values are one for 0 and one for 15.
  • the absolute value of the difference is 0, which means that the insertion position is the first position of the identification code, the preset insertion content is in front of the identification code, the absolute value of the difference is 15, and there are 17 positions, which means that the insertion position is the identification code.
  • the preset insertion content is behind the identification code, regardless of whether the insertion position is in front of or behind the identification code. In this case, the identification code is easily recognized, so that the insertion position is in the middle of the first and last positions of the UUID.
  • the value of n3 can be up to 16 and the minimum is 1. This insertion mode can ensure that the values of the first and last digits are unchanged, which is convenient for determining the insertion position during verification, and obtaining the pre-position according to the insertion position. Set the insertion content.
  • the insertion point position is: 406fb0188 insertion point d884cc3a ff84b0f7ea2953c.
  • the generating module 34 includes: for inserting at least one of the following at the insertion position: a current time segment, a parity bit.
  • the current time segment refers to a time when the time stamp is acquired when the preset content is inserted at the insertion position, and is represented by a one-digit number, which is called a current time segment.
  • the current time segment can be obtained by taking JavaScript as an example. JavaScript uses new Date().getTime() to get the timestamp, and obtains the decimal timestamp in milliseconds. The decimal timestamp removes the high-order k. Bit (the bit farther from the production time when the time stamp is generated, the value is unchanged for a long time, and the survival time is not affected after the removal), and then the last 3 bits are removed (divided by 1000, intercepted from the second), converted into hexadecimal , get the current time segment.
  • 12345 removes the high level of 12345, that is, the number of bits shared with 12690 far from the production time, which does not affect the judgment of the validity of the survival time. Then, the high bit 12 of 12345 is removed, and the remaining number of bits is 345.
  • the decimal time stamp removes the upper k bits of the high order, which means that the first two bits 12 of the high order of the decimal time stamp 12345 are removed.
  • the obtained timestamp is a timestamp in seconds, which is directly converted into hexadecimal, and the current time segment is obtained by different methods.
  • the timestamp is converted into the required time unit according to the relationship between the unit of time unit milliseconds, seconds, etc., and converted into hexadecimal to obtain the current time segment.
  • the time stamp refers to the total number of seconds from 01:00 to 00:00 on January 01, 1970 (Beijing time, January 01, 1970, 08:00:00).
  • the time segment may also be acquired in units of minutes.
  • JavaScript is still used as an example. Since the timestamp generated by the terminal is calculated in milliseconds by default, since the second and milliseconds are multiples of 1000, if the time segment is acquired in seconds, the last 3 bits are removed, divided by 1000; if it is in minutes, it is divided by 60 ⁇ 1000.
  • the setting of the time segment can also be customized by reversing the order of the time segments, such as from front to back.
  • the time segment obtained by the above algorithm is 12345, and the sequence of 12345 can be reversed.
  • the time segment is represented by 54321, thereby obtaining the customization of the time segment.
  • the manner of obtaining the current time segment in the above manner is various, thereby realizing the flexibility of the current time segment customization, and further ensuring the security of the identification code.
  • the time-sensitive requirement of the identification code is based on the current time segment, and the survival time of the identification code can be defined by the server, and the survival time of the identification code, that is, the effective time of the identification code, During the survival time, the identification code is in a valid state, exceeding the survival time, and the identification code is in a failure state. For example, if the survival time of the identification code is 5 minutes, the identification code is valid within 5 minutes from the time when the identification code is generated. The identification code is invalid for more than 5 minutes.
  • the server compares the generation time of the identification code represented by the current time segment of the generated identification code with the current time, and determines that the identification code is valid within the defined survival time, and if the server determines that the identification code exceeds the identification If the code defines the lifetime, the identifier will be invalid. That is, the survival time of the identification code can be customized according to the needs of the server, for example, 5 minutes, 3 minutes, etc. In the survival time, the UUID is valid, and the UUID is invalid after the survival time is exceeded, thereby verifying the timeliness of the UUID and satisfying the actual situation.
  • the identification code In the case of need for the time-sensitive requirements of the identification code, such as scan code registration, scan code payment, etc., in order to ensure the security of the account, the identification code needs to meet certain timeliness requirements, scan code registration, set the identification code to 2 minutes, in Within 2 minutes, the identification code is valid. If it is more than 2 minutes, the identification code will automatically expire.
  • the check digit is parity, CRC check, and check or MD5 check.
  • the check digit is acquired by the current time segment according to a second preset rule.
  • the second preset rule is a manner of acquiring a check digit.
  • the value of the parity bit can take: (3 bits after the current time segment + insertion bit) %16.
  • the current time segment in the k-bit after the current time segment may be a current time segment expressed in hexadecimal or a current time segment expressed in decimal, thereby further implementing flexible diversity of the check bit acquisition manner.
  • the obtained check digit is also unique, and the authenticity of the identifier is verified according to whether the check digit corresponds to the current time segment.
  • the current time segment is inserted at the insertion position, and the time represented by the current time segment is compared with the current time when the server determines the identification code, and the identification code is determined according to whether the difference of the time exceeds the survival time of the server-defined identification code.
  • Timeliness by inserting a check digit at the insertion position, it is used to set the authenticity of the identification code. If the current time segment and the check digit are simultaneously inserted in the position, the timeliness and authenticity of the identification code can be verified at the same time.
  • the identification code adopts hexadecimal, the value at each position of the identification code is at most 15, so the insertion position obtained by (first value + last value) +1 is in the middle of the first and last bits of the identification code.
  • the current time segment can be intercepted from the second, remove the upper k position (bit far from the production time), and turn to hexadecimal, for example, the current time segment of the obtained hexadecimal is: 1d8b6f84.
  • the survival time of the identifier set by the server is 3 minutes.
  • Check digit 1 bit, the value is: (3 bits after the current time segment + insert bit) %16, for example, the current time segment is expressed in hexadecimal, the last 3 digits of the current time segment in decimal notation To obtain the check digit, the current time segment according to hexadecimal is: the check digit of the last 3 digits of the decimal representation of 1d8b6f84 is 5.
  • the new identifier generation result is as follows:
  • the 17th position of the insertion position is found, and according to the new UUID length -32 (the original UUID length), the insertion length 9 bits is acquired, and the insertion content 1d8b6f84 5 is intercepted from the insertion position.
  • the identification code generated by the above manner can verify the authenticity and timeliness of the identification code.
  • the improved new UUID has the following beneficial effects:
  • the inserted time segment, check field and its life cycle can be customized, therefore, the new UUID generation rules are diverse;
  • the generation and verification algorithm has low complexity and short time.
  • the current time segment and the check digit are inserted at the insertion position, wherein the current time segment is first, the parity bit is after, or the parity bit is first, and the current time segment is after.
  • the order of the current time segment and the check bit may be set to the current time segment first, or may be set to the check bit first.
  • a unique field is required to represent the two-dimensional code
  • a unique field UUID is used to represent the two-dimensional code, and the authenticity is verified by the uniqueness of the UUID.
  • the validity and failure of the two-dimensional code are ensured by the timeliness of the UUID.
  • each module in the above-mentioned identification code generating device is for illustrative purposes only. In other embodiments, the identification code generating device may be divided into different modules as needed to complete all or part of the above-mentioned identification code generating device.
  • the above-described identification code generating means can be implemented in the form of a computer readable instruction which can be run on a computer device as shown in FIG.
  • one or more non-volatile readable storage media having computer readable instructions stored by one or more processors are provided, such that one or more processors are Performing the following steps: if receiving the instruction for generating the identification code UUID, generating the UUID; and pre-specifying the value according to the UUID, obtaining the insertion position between the first and last positions of the UUID according to the preset acquisition manner; inserting at the insertion position The preset content of the UUID is verified, and a new identification code is generated, and the preset content is generated according to the first preset rule.
  • the UUID pre-specified value includes at least one of the following: a first value on the first bit of the UUID and a last value on the last bit of the UUID.
  • the step of obtaining the insertion position between the first position and the last position of the UUID according to the preset acquisition manner by the processor according to the UUID pre-specified value includes: according to the first value, the last value or The first value and the last value are obtained as positive integers; and the insertion position is obtained between the first and last positions of the UUID according to the positive integer in the order from left to right in UUID or from right to left in accordance with the UUID.
  • the step of obtaining a positive integer according to the first bit value and the last bit value performed by the processor comprises: according to the sum of the first bit value and the last bit value, or according to the absolute value of the difference between the first bit value and the last bit value, Get a positive integer.
  • the step of obtaining a positive integer according to the first bit value, the last bit value or the first bit value and the last bit value performed by the processor includes: adding n1 according to the first bit value, adding n2 to the last bit value, and the first bit value and the last bit value. The sum is incremented by 1, or the absolute value of the difference between the first bit value and the last bit value is added by n3 to obtain a positive integer, where 1 ⁇ n1 ⁇ 16, 1 ⁇ n2 ⁇ 16, and 1 ⁇ n3 ⁇ 16.
  • the step of inserting, by the processor, the preset content of the verification UUID at the insertion position comprises: inserting at least one of the following contents at the insertion position: a current time segment, a parity bit.
  • the check digit is acquired by the current time segment according to a second preset rule.
  • the embodiment of the present application further provides a computer device, including a memory and a processor, where the computer stores readable instructions, and when the computer readable instructions are executed by the processor, the method for generating the identifier executed by the processor A step of.
  • the computer device can be a computer device including a personal computer or a server.
  • the computer device includes a processor, a non-volatile storage medium, an internal memory, and a network interface connected by a system bus.
  • the non-volatile storage medium of the computer device stores an operating system and computer readable instructions.
  • the computer readable instructions are executed by the processor to implement a method of generating an identification code.
  • the processor of the computer device is used to provide computing and control capabilities to support the operation of the entire computer device.
  • the network interface of the computer device is configured to communicate with an external terminal via a network connection, such as receiving a scan code request sent by the terminal and returning a two-dimensional code including the identification code to the terminal.
  • the computer device can be implemented by a stand-alone server or a server cluster composed of multiple servers. It will be understood by those skilled in the art that the structure shown in FIG. 4 is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation of the computer device to which the solution of the present application is applied.
  • the specific computer device may It includes more or fewer components than those shown in the figures, or some components are combined, or have different component arrangements.
  • a computer apparatus comprising a memory and one or more processors having stored therein computer readable instructions that, when executed by a processor, cause one or more processes
  • the device performs the following steps: if receiving the instruction for generating the identification code UUID, generating the UUID; and pre-specifying the value according to the UUID, and obtaining the insertion position between the first and last positions of the UUID according to the preset acquisition manner;
  • the preset content of the verification UUID is inserted to generate a new identification code, and the preset content is generated according to the first preset rule.
  • the UUID pre-specified value includes at least one of the following: a first value on the first bit of the UUID and a last value on the last bit of the UUID.
  • the step of obtaining the insertion position between the first position and the last position of the UUID according to the preset acquisition manner by the processor according to the UUID pre-specified value includes: according to the first value, the last value or The first value and the last value are obtained as positive integers; and the insertion position is obtained between the first and last positions of the UUID according to the positive integer in the order from left to right in UUID or from right to left in accordance with the UUID.
  • the step of obtaining a positive integer according to the first bit value and the last bit value performed by the processor comprises: according to the sum of the first bit value and the last bit value, or according to the absolute value of the difference between the first bit value and the last bit value, Get a positive integer.
  • the step of obtaining a positive integer according to the first bit value, the last bit value or the first bit value and the last bit value performed by the processor includes: adding n1 according to the first bit value, adding n2 to the last bit value, and the first bit value and the last bit value. The sum is incremented by 1, or the absolute value of the difference between the first bit value and the last bit value is added by n3 to obtain a positive integer, where 1 ⁇ n1 ⁇ 16, 1 ⁇ n2 ⁇ 16, and 1 ⁇ n3 ⁇ 16.
  • the step of inserting, by the processor, the preset content of the verification UUID at the insertion position comprises: inserting at least one of the following contents at the insertion position: a current time segment, a parity bit.
  • the check digit is acquired by the current time segment according to a second preset rule.
  • Non-volatile memories can include read only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory.
  • ROM read only memory
  • PROM programmable ROM
  • EPROM electrically programmable ROM
  • EEPROM electrically erasable programmable ROM

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Quality & Reliability (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Storage Device Security (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

A method for generating an identifier. The method comprises: if an instruction for generating an identifier UUID is received, generating the UUID; acquiring an insertion position between the first bit and the tail bit of the UUID in a pre-set acquisition manner according to a value at a pre-designated position in the UUID; and inserting, at the insertion position, pre-set content for verifying the UUID, and generating a new identifier, with the pre-set content being generated according to a first pre-set rule.

Description

识别码的生成方法和装置、计算机设备和存储介质Method and device for generating identification code, computer device and storage medium
本申请要求于2017年10月30日提交中国专利局、申请号为201711035194.9、发明名称为“识别码的生成方法和装置、计算机设备、可读存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese Patent Application filed on October 30, 2017, the Chinese Patent Application No. 201711035194.9, the invention entitled "Identification Code Generation Method and Apparatus, Computer Equipment, Readable Storage Medium", all of which The content is incorporated herein by reference.
技术领域Technical field
本申请涉及计算机技术领域,特别是涉及一种识别码的生成方法和装置、计算机设备和存储介质。The present application relates to the field of computer technology, and in particular, to a method and device for generating an identification code, a computer device, and a storage medium.
背景技术Background technique
UUID,是指通用唯一识别码(Universally Unique Identifier),UUID的目的是让分布式系统中的所有元素,都能有唯一的标识,而不需要透过中央控制端来做辨别标识的指定。如此一来,分布式系统中的每个元素都可以建立不与其它元素冲突的UUID。在这样的情况下,就不需考虑数据库建立时的名称重复问题。UUID是指在一台机器上生成的数字,它保证对在同一时空中的所有机器都是唯一的。通常平台会提供生成UUID的API(Application Programming Interface,应用程序编程接口)。按照开放软件基金会(OSF)制定的标准计算,用到了以太网卡地址、纳秒级时间、芯片ID码和许多可能的数字。UUID refers to the Universally Unique Identifier. The purpose of UUID is to make all elements in a distributed system uniquely identified without the need to identify the identification through the central console. In this way, each element in the distributed system can establish a UUID that does not conflict with other elements. In such a case, there is no need to consider the name duplication problem when the database is created. UUID is a number generated on a machine that is guaranteed to be unique to all machines in the same time and space. Usually the platform provides an API (Application Programming Interface) that generates UUIDs. According to the standards developed by the Open Software Foundation (OSF), Ethernet card addresses, nanosecond time, chip ID codes, and many possible numbers are used.
上述UUID生成算法采用随机生成一个32位的十六进制数,但规则统一,任何人都可以生成,对识别码的校验存在困难。The above UUID generation algorithm randomly generates a 32-bit hexadecimal number, but the rules are uniform and can be generated by anyone, and it is difficult to verify the identification code.
发明内容Summary of the invention
根据本申请的各种实施例,提供一种识别码的生成方法和装置、计算机设备和存储介质。According to various embodiments of the present application, a method and apparatus for generating an identification code, a computer device, and a storage medium are provided.
一种识别码的生成方法,所述方法包括:若接收到产生识别码UUID的指令,产生所述UUID;根据所述UUID预先指定位置上的值,按照预设获取方式,在所述UUID的首位和末位之间获取插入位置;及在所述插入位置插入验证所述UUID的预设内容,生成新的识别码,所述预设内容按照第一预设规则生成。A method for generating an identification code, the method comprising: generating an UUID if an instruction to generate an identification code UUID is received; pre-specifying a value according to the UUID, according to a preset acquisition manner, in the UUID Obtaining an insertion position between the first position and the last position; and inserting a preset content for verifying the UUID at the insertion position to generate a new identification code, and the preset content is generated according to the first preset rule.
一种识别码的生成装置,所述装置包括:产生模块,用于若接收到产生识别码UUID的指令,产生所述UUID;获取模块,用于根据所述UUID预先指定位置上的值,按照预设获取方式,在所述UUID的首位和末位之间获取插入位置;及生成模块,用于在所述插入位置插入验证所述UUID的预设内容,生成新的识别码,所述预设内容按照第一预设规则生成。An apparatus for generating an identification code, the apparatus comprising: a generating module, configured to generate the UUID if an instruction to generate an identification code UUID is received; and an acquiring module, configured to pre-specify a value according to the UUID according to the UUID a preset acquisition mode, obtaining an insertion position between a first bit and a last bit of the UUID; and a generating module, configured to insert a preset content for verifying the UUID at the insertion position, and generate a new identification code, where the The content is generated according to the first preset rule.
一种计算机设备,包括存储器和一个或多个处理器,所述存储器中存储有计算机可读指令,所述计算机可读指令被所述处理器执行时,使得所述一个或多个处理器执行以下步骤:若接收到产生识别码UUID的指令,产生所述UUID;根据所述UUID预先指定位置上的值,按照预设获取方式,在所述UUID的首位和末位之间获取插入位置;及在所述插入位置插入验证所述UUID的预设内容,生成新的识别码,所述预设内容按照第一预设规则生成。A computer device comprising a memory and one or more processors, the memory storing computer readable instructions, the computer readable instructions being executed by the processor, causing the one or more processors to execute The following steps: if the instruction for generating the identifier UUID is received, the UUID is generated; the value at the location is pre-specified according to the UUID, and the insertion position is obtained between the first and last digits of the UUID according to a preset acquisition manner; And inserting a preset content for verifying the UUID at the insertion position, generating a new identification code, and the preset content is generated according to the first preset rule.
一个或多个存储有计算机可读指令的非易失性可读存储介质,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行以下步骤:若接收到产生识别码UUID的指令,产生所述UUID;根据所述UUID预先指定位置上的值,按照预设获取方式,在所述UUID的首位和末位之间获取插入位置;及在所述插入位置插入验证所述UUID的预设内容,生成新的识别码,所述预设内容按照第一预设规则生成。One or more non-transitory readable storage mediums storing computer readable instructions, when executed by one or more processors, cause the one or more processors to perform the following steps: Receiving an instruction to generate an identifier UUID, generating the UUID; pre-specifying a value according to the UUID, acquiring an insertion position between a first bit and a last bit of the UUID according to a preset acquisition manner; The insertion position is inserted to verify the preset content of the UUID, and a new identification code is generated, and the preset content is generated according to the first preset rule.
本申请的一个或多个实施例的细节在下面的附图和描述中提出。本申请的其它特征、目的和优点将从说明书、附图以及权利要求书变得明显。Details of one or more embodiments of the present application are set forth in the accompanying drawings and description below. Other features, objects, and advantages of the invention will be apparent from the description and appended claims.
附图说明DRAWINGS
为了更清楚地说明本申请实施例或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings to be used in the embodiments or the prior art description will be briefly described below. Obviously, the drawings in the following description are only It is a certain embodiment of the present application, and other drawings can be obtained according to the drawings without any creative work for those skilled in the art.
图1为一个实施例中识别码的生成方法的应用环境图;1 is an application environment diagram of a method for generating an identification code in an embodiment;
图2为一个实施例中识别码的生成方法的流程图;2 is a flow chart of a method for generating an identification code in an embodiment;
图3为一个实施例中识别码的生成装置的结构图;3 is a structural diagram of an apparatus for generating an identification code in an embodiment;
图4为一个实施例中计算机设备的内部结构图。4 is a diagram showing the internal structure of a computer device in an embodiment.
具体实施方式Detailed ways
为了使本申请的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本申请进行进一步详细说明。应当理解,此处所描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。In order to make the objects, technical solutions, and advantages of the present application more comprehensible, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It is understood that the specific embodiments described herein are merely illustrative of the application and are not intended to be limiting.
可以理解,本申请所使用的术语“第一”、“第二”等可在本文中用于描述各种元素,但这些元素不受这些术语限制。这些术语仅用于将第一个元素与另一个元素区分。举例来说,在不脱离本申请的范围的情况下,可以将第一预设规则称为第二预设规则,且类似地,可将第二预设规则称为第一预设规则。第一预设规则和第二预设规则两者都是预设规则,但其不是同一预设规则。It will be understood that the terms "first," "second," and the like, as used herein, may be used to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish the first element from another element. For example, the first preset rule may be referred to as a second preset rule without departing from the scope of the present application, and similarly, the second preset rule may be referred to as a first preset rule. Both the first preset rule and the second preset rule are preset rules, but they are not the same preset rule.
请参阅图1,图1为一个实施例中识别码的生成方法的应用环境图,该应用环境包括:终端120、连接网络140和服务器160。其中,终端120包括移动终端、平板电脑、智能穿戴设备、台式机或者笔记本等电子设备。连接网络140为有线或无线网络,无线连接方式包括移动通信网络或者WIFI(WIreless-Fidelity,无线保真)等连接方式。服务器160,为本地服务器或者云端服务器等。Please refer to FIG. 1. FIG. 1 is an application environment diagram of a method for generating an identifier in an embodiment, where the application environment includes: a terminal 120, a connection network 140, and a server 160. The terminal 120 includes an electronic device such as a mobile terminal, a tablet computer, a smart wearable device, a desktop computer, or a notebook. The connection network 140 is a wired or wireless network, and the wireless connection method includes a mobile communication network or a connection method such as WIFI (WIreless-Fidelity). The server 160 is a local server or a cloud server.
该应用环境中各部件的工作过程为:终端120通过连接网络140向服务器160发送请求,比如终端120通过连接网络140向服务器160发送通过扫描二维码进行账号登录请求,服务器160接收到终端120发送的账号登录请求后,服务器160调用服务器160上产生通用唯一识别码UUID的模块,模块接收到产生识别码UUID的指令后,产生UUID,同时服务器160 根据UUID预先指定位置上的值,按照预设获取方式,在UUID的首位和末位之间获取插入位置,在插入位置插入按照第一预设规则产生的验证UUID的预设内容,生成新的识别码,服务器160将通用唯一的新的识别码以二维码的形式发送给终端120,终端120通过新的识别码进行账号验证,登录服务器160,当终端120通过包含新的识别码的二维码登录服务器160时,服务器160通过新的识别码包含的验证内容验证二维码,进而实现对登录账号的验证。The working process of each component in the application environment is: the terminal 120 sends a request to the server 160 through the connection network 140, for example, the terminal 120 sends an account login request by scanning the two-dimensional code to the server 160 through the connection network 140, and the server 160 receives the terminal 120. After the account login request is sent, the server 160 invokes a module for generating the universal unique identifier UUID on the server 160. After receiving the instruction to generate the identifier UUID, the module generates a UUID, and the server 160 pre-specifies the value according to the UUID, according to the pre-predetermined value. The acquisition mode is set to obtain an insertion position between the first and last positions of the UUID, and the preset content of the verification UUID generated according to the first preset rule is inserted at the insertion position to generate a new identification code, and the server 160 will be universally unique and new. The identification code is sent to the terminal 120 in the form of a two-dimensional code. The terminal 120 performs account verification by using the new identification code, and logs in to the server 160. When the terminal 120 logs in to the server 160 through the two-dimensional code including the new identification code, the server 160 passes the new one. The verification code contained in the identification code verifies the two-dimensional code, thereby implementing verification of the login account. .
请参阅图2,图2为本申请提供的识别码的生成方法的一个实施例的流程图,该方法包括:Referring to FIG. 2, FIG. 2 is a flowchart of an embodiment of a method for generating an identifier provided by the present application, where the method includes:
步骤200、若接收到产生识别码UUID的指令,产生UUID。Step 200: If an instruction to generate the identification code UUID is received, a UUID is generated.
具体地,目前最广泛应用的UUID,即是微软的Microsoft's Globally Unique Identifiers(GUIDs),而其他应用,则有Linux ext2/ext3档案系统、LUKS加密分割区、GNOME、KDE、Mac OS X等等,通常计算机设备平台会提供生成UUID的API模块(Application Programming Interface,应用程序编程接口)。Specifically, the most widely used UUIDs are Microsoft's Globally Unique Identifiers (GUIDs), while other applications include Linux ext2/ext3 file systems, LUKS encryption partitions, GNOME, KDE, Mac OS X, etc. Usually, the computer equipment platform provides an API module (Application Programming Interface) that generates a UUID.
计算机设备接收到产生识别码UUID的指令,计算机设备通过调用计算机设备上的生成UUID的API接口,生成一个识别码UUID,UUID为32位的16进制随机数,转化为二进制,也就是16字节128位的二进制数。The computer device receives the instruction to generate the identification code UUID, and the computer device generates an identification code UUID by calling the API interface of the UUID on the computer device, and the UUID is a 32-bit hexadecimal random number, which is converted into a binary, that is, 16 words. A 128-bit binary number.
UUID的生成方式可以为:The UUID can be generated as follows:
Java生成代码:UUID.randomUUID().toString().replace("-",""),生成一个32位的16进制随机数,如:406fb0188d884cc3aff84b0f7ea2953c。Java generated code: UUID.randomUUID().toString().replace("-",""), generates a 32-bit hexadecimal random number, such as: 406fb0188d884cc3aff84b0f7ea2953c.
通常,UUID由以下几部分的组合:Usually, the UUID consists of the following parts:
(1)当前日期和时间,UUID的第一个部分与时间有关,如果在生成一个UUID之后,过几秒又生成一个UUID,则第一个部分不同,其余相同。(1) The current date and time, the first part of the UUID is related to time. If a UUID is generated after a few seconds after generating a UUID, the first part is different and the others are the same.
(2)时钟序列。(2) Clock sequence.
(3)全局唯一的IEEE机器识别号(IEEE,全称是Institute of Electrical and Electronics Engineers,电气和电子工程师协会),如果有网卡,从网卡MAC地址获得(MAC,Media Access Control或者Medium Access Control,媒体访问控制,或称为物理地址、硬件地址,用来定义网络设备的位置),没有网卡以其他方式获得。(3) Globally unique IEEE machine identification number (IEEE, the full name is Institute of Electrical and Electronics Engineers, Institute of Electrical and Electronics Engineers), if there is a network card, obtained from the MAC address of the network card (MAC, Media Access Control or Medium Access Control, media Access control, or physical address, hardware address, is used to define the location of a network device. No network card is otherwise available.
步骤220、根据UUID预先指定位置上的值,按照预设获取方式,在UUID的首位和末位之间获取插入位置。Step 220: Pre-specify the value according to the UUID, and obtain the insertion position between the first position and the last position of the UUID according to the preset acquisition manner.
具体地,计算机设备根据接收到的生成UUID的指令生成UUID,根据UUID预先指定位置上的值,按照预设获取方式,在UUID的首位和末位之间获取一个插入位置,确保识别码的首位的值和末位的值不变。之所以在UUID的首位和末位之间获取一个插入位置,是因为不知道插入位置的获取方式,就不能确定插入位置,进而不能获取插入内容,从而保证识别码不被破解或篡改,从而保证UUID的安全性。Specifically, the computer device generates a UUID according to the received instruction for generating the UUID, pre-specifies the value according to the UUID, and obtains an insertion position between the first and last positions of the UUID according to the preset acquisition manner to ensure the first position of the identification code. The value of the last bit and the value of the last bit are unchanged. The reason why an insertion position is obtained between the first and last positions of the UUID is that the insertion position cannot be determined because the insertion position is not known, and the insertion content cannot be obtained, thereby ensuring that the identification code is not cracked or tampered, thereby ensuring that the identification code is not cracked or falsified. UUID security.
步骤240、在插入位置插入验证UUID的预设内容,生成新的识别码,预设内容按照第一预设规则生成。Step 240: Insert a preset content of the verification UUID at the insertion position, generate a new identification code, and generate the preset content according to the first preset rule.
具体地,第一预设规则至少包括以下内容的一项:生成验证UUID时效性的当前时间片段的生成方式,生成验证UUID真实性的校验位(或者称为校验码)的生成方式。Specifically, the first preset rule includes at least one of the following: generating a manner of generating a current time segment for verifying the validity of the UUID, and generating a check mode for verifying the authenticity of the UUID (or a check code).
计算机设备在UUID获取插入位置,在插入位置插入预设内容,生成新的识别码,由于未插入预设内容时的原识别码具有唯一性,则新生成的识别码在原来唯一的基础上也具有唯一性,从而在保证新生成的识别码唯一的基础上,根据新识别码的插入内容,实现对新识别码的校验,且新识别码的生成方法简单,计算复杂度低,具有高效性。The computer device acquires the insertion position in the UUID, inserts the preset content in the insertion position, and generates a new identification code. Since the original identification code when the preset content is not inserted is unique, the newly generated identification code is also based on the original unique identifier. It is unique, so as to ensure the uniqueness of the newly generated identification code, according to the insertion content of the new identification code, the verification of the new identification code is realized, and the generation method of the new identification code is simple, the calculation complexity is low, and the efficiency is high. Sex.
进一步的,校验新生成的识别码时,采取的步骤如下:Further, when verifying the newly generated identification code, the steps taken are as follows:
(1)根据生成新识别码的首位上的首位值和末位上的末位值,及插入位置的预设获取方式,确定插入位置。(1) The insertion position is determined according to the first bit value on the first bit of the new identification code and the last bit value on the last bit, and the preset acquisition mode of the insertion position.
具体地,由于插入的预设内容在识别码的首位和末位的中间,则插入预设内容后新生成的识别码的首位和末位相对于原来的识别码的首位和末位不变,根据新生成的识别码的首位的首位值和末位的末位值,及插入位置的预设获取方式,找到插入位置。Specifically, since the inserted preset content is in the middle of the first bit and the last bit of the identification code, the first bit and the last bit of the newly generated identification code after the preset content is inserted are unchanged with respect to the first bit and the last bit of the original identifier, according to The first bit value of the first bit of the newly generated identification code and the last bit value of the last bit, and the preset acquisition mode of the insertion position, find the insertion position.
(2)根据新生成的新UUID长度-32(32为原UUID长度)获取插入的预设内容的插入长度,从获取的插入位置根据插入长度,截取出插入的预设内容。(2) Acquiring the insertion length of the inserted preset content according to the newly generated new UUID length -32 (32 is the original UUID length), and extracting the inserted preset content according to the insertion length from the acquired insertion position.
(3)根据插入的预设内容,校验新生成的识别码。(3) Verify the newly generated identification code based on the inserted preset content.
具体地,比如,若插入内容为生成识别码的当前时间片段和校验位,则可以通过生成识别码的当前时间片段和计算机设备的当前时间比较,以及计算机设备上设置的识别码的有效存续时间,验证识别码的时效性,也就是验证识别码是否还处于有效时间内。比如,若计算机设备上设置的识别码的有效存续时间为5分钟,则比较识别码的生成时间到计算机设备上的当前时间是否超过了5分钟,若未超过5分钟,识别码处于有效时间内,识别码为有效;若超过5分钟,识别码已经超过有效时间,则识别码失效。Specifically, for example, if the insertion content is the current time segment and the check digit of the generated identification code, the current time segment of the generated identification code and the current time of the computer device can be compared, and the effective survival of the identification code set on the computer device can be performed. Time, verify the timeliness of the identification code, that is, verify that the identification code is still within the valid time. For example, if the effective duration of the identification code set on the computer device is 5 minutes, then the comparison time of the generation of the identification code to the current time on the computer device exceeds 5 minutes. If the identification code is less than 5 minutes, the identification code is within the valid time. The identification code is valid; if the identification code has exceeded the valid time for more than 5 minutes, the identification code is invalid.
还可以通过校验位验证识别码的真实性,也就是根据校验位上采取的不同的校验方式的校验规则,验证校验位是否存在一致性,若校验位存在一致性性,表明识别码是真实的,若校验位存在不一致性,表明识别码被篡改或破解了。比如,若校验位采用奇偶校验,根据被传输的一组二进制代码的数位中“1”的个数是奇数或偶数来进行校验。采用奇数的称为奇校验,反之,称为偶校验。采用何种校验是事先规定好的。通常专门设置一个奇偶校验位,用它使这组代码中“1”的个数为奇数或偶数。若用奇校验,则当接收端收到这组代码时,校验“1”的个数是否为奇数,从而确定传输代码的正确性。It is also possible to verify the authenticity of the identification code by the check digit, that is, according to the verification rule of different verification methods adopted on the check digit, verify whether the check digit has consistency, and if the check digit has consistency, Indicates that the identification code is authentic. If there is an inconsistency in the check digit, it indicates that the identification code has been tampered with or cracked. For example, if the parity bit uses parity, the number of "1"s in the digits of the transmitted binary code is odd or even. The odd number is called odd parity, and the other is called even parity. Which calibration is used is prescribed in advance. Usually a parity bit is set specifically, which is used to make the number of "1"s in this group of codes odd or even. If odd parity is used, when the receiving end receives the set of codes, it is checked whether the number of "1" is an odd number, thereby determining the correctness of the transmission code.
相对于根据统一规则生成的原UUID,根据插入内容能够实现对新生成的识别码的简单校验。A simple verification of the newly generated identification code can be implemented according to the inserted content with respect to the original UUID generated according to the unified rule.
在一个实施例中,UUID预先指定位置上的值包括以下至少一项:UUID的首位上的首位值,UUID的末位上的末位值。In one embodiment, the UUID pre-specified value includes at least one of the following: a first value on the first bit of the UUID and a last value on the last bit of the UUID.
具体地,计算机设备根据接收到产生识别码UUID的指令,计算机设备通过调用生成UUID的API接口,生成识别码UUID,计算机设备生成的识别码UUID为32位的16进制随机数,如:406fb0188d884cc3aff84b0f7ea2953c。计算机设备判断识别码UUID的每一位的位置范围为0~31位,每一位上的值为0~15之间的值,根据计算机的规则,识别码UUID的 每个位置上的值和十进制的对应关系如下表格1所示:Specifically, the computer device generates an identification code UUID by calling an API interface that generates the UUID according to the instruction to generate the identification code UUID, and the identification code UUID generated by the computer device is a 32-bit hexadecimal random number, such as: 406fb0188d884cc3aff84b0f7ea2953c . The computer device determines that the position range of each bit of the identification code UUID is 0 to 31 bits, and the value on each bit is a value between 0 and 15, according to the rules of the computer, the value at each position of the identification code UUID and The decimal correspondence is shown in Table 1 below:
表格1Table 1
十进制Decimal 00 11 22 33 44 55 66 77 88 99 1010 1111 1212 1313 1414 1515
十六进制Hexadecimal 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff
根据上述表格1可知,上述识别码:406fb0188d884cc3aff84b0f7ea2953c,首位是4,末位是c,则识别码“406fb0188d884cc3aff84b0f7ea2953c”首位上的首位值为4,末位上的末位值为12。According to the above Table 1, the identification code: 406fb0188d884cc3aff84b0f7ea2953c, the first digit is 4, and the last digit is c, the first digit of the first digit of the identification code "406fb0188d884cc3aff84b0f7ea2953c" is 4, and the last digit of the last digit is 12.
在一个实施例中,根据UUID预先指定位置上的值,按照预设获取方式,在UUID的首位和末位之间获取插入位置的步骤包括:根据首位值、末位值或者首位值与末位值,获取正整数;按照UUID从左到右的顺序,或者按照UUID从右到左的顺序,根据正整数,在UUID的首位和末位之间获取插入位置。In an embodiment, according to the UUID pre-specifying the value in the position, the step of obtaining the insertion position between the first bit and the last bit of the UUID according to the preset acquisition manner includes: according to the first bit value, the last bit value or the first bit value and the last bit position Value, get a positive integer; get the insertion position between the first and last digits of the UUID according to the positive integer, in order from left to right, or from UYID to right-to-left.
具体地,计算机设备获取插入位置,插入位置根据UUID预先指定位置上的值及插入位置的预设获取方式获取,可以是根据首位值获取的正整数,也可以是根据末位值获取的正整数,还可以是根据首位值与末位值结合起来获取正整数。比如上述识别码:406fb0188d884cc3aff84b0f7ea2953c,可见,识别码的首位的首位值为4,末位的末位值为c,16进制c对应的十进制为12,计算机设备根据识别码首位值4,及末位值12,根据UUID预先指定位置上的值,及按照预设插入位置的获取方式,获取一个插入位置,获取的插入位置可以为以下情形中的一种:Specifically, the computer device obtains the insertion position, and the insertion position is obtained according to the preset value of the pre-specified position and the insertion position of the UUID, and may be a positive integer obtained according to the first value or a positive integer obtained according to the last value. It is also possible to combine a first value with a last value to obtain a positive integer. For example, the above identification code: 406fb0188d884cc3aff84b0f7ea2953c, it can be seen that the first digit of the first digit of the identification code is 4, the last digit of the last digit is c, the decimal of the hexadecimal c is 12, and the computer device according to the first value of the identification code 4, and the last digit The value 12 is obtained by pre-specifying the value according to the UUID and acquiring the insertion position according to the preset insertion position. The obtained insertion position may be one of the following situations:
(1)根据UUID预先指定位置上的值,插入位置的获取方式为按照识别码从左到右的顺序获取插入位置。(1) The value at the position is pre-specified according to the UUID, and the insertion position is obtained by acquiring the insertion position in order from the left to the right according to the identification code.
若插入位置为识别码的首位值,由于识别码的首位值为4,则插入位置为识别码从左到右的第4个位置,即识别码中从左到右的第一个f后;同样,若插入位置为识别码的末位值,则插入位置为识别码从左到右的第12个位置,即识别码中从左到右的第4个8后。If the insertion position is the first value of the identification code, since the first bit value of the identification code is 4, the insertion position is the 4th position of the identification code from left to right, that is, the first f after the identification code from left to right; Similarly, if the insertion position is the last value of the identification code, the insertion position is the 12th position of the identification code from left to right, that is, the 4th 8th from left to right in the identification code.
(2)根据UUID预先指定位置上的值,插入位置的获取方式为按照识别码从右到左的顺序获取插入位置。(2) The value of the insertion position is obtained in advance according to the UUID, and the insertion position is obtained by acquiring the insertion position in order from right to left according to the identification code.
若插入位置为识别码的首位值,由于识别码的首位值为4,则插入位置为识别码从右到左的第4个位置,即识别码中从右到左第一个9前面的位置;同样,若插入位置为识别码的末位值,则插入位置为识别码的第12个位置,即识别码中从右到左第1个4的前面。If the insertion position is the first value of the identification code, since the first bit value of the identification code is 4, the insertion position is the 4th position of the identification code from right to left, that is, the position from the right to the left of the first 9 in the identification code. Similarly, if the insertion position is the last value of the identification code, the insertion position is the 12th position of the identification code, that is, the front of the first 4 from right to left in the identification code.
可见,通过上述方式,可以实现插入位置的灵活设置,进一步确保识别码的安全性。It can be seen that, through the above manner, flexible setting of the insertion position can be realized, and the security of the identification code is further ensured.
在一个实施例中,根据首位值与末位值,获取正整数的步骤包括:In one embodiment, the step of obtaining a positive integer according to the first value and the last value includes:
根据UUID的首位上的首位值和末位上的末位值的和,获取正整数。A positive integer is obtained based on the sum of the first value on the first digit of the UUID and the last value on the last digit.
具体地,计算机设备根据UUID的首位上的首位值和末位上的末位值的和,获取正整数,根据获取的正整数,按照插入位置的预设获取方式,在UUID的首位和末位之间获取插入位置。Specifically, the computer device obtains a positive integer according to the sum of the first bit value on the first bit of the UUID and the last bit value on the last bit, and according to the obtained positive integer, according to the preset acquisition manner of the insertion position, the first and last positions of the UUID Get the insertion position between.
以上述识别码:406fb0188d884cc3aff84b0f7ea2953c为例,计算机设备可以以识别码的首 位值4和末位值12之和16,按照识别码从左到右的顺序,以识别码第16个位置作为预设内容的插入位置,也就是在识别码:406fb0188d884cc3 aff84b0f7ea2953c的第16个位置,也就是空格处插入预设内容。Taking the above identification code: 406fb0188d884cc3aff84b0f7ea2953c as an example, the computer device may use the sum of the first value 4 and the last value 12 of the identification code, in the order of the identification code from left to right, with the 16th position of the identification code as the preset content. The insertion position, that is, the preset content is inserted in the 16th position of the identification code: 406fb0188d884cc3 aff84b0f7ea2953c, that is, the space.
在一个实施例中,根据首位值与末位值,获取正整数的步骤包括:In one embodiment, the step of obtaining a positive integer according to the first value and the last value includes:
根据UUID的首位值和末位值的差的绝对值,获取正整数。A positive integer is obtained based on the absolute value of the difference between the first value and the last value of the UUID.
具体地,计算机设备根据UUID的首位上的首位值和末位上的末位值的差的绝对值,获取正整数,根据获取的正整数,按照插入位置的预设获取方式,在UUID的首位和末位之间获取插入位置。Specifically, the computer device obtains a positive integer according to the absolute value of the difference between the first bit value on the first bit of the UUID and the last bit value on the last bit, and according to the obtained positive integer, according to the preset acquisition mode of the insertion position, the first position of the UUID Get the insertion position between the last bit and the last bit.
以上述识别码:406fb0188d884cc3aff84b0f7ea2953c为例,计算机设备可以以识别码的首位值4和末位值12之差的绝对值8,按照识别码从左到右的顺序,以识别码第8个位置作为预设内容的插入位置,也就是在识别码:406fb018 8d884cc3aff84b0f7ea2953c的第8个位置,也就是空格处插入预设内容。Taking the above identification code: 406fb0188d884cc3aff84b0f7ea2953c as an example, the computer device may use the absolute value 8 of the difference between the first value 4 and the last value 12 of the identification code, in the order of the identification code from left to right, and the eighth position of the identification code as a pre- Set the insertion position of the content, that is, insert the preset content in the eighth position of the identification code: 406fb018 8d884cc3aff84b0f7ea2953c, that is, the space.
在一个实施例中,根据首位值、末位值或者首位值与末位值获取正整数的步骤包括:In one embodiment, the step of obtaining a positive integer based on the first value, the last value, or the first value and the last value includes:
根据首位值加n1,末位值加n2,首位值与末位值之和加1,或者首位值与末位值之差的绝对值加n3,获取正整数,其中,1≤n1≤16,1≤n2≤16,1≤n3≤16。According to the first value plus n1, the last value plus n2, the sum of the first value and the last value plus one, or the absolute value of the difference between the first value and the last value plus n3, obtain a positive integer, where 1 ≤ n1 ≤ 16, 1 ≤ n2 ≤ 16, 1 ≤ n3 ≤ 16.
具体地,计算机设备根据以下情形之一,来获取正整数,进一步根据正整数和插入位置的预设获取方式获取插入位置:Specifically, the computer device obtains a positive integer according to one of the following situations, and further acquires the insertion position according to a preset acquisition manner of the positive integer and the insertion position:
(1)根据首位值加n1,1≤n1≤16。由于UUID是32位的自然数,首位上的首位值最大为15,最小为0,为了保证插入位置在首位和末位之间,则首位值加n1,n1的取值范围只能是1≤n1≤16。(1) Add n1 according to the first value, 1 ≤ n1 ≤ 16. Since the UUID is a 32-bit natural number, the first value on the first digit is a maximum of 15 and the minimum is 0. To ensure that the insertion position is between the first and last digits, the first value is added to n1, and the range of n1 can only be 1≤n1. ≤16.
同理,末位值加n2,n2的取值范围只能是1≤n2≤16。Similarly, the last value plus n2, n2 can only be 1 ≤ n2 ≤ 16.
(2)为避免识别码的首位上的首位值与识别码的末位上的末位值的和为0,也就是,识别码的首位值与识别码的末位值均为0的情形,其和为0,和为0,意味着插入位置为识别码的首位,预设的插入内容在识别码的前面,这样的情形,识别码容易被识别,在识别码的首位值与识别码的末位值之和再加1,也就是(首位+末位)+1,范围1~31正好在识别码的首位和末位的中间,该插入方式能够保证首位和末位的数值不变,方便进行校验时确定插入位置,根据插入位置获取预设的插入内容。比如,以上述识别码:406fb0188d884cc3aff84b0f7ea2953c为例,则插入点位置为:406fb0188d884cc3a插入点ff84b0f7ea2953c。(2) In order to avoid the sum of the first bit value on the first bit of the identification code and the last bit value on the last bit of the identification code being 0, that is, the case where the first bit value of the identification code and the last bit value of the identification code are both 0, The sum is 0, and 0, which means that the insertion position is the first position of the identification code, and the preset insertion content is in front of the identification code. In this case, the identification code is easily recognized, and the first value of the identification code and the identification code are Add the sum of the last value, that is, (first + last) +1, the range 1 ~ 31 is just in the middle of the first and last digits of the identification code, the insertion method can ensure that the values of the first and last digits are unchanged. It is convenient to determine the insertion position when performing verification, and obtain the preset insertion content according to the insertion position. For example, taking the above identification code: 406fb0188d884cc3aff84b0f7ea2953c as an example, the insertion point position is: 406fb0188d884cc3a insertion point ff84b0f7ea2953c.
(3)若根据首位值与末位值之差的绝对值加n3,获取正整数。(3) If n3 is added according to the absolute value of the difference between the first value and the last value, a positive integer is obtained.
具体地,有以下两种情形:Specifically, there are two situations:
1)识别码的首位上的首位值与识别码的末位上的末位值的差的绝对值最小为0,也就是,识别码的首位上的首位值与识别码的末位上的末位值相同。1) The absolute value of the difference between the first bit value on the first bit of the identification code and the last bit value on the last bit of the identification code is 0, that is, the first bit value on the first bit of the identification code and the last bit on the last bit of the identification code The bit values are the same.
2)识别码的首位上的首位值与识别码的末位上的末位值的差的绝对值最大为15,也就是,识别码的首位上的首位值与识别码的末位上的末位值一个为0和一个为15。2) The absolute value of the difference between the first bit value on the first bit of the identification code and the last bit value on the last bit of the identification code is at most 15, that is, the first bit value on the first bit of the identification code and the last bit on the last bit of the identification code The bit values are one for 0 and one for 15.
差的绝对值为0,意味着插入位置为识别码的首位,预设的插入内容在识别码的前面, 差的绝对值为15,再有17个位置,则意味着插入位置为识别码的末位,预设的插入内容在识别码的后面面,无论插入位置在识别码的前面还是后面,这样的情形,识别码容易被识别,因此为了保证插入位置在UUID的首位和末位的中间,在识别码的首位上的首位值与识别码的末位上的末位值之差的绝对值上,再加n3,也就是|首位﹣末尾|+n3,为了保证获取的插入位置在UUID的首位和末位的中间,则n3的取值最大可以取16,最小为1,该插入方式能够保证首位和末位的数值不变,方便进行校验时确定插入位置,根据插入位置获取预设的插入内容。The absolute value of the difference is 0, which means that the insertion position is the first position of the identification code, the preset insertion content is in front of the identification code, the absolute value of the difference is 15, and there are 17 positions, which means that the insertion position is the identification code. At the last position, the preset insertion content is behind the identification code, regardless of whether the insertion position is in front of or behind the identification code. In this case, the identification code is easily recognized, so that the insertion position is in the middle of the first and last positions of the UUID. , in the absolute value of the difference between the first value of the first digit of the identification code and the last digit of the last digit of the identification code, plus n3, that is, the first position - the end | + n3, in order to ensure that the obtained insertion position is in the UUID In the middle of the first and last positions, the value of n3 can be up to 16 and the minimum is 1. This insertion mode can ensure that the values of the first and last digits are unchanged, which is convenient for determining the insertion position during verification, and obtaining the pre-position according to the insertion position. Set the insertion content.
比如,以上述识别码:406fb0188d884cc3aff84b0f7ea2953c为例,以n3取1为例,则插入点位置为:406fb0188插入点d884cc3a ff84b0f7ea2953c。For example, taking the above identification code: 406fb0188d884cc3aff84b0f7ea2953c as an example, taking n3 as an example, the insertion point position is: 406fb0188 insertion point d884cc3a ff84b0f7ea2953c.
在一个实施例中,在插入位置插入验证UUID的预设内容的步骤包括:In one embodiment, the step of inserting the preset content of the verification UUID at the insertion location comprises:
在插入位置插入至少以下一项内容:当前时间片段,校验位。Insert at least one of the following at the insertion position: current time segment, check digit.
具体地,其中,当前时间片段指在插入位置插入预设内容时,获取的时间戳的生成时间,由于是以一段数字表示,称之为当前时间片段。当前时间片段的获取方式可以为:以JavaScript为例,JavaScript用new Date().getTime()来获时间戳,获取的是十进制的以毫秒为单位的时间戳,十进制的时间戳去除高位前k位(离产生时间戳的生产时间较远的位,数值长期不变,去除后不影响生存时间的判定),再去除后3位(除以1000,从秒截取),转化成十六进制,得到当前时间片段。对于k的取值,以不影响定义的时间片段的有效性生存时间为准,比如生成一个十进制的时间戳为12345,假设定义的当前时间片段的生存时间为345,则12345+345=12690,也就是当前时间片段的有效性截止时间为12690,12345与12690相比,去除12345的高位,也就是离生产时间较远的与12690共有的位数12,不影响对生存时间有效性的判断,则去掉12345的高位12,剩余位数345,则十进制的时间戳去除高位前k位,是指去除十进制的时间戳12345的高位前2位12。Specifically, the current time segment refers to a time when the time stamp is acquired when the preset content is inserted at the insertion position, and is represented by a one-digit number, which is called a current time segment. The current time segment can be obtained by taking JavaScript as an example. JavaScript uses new Date().getTime() to get the timestamp, and obtains the decimal timestamp in milliseconds. The decimal timestamp removes the high-order k. Bit (the bit farther from the production time when the time stamp is generated, the value is unchanged for a long time, and the survival time is not affected after the removal), and then the last 3 bits are removed (divided by 1000, intercepted from the second), converted into hexadecimal , get the current time segment. For the value of k, the validity time of the time segment is not affected, for example, generating a decimal timestamp of 12345, assuming that the defined current time segment has a lifetime of 345, then 12345+345=12690, That is, the validity time limit of the current time segment is 12690. Compared with 12690, 12345 removes the high level of 12345, that is, the number of bits shared with 12690 far from the production time, which does not affect the judgment of the validity of the survival time. Then, the high bit 12 of 12345 is removed, and the remaining number of bits is 345. The decimal time stamp removes the upper k bits of the high order, which means that the first two bits 12 of the high order of the decimal time stamp 12345 are removed.
如果以PHP(是英文超文本预处理语言Hypertext Preprocessor的缩写)为例,获取的时间戳是以秒为单位的时间戳,则直接转化成16进制,得到当前时间片段,通过不同方式获取的时间戳,根据时间单位毫秒、秒等单位之间的关系换算成需要的时间单位,转换成16进制,即可得到当前的时间片段。其中,时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。If PHP (which is the abbreviation of Hypertext Preprocessor in English), the obtained timestamp is a timestamp in seconds, which is directly converted into hexadecimal, and the current time segment is obtained by different methods. The timestamp is converted into the required time unit according to the relationship between the unit of time unit milliseconds, seconds, etc., and converted into hexadecimal to obtain the current time segment. Among them, the time stamp refers to the total number of seconds from 01:00 to 00:00 on January 01, 1970 (Beijing time, January 01, 1970, 08:00:00).
在一个实施例中,根据实际需要对时间的敏感度,除了上述用秒为时间单位获取当前时间片段,还可以以分钟为时间单位来获取时间片段。比如,仍以JavaScript为例,由于终端生成的时间戳默认是以毫秒计算的,由于秒和毫秒之间是1000的倍数关系,所以以秒来获取时间片段的话,是去除后3位,除以1000;如果是以分钟,则是除以60×1000。In one embodiment, according to the actual need for time sensitivity, in addition to the above-mentioned time segment for acquiring the current time segment in seconds, the time segment may also be acquired in units of minutes. For example, JavaScript is still used as an example. Since the timestamp generated by the terminal is calculated in milliseconds by default, since the second and milliseconds are multiples of 1000, if the time segment is acquired in seconds, the last 3 bits are removed, divided by 1000; if it is in minutes, it is divided by 60×1000.
在一个实施例中,时间片段的设置,还可以通过将时间片段的顺序颠倒,比如从正到反,来定制时间片段,比如按上述算法获得的时间片段是12345,则可将12345顺序反过来,通过54321来表示时间片段,从而获得时间片段的定制。In one embodiment, the setting of the time segment can also be customized by reversing the order of the time segments, such as from front to back. For example, the time segment obtained by the above algorithm is 12345, and the sequence of 12345 can be reversed. The time segment is represented by 54321, thereby obtaining the customization of the time segment.
可见,通过上述方式获取当前时间片段的方式是多种多样的,从而实现当前时间片段定制的灵活性,进一步确保识别码的安全。It can be seen that the manner of obtaining the current time segment in the above manner is various, thereby realizing the flexibility of the current time segment customization, and further ensuring the security of the identification code.
在一个实施例中,根据实际情形对识别码时效性需求,以当前时间片段为基准,可通过服务器端定义识别码的生存时间,识别码的生存时间,也就是指识别码的有效时间,在生存时间内,识别码处于有效状态,超过生存时间,识别码处于失效状态,比如定义识别码的生存时间为5分钟,则从识别码生成的时间算起,在5分钟内,识别码有效,超过5分钟,识别码失效。服务器校验识别码时,服务器根据生成识别码的当前时间片段表示的识别码的生成时间与当前时间比较,判断识别码在定义的生存时间内,识别码有效,若服务器判断识别码超过了识别码定义的生存时间,则识别码失效。也就是识别码的生存时间是可以通过服务器根据需要定制的,例如5分钟、3分钟等,在生存时间内,则UUID有效,超过生存时间,则UUID失效,从而验证UUID的时效性,满足实际需要中对识别码有时效性要求的情形,比如扫码登录、扫码支付等,为了保证账户的安全,识别码需要满足一定的时效性要求,扫码登录,设置识别码为2分钟,在2分钟内,识别码有效,超过2分钟,识别码自动失效。In an embodiment, according to the actual situation, the time-sensitive requirement of the identification code is based on the current time segment, and the survival time of the identification code can be defined by the server, and the survival time of the identification code, that is, the effective time of the identification code, During the survival time, the identification code is in a valid state, exceeding the survival time, and the identification code is in a failure state. For example, if the survival time of the identification code is 5 minutes, the identification code is valid within 5 minutes from the time when the identification code is generated. The identification code is invalid for more than 5 minutes. When the server verifies the identification code, the server compares the generation time of the identification code represented by the current time segment of the generated identification code with the current time, and determines that the identification code is valid within the defined survival time, and if the server determines that the identification code exceeds the identification If the code defines the lifetime, the identifier will be invalid. That is, the survival time of the identification code can be customized according to the needs of the server, for example, 5 minutes, 3 minutes, etc. In the survival time, the UUID is valid, and the UUID is invalid after the survival time is exceeded, thereby verifying the timeliness of the UUID and satisfying the actual situation. In the case of need for the time-sensitive requirements of the identification code, such as scan code registration, scan code payment, etc., in order to ensure the security of the account, the identification code needs to meet certain timeliness requirements, scan code registration, set the identification code to 2 minutes, in Within 2 minutes, the identification code is valid. If it is more than 2 minutes, the identification code will automatically expire.
其中,校验位为奇偶校验、CRC校验、和校验或者MD5校验等。Among them, the check digit is parity, CRC check, and check or MD5 check.
其中,奇偶校验(Parity Check)是一种校验代码传输正确性的方法。根据被传输的一组二进制代码的数位中“1”的个数是奇数或偶数来进行校验。采用奇数的称为奇校验,反之,称为偶校验。采用何种校验是事先规定好的。通常专门设置一个奇偶校验位,用它使这组代码中“1”的个数为奇数或偶数。若用奇校验,则当接收端收到这组代码时,校验“1”的个数是否为奇数,从而确定传输代码的正确性。Among them, Parity Check is a method to verify the correctness of code transmission. The check is performed based on whether the number of "1"s in the digits of the transmitted binary code is odd or even. The odd number is called odd parity, and the other is called even parity. Which calibration is used is prescribed in advance. Usually a parity bit is set specifically, which is used to make the number of "1"s in this group of codes odd or even. If odd parity is used, when the receiving end receives the set of codes, it is checked whether the number of "1" is an odd number, thereby determining the correctness of the transmission code.
CRC即循环冗余校验码(Cyclic Redundancy Check):是数据通信领域中最常用的一种查错校验码,其特征是信息字段和校验字段的长度可以任意选定。循环冗余检查(CRC)是一种数据传输检错功能,对数据进行多项式计算,并将得到的结果附在帧的后面,接收设备也执行类似的算法,以保证数据传输的正确性和完整性。CRC is the Cyclic Redundancy Check (Cyclic Redundancy Check): It is the most commonly used error checking code in the field of data communication. Its characteristic is that the length of the information field and the check field can be arbitrarily selected. Cyclic Redundancy Check (CRC) is a data transmission error detection function that performs polynomial calculation on data and attaches the result to the back of the frame. The receiving device also performs a similar algorithm to ensure the correctness and completeness of the data transmission. Sex.
和校验是指校验一组数据项的和是否正确。通常是以十六进制为数制表示的形式。如果校验和的数值超过十六进制的FF,也就是255。And check is to verify that the sum of a set of data items is correct. Usually expressed in hexadecimal notation. If the value of the checksum exceeds the hexadecimal FF, it is 255.
MD5的实际应用是对一段Message(字节串)产生fingerprint(指纹),可以防止被篡改。The practical application of MD5 is to generate a fingerprint for a piece of Message (byte string) to prevent tampering.
在一个实施例中,校验位由当前时间片段根据第二预设规则获取。In one embodiment, the check digit is acquired by the current time segment according to a second preset rule.
具体地,第二预设规则为校验位的获取方式。校验位的获取方式为:(当前时间片段后k位+插入位,k≥1)%16 n,若校验位取1位时,n为1,也就是16 n=16 1=16,比如校验位取1位时,校验位的值可采取:(当前时间片段后3位+插入位)%16。其中,当前时间片段后k位中的当前时间片段,可以是以十六进制表示的当前时间片段,也可以是以十进制表示的当前时间片段,从而进一步实现校验位获取方式的灵活多样性,根据当前时间片段的唯一性,从而获取的校验位也是唯一的,根据校验位和当前时间片段是否对应,从而校验识别码的真实性。 Specifically, the second preset rule is a manner of acquiring a check digit. The check bit is obtained by: (the current time segment is followed by k bit + insert bit, k ≥ 1)% 16 n , if the check bit takes 1 bit, n is 1, that is, 16 n = 16 1 = 16, For example, when the parity bit takes 1 bit, the value of the parity bit can take: (3 bits after the current time segment + insertion bit) %16. The current time segment in the k-bit after the current time segment may be a current time segment expressed in hexadecimal or a current time segment expressed in decimal, thereby further implementing flexible diversity of the check bit acquisition manner. According to the uniqueness of the current time segment, the obtained check digit is also unique, and the authenticity of the identifier is verified according to whether the check digit corresponds to the current time segment.
同样,若校验位为2位时,n取2,也就是16 n=16 2,若校验位为3位时,16 n=16 3,校验位为n位时,为16 n,因此,采取这种方式获取的校验位,校验覆盖插入位与生存时间相关的当前时间片段,校验规则简单,校验位也是可以灵活设置的。 Similarly, if the parity bit is 2 bits, n takes 2, which is 16 n = 16 2 . If the parity bit is 3 bits, 16 n = 16 3 , and when the parity bit is n bits, it is 16 n . Therefore, the check bit obtained in this way is verified, and the current time segment related to the survival time is covered by the overlay insertion bit, the verification rule is simple, and the check bit can also be flexibly set.
具体地,在插入位置插入当前时间片段,根据当前时间片段表示的时间与服务器判断识 别码时的当时时间进行比较,根据时间的差值是否超过服务器定义的识别码的生存时间,判断识别码的时效性,通过在插入位置插入校验位,用来设置识别码的真实性,如果在位置同时插入当前时间片段和校验位,则可以同时验证识别码的时效性和真实性。Specifically, the current time segment is inserted at the insertion position, and the time represented by the current time segment is compared with the current time when the server determines the identification code, and the identification code is determined according to whether the difference of the time exceeds the survival time of the server-defined identification code. Timeliness, by inserting a check digit at the insertion position, it is used to set the authenticity of the identification code. If the current time segment and the check digit are simultaneously inserted in the position, the timeliness and authenticity of the identification code can be verified at the same time.
比如,以上述识别码:406fb0188d884cc3aff84b0f7ea2953c为例,插入位置为(首位值+末位值)+1,则插入位置为:4+c(十进制的12)+1=17,也就是插入位置为识别码的第17位,插入内容:当前时间片段+校验位。其中,由于识别码采取十六进制,识别码每个位置上的值最大为15,因此(首位值+末位值)+1获取的插入位置在识别码的首位和末位的中间。For example, taking the above identification code: 406fb0188d884cc3aff84b0f7ea2953c as an example, the insertion position is (first value + last value) +1, then the insertion position is: 4+c (12 in decimal) +1=17, that is, the insertion position is the identification code. 17th place, insert content: current time segment + check digit. Wherein, since the identification code adopts hexadecimal, the value at each position of the identification code is at most 15, so the insertion position obtained by (first value + last value) +1 is in the middle of the first and last bits of the identification code.
其中,当前时间片段:可以从秒截取,去除高位前k位(离生产时间较远的位),转十六进制进制,比如获取的十六进制的当前时间片段为:1d8b6f84。同时,可根据时效性需求,比如通过服务器设置识别码的生存时间为3分钟。Among them, the current time segment: can be intercepted from the second, remove the upper k position (bit far from the production time), and turn to hexadecimal, for example, the current time segment of the obtained hexadecimal is: 1d8b6f84. At the same time, according to the timeliness requirements, for example, the survival time of the identifier set by the server is 3 minutes.
校验位:1位,值为:(当前时间片段后3位+插入位)%16,比如,以十六进制表示当前时间片段,以当前时间片段的10进制表示方式的后3位获取校验位,则根据十六进制的当前时间片段为:1d8b6f84的十进制表示方式的后3位获取的校验位为5。Check digit: 1 bit, the value is: (3 bits after the current time segment + insert bit) %16, for example, the current time segment is expressed in hexadecimal, the last 3 digits of the current time segment in decimal notation To obtain the check digit, the current time segment according to hexadecimal is: the check digit of the last 3 digits of the decimal representation of 1d8b6f84 is 5.
新识别码生成结果如下:The new identifier generation result is as follows:
406fb0188d884cc3a            ff84b0f7ea2953c;406fb0188d884cc3a ff84b0f7ea2953c;
406fb0188d884cc3a 1d8b6f84 5 ff84b0f7ea2953c。406fb0188d884cc3a 1d8b6f84 5 ff84b0f7ea2953c.
对上述新生成的识别码,服务器进行新生成的识别码校验时,可采取如下方式:For the newly generated identification code, when the server performs the newly generated identification code verification, the following manner may be adopted:
1)、根据首位值4和末位值c,找到插入位置第17位,根据新UUID长度-32(原UUID长度),获取插入长度9位,从插入位置截取出插入内容1d8b6f84 5。1) According to the first value 4 and the last value c, the 17th position of the insertion position is found, and according to the new UUID length -32 (the original UUID length), the insertion length 9 bits is acquired, and the insertion content 1d8b6f84 5 is intercepted from the insertion position.
2)、取插入内容最后一位5用作校验,检验UUID的真实性。2), take the last bit of the inserted content 5 for verification, verify the authenticity of the UUID.
3)、取插入内容的其余片段与当前时间做比较,查看识别码是否超过服务器定义的生存时间(如3分钟),检验UUID的时效性。3), take the rest of the inserted content to compare with the current time, check whether the identification code exceeds the server-defined survival time (such as 3 minutes), and check the timeliness of the UUID.
因此,通过上述方式生成的识别码可校验识别码的真实性和时效性。Therefore, the identification code generated by the above manner can verify the authenticity and timeliness of the identification code.
在一个实施例中,根据上述方式新生成的识别码也是唯一的,可以根据反证法来进行验证:In one embodiment, the newly generated identification code according to the above manner is also unique and can be verified according to the counter-evidence method:
前提:原UUID唯一Prerequisite: The original UUID is unique
假设:存在2个完全相同的UUID,u1和u2;Assume that there are 2 identical UUIDs, u1 and u2;
证明:prove:
u1与u2首尾相同,则插入点一致。U1 is the same as the end of u2, and the insertion point is the same.
u1与u2长度相同,则插入长度一致。If u1 and u2 are the same length, the insertion length is the same.
删除u1与u2插入内容,可得u1与u2仍然相等。Delete the contents of u1 and u2, and u1 and u2 are still equal.
因此,违反了原UUID唯一性原则。因此,假设不成立,新UUID唯一。Therefore, the original UUID uniqueness principle is violated. Therefore, the assumption is not true and the new UUID is unique.
在保持了新生成的UUID唯一性的前提下,改进后新UUID有如下有益效果:Under the premise of maintaining the uniqueness of the newly generated UUID, the improved new UUID has the following beneficial effects:
1)、新UUID的生成方式,可验证新UUID是可靠的、真实的;1) The new UUID is generated to verify that the new UUID is reliable and authentic;
2)、插入时间片段,并纳入校验,可为新UUID设定有效的存活时间;2) Insert a time segment and include a check to set a valid survival time for the new UUID;
3)、插入的时间片段、校验字段以及其生存周期皆可定制,因此,新UUID生成规则具 有多样性;3) The inserted time segment, check field and its life cycle can be customized. Therefore, the new UUID generation rules are diverse;
4)、生成与校验算法复杂度较低,耗时短。4) The generation and verification algorithm has low complexity and short time.
在一个实施例中,在插入位置插入当前时间片段和校验位,其中,当前时间片段在前,校验位在后,或者校验位在前,当前时间片段在后。In one embodiment, the current time segment and the check digit are inserted at the insertion position, wherein the current time segment is first, the parity bit is after, or the parity bit is first, and the current time segment is after.
具体地,当在识别码的插入位置同时插入当前时间片段和校验位时,当前时间片段和校验位的顺序可以设置为当前时间片段在前,也可以设置为校验位在前。Specifically, when the current time segment and the check bit are simultaneously inserted at the insertion position of the identification code, the order of the current time segment and the check bit may be set to the current time segment first, or may be set to the check bit first.
识别码在实际应用中,比如做一个二维码扫码登录功能开发时,需要一个唯一的字段代表二维码,通过一个唯一的字段UUID代表二维码,通过UUID的唯一性验证真实性,通过UUID的时效性来保证二维码的有效与失效,当验证二维码真实且有效时,允许用户通过扫码登录账户,从而保证登录账户的安全。In the actual application, for example, when developing a QR code scan code registration function, a unique field is required to represent the two-dimensional code, and a unique field UUID is used to represent the two-dimensional code, and the authenticity is verified by the uniqueness of the UUID. The validity and failure of the two-dimensional code are ensured by the timeliness of the UUID. When verifying that the two-dimensional code is true and valid, the user is allowed to log in to the account by scanning the code, thereby ensuring the security of the login account.
上述识别码的生成方法,通过若接收到产生识别码UUID的指令,产生UUID;根据UUID预先指定位置上的值,在UUID的首位和末位之间获取插入位置;在插入位置插入验证UUID的预设内容,生成新的识别码,通过插入的预设内容实现对识别码的简单校验。The method for generating the identification code generates a UUID by receiving an instruction to generate the identification code UUID; pre-specifying the value according to the UUID, obtaining an insertion position between the first and last positions of the UUID; and inserting the verification UUID at the insertion position The preset content is generated, a new identification code is generated, and the simple verification of the identification code is realized by the inserted preset content.
请参阅图3,本申请实施例还提供一种识别码的生成装置,该装置包括:Referring to FIG. 3, an embodiment of the present application further provides an apparatus for generating an identifier, where the apparatus includes:
产生模块30,用于若接收到产生识别码UUID的指令,产生UUID。The generating module 30 is configured to generate a UUID if receiving an instruction to generate the identification code UUID.
具体地,计算机设备接收到产生识别码UUID的指令,计算机设备通过调用计算机设备上的生成UUID的API接口,生成一个识别码UUID,UUID为32位的16进制随机数,转化为二进制,也就是16字节128位的二进制数。Specifically, the computer device receives the instruction for generating the identifier UUID, and the computer device generates an identifier UUID by calling an API interface for generating the UUID on the computer device, and the UUID is a 32-bit hexadecimal random number, which is converted into a binary, It is a 16-byte 128-bit binary number.
UUID的生成方式可以为:The UUID can be generated as follows:
Java生成代码:UUID.randomUUID().toString().replace("-",""),生成一个32位的16进制随机数,如:406fb0188d884cc3aff84b0f7ea2953c。Java generated code: UUID.randomUUID().toString().replace("-",""), generates a 32-bit hexadecimal random number, such as: 406fb0188d884cc3aff84b0f7ea2953c.
获取模块32,用于根据UUID预先指定位置上的值,按照预设获取方式,在UUID的首位和末位之间获取插入位置。The obtaining module 32 is configured to obtain the insertion position between the first position and the last position of the UUID according to the preset acquisition manner according to the UUID.
具体地,计算机设备根据接收到的生成UUID的指令生成UUID,根据UUID预先指定位置上的值,按照预设获取方式,在UUID的首位和末位之间获取一个插入位置,确保识别码的首位的值和末位的值不变。之所以在UUID的首位和末位之间获取一个插入位置,是因为不知道插入位置的获取方式,就不能确定插入位置,进而不能获取插入内容,从而保证识别码不被破解或篡改,从而保证UUID的安全性。Specifically, the computer device generates a UUID according to the received instruction for generating the UUID, pre-specifies the value according to the UUID, and obtains an insertion position between the first and last positions of the UUID according to the preset acquisition manner to ensure the first position of the identification code. The value of the last bit and the value of the last bit are unchanged. The reason why an insertion position is obtained between the first and last positions of the UUID is that the insertion position cannot be determined because the insertion position is not known, and the insertion content cannot be obtained, thereby ensuring that the identification code is not cracked or tampered, thereby ensuring that the identification code is not cracked or falsified. UUID security.
生成模块34,用于在插入位置插入验证UUID的预设内容,生成新的识别码,预设内容按照第一预设规则生成。The generating module 34 is configured to insert a preset content of the verification UUID at the insertion position, generate a new identification code, and generate the preset content according to the first preset rule.
具体地,第一预设规则至少包括以下内容的一项:生成验证UUID时效性的当前时间片段的生成方式,生成验证UUID真实性的校验位(或者称为校验码)的生成方式。Specifically, the first preset rule includes at least one of the following: generating a manner of generating a current time segment for verifying the validity of the UUID, and generating a check mode for verifying the authenticity of the UUID (or a check code).
计算机设备在UUID获取插入位置,在插入位置插入预设内容,生成新的识别码,由于未插入预设内容时的原识别码具有唯一性,则新生成的识别码在原来唯一的基础上也具有唯一性,从而在保证新生成的识别码唯一的基础上,根据新识别码的插入内容,实现对新识别码的校验,且新识别码的生成方法简单,计算复杂度低,具有高效性。The computer device acquires the insertion position in the UUID, inserts the preset content in the insertion position, and generates a new identification code. Since the original identification code when the preset content is not inserted is unique, the newly generated identification code is also based on the original unique identifier. It is unique, so as to ensure the uniqueness of the newly generated identification code, according to the insertion content of the new identification code, the verification of the new identification code is realized, and the generation method of the new identification code is simple, the calculation complexity is low, and the efficiency is high. Sex.
比如,若插入内容为生成识别码的当前时间片段和校验位,则可以通过生成识别码的当前时间片段和计算机设备的当前时间比较,以及计算机设备上设置的识别码的有效存续时间,验证识别码的时效性,也就是验证识别码是否还处于有效时间内。比如,若计算机设备上设置的识别码的有效存续时间为5分钟,则比较识别码的生成时间到计算机设备上的当前时间是否超过了5分钟,若未超过5分钟,识别码处于有效时间内,识别码为有效;若超过5分钟,识别码已经超过有效时间,则识别码失效。For example, if the inserted content is the current time segment and the check digit of the generated identification code, the current time segment of the generated identification code and the current time of the computer device can be compared, and the effective duration of the identification code set on the computer device can be verified. The timeliness of the identification code, that is, whether the identification code is still within the valid time. For example, if the effective duration of the identification code set on the computer device is 5 minutes, then the comparison time of the generation of the identification code to the current time on the computer device exceeds 5 minutes. If the identification code is less than 5 minutes, the identification code is within the valid time. The identification code is valid; if the identification code has exceeded the valid time for more than 5 minutes, the identification code is invalid.
还可以通过校验位验证识别码的真实性,也就是根据校验位上采取的不同的校验方式的校验规则,验证校验位是否存在一致性,若校验位存在一致性性,表明识别码是真实的,若校验位存在不一致性,表明识别码被篡改或破解了。比如,若校验位采用奇偶校验,根据被传输的一组二进制代码的数位中“1”的个数是奇数或偶数来进行校验。采用奇数的称为奇校验,反之,称为偶校验。采用何种校验是事先规定好的。通常专门设置一个奇偶校验位,用它使这组代码中“1”的个数为奇数或偶数。若用奇校验,则当接收端收到这组代码时,校验“1”的个数是否为奇数,从而确定传输代码的正确性。It is also possible to verify the authenticity of the identification code by the check digit, that is, according to the verification rule of different verification methods adopted on the check digit, verify whether the check digit has consistency, and if the check digit has consistency, Indicates that the identification code is authentic. If there is an inconsistency in the check digit, it indicates that the identification code has been tampered with or cracked. For example, if the parity bit uses parity, the number of "1"s in the digits of the transmitted binary code is odd or even. The odd number is called odd parity, and the other is called even parity. Which calibration is used is prescribed in advance. Usually a parity bit is set specifically, which is used to make the number of "1"s in this group of codes odd or even. If odd parity is used, when the receiving end receives the set of codes, it is checked whether the number of "1" is an odd number, thereby determining the correctness of the transmission code.
相对于根据统一规则生成的原UUID,根据插入内容能够实现对新生成的识别码的简单校验。A simple verification of the newly generated identification code can be implemented according to the inserted content with respect to the original UUID generated according to the unified rule.
在一个实施例中,UUID预先指定位置上的值包括以下至少一项:UUID的首位上的首位值,UUID的末位上的末位值。In one embodiment, the UUID pre-specified value includes at least one of the following: a first value on the first bit of the UUID and a last value on the last bit of the UUID.
具体地,计算机设备根据接收到产生识别码UUID的指令,计算机设备通过调用生成UUID的API接口,生成识别码UUID,计算机设备生成的识别码UUID为32位的16进制随机数,如:406fb0188d884cc3aff84b0f7ea2953c。计算机设备判断识别码UUID的每一位的位置范围为0~31位,每一位上的值为0~15之间的值,根据计算机的规则,识别码UUID的每个位置上的值和十进制的对应关系如下表格2所示:Specifically, the computer device generates an identification code UUID by calling an API interface that generates the UUID according to the instruction to generate the identification code UUID, and the identification code UUID generated by the computer device is a 32-bit hexadecimal random number, such as: 406fb0188d884cc3aff84b0f7ea2953c . The computer device determines that the position range of each bit of the identification code UUID is 0 to 31 bits, and the value on each bit is a value between 0 and 15, according to the rules of the computer, the value at each position of the identification code UUID and The decimal correspondence is shown in Table 2 below:
表格2Form 2
十进制Decimal 00 11 22 33 44 55 66 77 88 99 1010 1111 1212 1313 1414 1515
十六进制Hexadecimal 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff
根据上述表格2可知,上述识别码:406fb0188d884cc3aff84b0f7ea2953c,首位是4,末位是c,则识别码“406fb0188d884cc3aff84b0f7ea2953c”首位上的首位值为4,末位上的末位值为12。According to the above Table 2, the above identification code: 406fb0188d884cc3aff84b0f7ea2953c, the first digit is 4, and the last digit is c, the first digit of the first digit of the identification code "406fb0188d884cc3aff84b0f7ea2953c" is 4, and the last digit of the last digit is 12.
在一个实施例中,获取模块32包括:正整数获取单元,用于根据首位值、末位值或者首位值与末位值,获取正整数;插入位置获取单元,用于按照UUID从左到右的顺序,或者按照UUID从右到左的顺序,根据正整数,在UUID的首位和末位之间获取插入位置。In an embodiment, the obtaining module 32 includes: a positive integer obtaining unit, configured to obtain a positive integer according to the first bit value, the last bit value or the first bit value and the last bit value; and an insertion position obtaining unit for using the UUID from left to right The order of the insertion, or the order of the UUID from right to left, according to a positive integer, obtains the insertion position between the first and last digits of the UUID.
具体地,计算机设备获取插入位置,插入位置根据UUID预先指定位置上的值及插入位置的预设获取方式获取,可以是根据首位值获取的正整数,也可以是根据末位值获取的正整数,还可以是根据首位值与末位值结合起来获取正整数。比如上述识别码:406fb0188d884cc3aff84b0f7ea2953c,可见,识别码的首位的首位值为4,末位的末位值为c, 16进制c对应的十进制为12,计算机设备根据识别码首位值4,及末位值12,根据UUID预先指定位置上的值,及按照预设插入位置的获取方式,获取一个插入位置,获取的插入位置可以为以下情形中的一种:Specifically, the computer device obtains the insertion position, and the insertion position is obtained according to the preset value of the pre-specified position and the insertion position of the UUID, and may be a positive integer obtained according to the first value or a positive integer obtained according to the last value. It is also possible to combine a first value with a last value to obtain a positive integer. For example, the above identification code: 406fb0188d884cc3aff84b0f7ea2953c, it can be seen that the first digit of the first digit of the identification code is 4, the last digit of the last digit is c, the decimal of the hexadecimal c is 12, and the computer device according to the first value of the identification code 4, and the last digit. The value 12 is obtained by pre-specifying the value according to the UUID and acquiring the insertion position according to the preset insertion position. The obtained insertion position may be one of the following situations:
(1)根据UUID预先指定位置上的值,插入位置的获取方式为按照识别码从左到右的顺序获取插入位置。(1) The value at the position is pre-specified according to the UUID, and the insertion position is obtained by acquiring the insertion position in order from the left to the right according to the identification code.
若插入位置为识别码的首位值,由于识别码的首位值为4,则插入位置为识别码从左到右的第4个位置,即识别码中从左到右的第一个f后;同样,若插入位置为识别码的末位值,则插入位置为识别码从左到右的第12个位置,即识别码中从左到右的第4个8后。If the insertion position is the first value of the identification code, since the first bit value of the identification code is 4, the insertion position is the 4th position of the identification code from left to right, that is, the first f after the identification code from left to right; Similarly, if the insertion position is the last value of the identification code, the insertion position is the 12th position of the identification code from left to right, that is, the 4th 8th from left to right in the identification code.
(2)根据UUID预先指定位置上的值,插入位置的获取方式为按照识别码从右到左的顺序获取插入位置。(2) The value of the insertion position is obtained in advance according to the UUID, and the insertion position is obtained by acquiring the insertion position in order from right to left according to the identification code.
若插入位置为识别码的首位值,由于识别码的首位值为4,则插入位置为识别码从右到左的第4个位置,即识别码中从右到左第一个9前面的位置;同样,若插入位置为识别码的末位值,则插入位置为识别码的第12个位置,即识别码中从右到左第1个4的前面。If the insertion position is the first value of the identification code, since the first bit value of the identification code is 4, the insertion position is the 4th position of the identification code from right to left, that is, the position from the right to the left of the first 9 in the identification code. Similarly, if the insertion position is the last value of the identification code, the insertion position is the 12th position of the identification code, that is, the front of the first 4 from right to left in the identification code.
可见,通过上述方式,可以实现插入位置的灵活设置,进一步确保识别码的安全性。It can be seen that, through the above manner, flexible setting of the insertion position can be realized, and the security of the identification code is further ensured.
在一个实施例中,正整数获取单元包括:用于根据UUID的首位上的首位值和末位上的末位值的和,获取正整数。In one embodiment, the positive integer acquisition unit includes: for obtaining a positive integer based on the sum of the first bit value on the first bit of the UUID and the last bit value on the last bit.
具体地,计算机设备根据UUID的首位上的首位值和末位上的末位值的和,获取正整数,根据获取的正整数,按照插入位置的预设获取方式,在UUID的首位和末位之间获取插入位置。Specifically, the computer device obtains a positive integer according to the sum of the first bit value on the first bit of the UUID and the last bit value on the last bit, and according to the obtained positive integer, according to the preset acquisition manner of the insertion position, the first and last positions of the UUID Get the insertion position between.
以上述识别码:406fb0188d884cc3aff84b0f7ea2953c为例,计算机设备可以以识别码的首位值4和末位值12之和16,按照识别码从左到右的顺序,以识别码第16个位置作为预设内容的插入位置,也就是在识别码:406fb0188d884cc3 aff84b0f7ea2953c的第16个位置,也就是空格处插入预设内容。Taking the above identification code: 406fb0188d884cc3aff84b0f7ea2953c as an example, the computer device may use the sum of the first value 4 and the last value 12 of the identification code, in the order of the identification code from left to right, with the 16th position of the identification code as the preset content. The insertion position, that is, the preset content is inserted in the 16th position of the identification code: 406fb0188d884cc3 aff84b0f7ea2953c, that is, the space.
在一个实施例中,正整数获取单元包括:用于根据UUID的首位值和末位值的差的绝对值,获取正整数。In one embodiment, the positive integer acquisition unit includes: for obtaining a positive integer based on the absolute value of the difference between the first value and the last value of the UUID.
具体地,计算机设备根据UUID的首位上的首位值和末位上的末位值的差的绝对值,获取正整数,根据获取的正整数,按照插入位置的预设获取方式,在UUID的首位和末位之间获取插入位置。Specifically, the computer device obtains a positive integer according to the absolute value of the difference between the first bit value on the first bit of the UUID and the last bit value on the last bit, and according to the obtained positive integer, according to the preset acquisition mode of the insertion position, the first position of the UUID Get the insertion position between the last bit and the last bit.
以上述识别码:406fb0188d884cc3aff84b0f7ea2953c为例,计算机设备可以以识别码的首位值4和末位值12之差的绝对值8,按照识别码从左到右的顺序,以识别码第8个位置作为预设内容的插入位置,也就是在识别码:406fb018 8d884cc3aff84b0f7ea2953c的第8个位置,也就是空格处插入预设内容。Taking the above identification code: 406fb0188d884cc3aff84b0f7ea2953c as an example, the computer device may use the absolute value 8 of the difference between the first value 4 and the last value 12 of the identification code, in the order of the identification code from left to right, and the eighth position of the identification code as a pre- Set the insertion position of the content, that is, insert the preset content in the eighth position of the identification code: 406fb018 8d884cc3aff84b0f7ea2953c, that is, the space.
在一个实施例中,正整数获取单元包括:用于根据首位值加n1,末位值加n2,首位值与末位值之和加1,或者首位值与末位值之差的绝对值加n3,获取正整数,其中,1≤n1≤16,1≤n2≤16,1≤n3≤16。In one embodiment, the positive integer obtaining unit includes: for adding n1 according to the first value, adding n2 for the last value, adding 1 to the sum of the first value and the last value, or adding the absolute value of the difference between the first value and the last value plus N3, obtaining a positive integer, where 1≤n1≤16, 1≤n2≤16, 1≤n3≤16.
具体地,计算机设备根据以下情形之一,来获取正整数,进一步根据正整数和插入位置 的预设获取方式获取插入位置:Specifically, the computer device obtains a positive integer according to one of the following situations, and further acquires the insertion position according to a preset acquisition manner of the positive integer and the insertion position:
(1)根据首位值加n1,1≤n1≤16。由于UUID是32位的自然数,首位上的首位值最大为15,最小为0,为了保证插入位置在首位和末位之间,则首位值加n1,n1的取值范围只能是1≤n1≤16。(1) Add n1 according to the first value, 1 ≤ n1 ≤ 16. Since the UUID is a 32-bit natural number, the first value on the first digit is a maximum of 15 and the minimum is 0. To ensure that the insertion position is between the first and last digits, the first value is added to n1, and the range of n1 can only be 1≤n1. ≤16.
同理,末位值加n2,n2的取值范围只能是1≤n2≤16。Similarly, the last value plus n2, n2 can only be 1 ≤ n2 ≤ 16.
(2)为避免识别码的首位上的首位值与识别码的末位上的末位值的和为0,也就是,识别码的首位值与识别码的末位值均为0的情形,其和为0,和为0,意味着插入位置为识别码的首位,预设的插入内容在识别码的前面,这样的情形,识别码容易被识别,在识别码的首位值与识别码的末位值之和再加1,也就是(首位+末位)+1,范围1~31正好在识别码的首位和末位的中间,该插入方式能够保证首位和末位的数值不变,方便进行校验时确定插入位置,根据插入位置获取预设的插入内容。比如,以上述识别码:406fb0188d884cc3aff84b0f7ea2953c为例,则插入点位置为:406fb0188d884cc3a插入点ff84b0f7ea2953c。(2) In order to avoid the sum of the first bit value on the first bit of the identification code and the last bit value on the last bit of the identification code being 0, that is, the case where the first bit value of the identification code and the last bit value of the identification code are both 0, The sum is 0, and 0, which means that the insertion position is the first position of the identification code, and the preset insertion content is in front of the identification code. In this case, the identification code is easily recognized, and the first value of the identification code and the identification code are Add the sum of the last value, that is, (first + last) +1, the range 1 ~ 31 is just in the middle of the first and last digits of the identification code, the insertion method can ensure that the values of the first and last digits are unchanged. It is convenient to determine the insertion position when performing verification, and obtain the preset insertion content according to the insertion position. For example, taking the above identification code: 406fb0188d884cc3aff84b0f7ea2953c as an example, the insertion point position is: 406fb0188d884cc3a insertion point ff84b0f7ea2953c.
(3)若根据首位值与末位值之差的绝对值加n3,获取正整数。(3) If n3 is added according to the absolute value of the difference between the first value and the last value, a positive integer is obtained.
具体地,有以下两种情形:Specifically, there are two situations:
1)识别码的首位上的首位值与识别码的末位上的末位值的差的绝对值最小为0,也就是,识别码的首位上的首位值与识别码的末位上的末位值相同。1) The absolute value of the difference between the first bit value on the first bit of the identification code and the last bit value on the last bit of the identification code is 0, that is, the first bit value on the first bit of the identification code and the last bit on the last bit of the identification code The bit values are the same.
2)识别码的首位上的首位值与识别码的末位上的末位值的差的绝对值最大为15,也就是,识别码的首位上的首位值与识别码的末位上的末位值一个为0和一个为15。2) The absolute value of the difference between the first bit value on the first bit of the identification code and the last bit value on the last bit of the identification code is at most 15, that is, the first bit value on the first bit of the identification code and the last bit on the last bit of the identification code The bit values are one for 0 and one for 15.
差的绝对值为0,意味着插入位置为识别码的首位,预设的插入内容在识别码的前面,差的绝对值为15,再有17个位置,则意味着插入位置为识别码的末位,预设的插入内容在识别码的后面面,无论插入位置在识别码的前面还是后面,这样的情形,识别码容易被识别,因此为了保证插入位置在UUID的首位和末位的中间,在识别码的首位上的首位值与识别码的末位上的末位值之差的绝对值上,再加n3,也就是|首位﹣末尾|+n3,为了保证获取的插入位置在UUID的首位和末位的中间,则n3的取值最大可以取16,最小为1,该插入方式能够保证首位和末位的数值不变,方便进行校验时确定插入位置,根据插入位置获取预设的插入内容。The absolute value of the difference is 0, which means that the insertion position is the first position of the identification code, the preset insertion content is in front of the identification code, the absolute value of the difference is 15, and there are 17 positions, which means that the insertion position is the identification code. At the last position, the preset insertion content is behind the identification code, regardless of whether the insertion position is in front of or behind the identification code. In this case, the identification code is easily recognized, so that the insertion position is in the middle of the first and last positions of the UUID. , in the absolute value of the difference between the first value of the first digit of the identification code and the last digit of the last digit of the identification code, plus n3, that is, the first position - the end | + n3, in order to ensure that the obtained insertion position is in the UUID In the middle of the first and last positions, the value of n3 can be up to 16 and the minimum is 1. This insertion mode can ensure that the values of the first and last digits are unchanged, which is convenient for determining the insertion position during verification, and obtaining the pre-position according to the insertion position. Set the insertion content.
比如,以上述识别码:406fb0188d884cc3aff84b0f7ea2953c为例,以n3取1为例,则插入点位置为:406fb0188插入点d884cc3a ff84b0f7ea2953c。For example, taking the above identification code: 406fb0188d884cc3aff84b0f7ea2953c as an example, taking n3 as an example, the insertion point position is: 406fb0188 insertion point d884cc3a ff84b0f7ea2953c.
在一个实施例中,生成模块34包括:用于在插入位置插入至少以下一项内容:当前时间片段,校验位。In one embodiment, the generating module 34 includes: for inserting at least one of the following at the insertion position: a current time segment, a parity bit.
具体地,其中,当前时间片段指在插入位置插入预设内容时,获取的时间戳的生成时间,由于是以一段数字表示,称之为当前时间片段。当前时间片段的获取方式可以为:以JavaScript为例,JavaScript用new Date().getTime()来获时间戳,获取的是十进制的以毫秒为单位的时间戳,十进制的时间戳去除高位前k位(离产生时间戳的生产时间较远的位,数值长期不变,去除后不影响生存时间的判定),再去除后3位(除以1000,从秒截取),转化成十六进制, 得到当前时间片段。对于k的取值,以不影响定义的时间片段的有效性生存时间为准,比如生成一个十进制的时间戳为12345,假设定义的当前时间片段的生存时间为345,则12345+345=12690,也就是当前时间片段的有效性截止时间为12690,12345与12690相比,去除12345的高位,也就是离生产时间较远的与12690共有的位数12,不影响对生存时间有效性的判断,则去掉12345的高位12,剩余位数345,则十进制的时间戳去除高位前k位,是指去除十进制的时间戳12345的高位前2位12。Specifically, the current time segment refers to a time when the time stamp is acquired when the preset content is inserted at the insertion position, and is represented by a one-digit number, which is called a current time segment. The current time segment can be obtained by taking JavaScript as an example. JavaScript uses new Date().getTime() to get the timestamp, and obtains the decimal timestamp in milliseconds. The decimal timestamp removes the high-order k. Bit (the bit farther from the production time when the time stamp is generated, the value is unchanged for a long time, and the survival time is not affected after the removal), and then the last 3 bits are removed (divided by 1000, intercepted from the second), converted into hexadecimal , get the current time segment. For the value of k, the validity time of the time segment is not affected, for example, generating a decimal timestamp of 12345, assuming that the defined current time segment has a lifetime of 345, then 12345+345=12690, That is, the validity time limit of the current time segment is 12690. Compared with 12690, 12345 removes the high level of 12345, that is, the number of bits shared with 12690 far from the production time, which does not affect the judgment of the validity of the survival time. Then, the high bit 12 of 12345 is removed, and the remaining number of bits is 345. The decimal time stamp removes the upper k bits of the high order, which means that the first two bits 12 of the high order of the decimal time stamp 12345 are removed.
如果以PHP(是英文超文本预处理语言Hypertext Preprocessor的缩写)为例,获取的时间戳是以秒为单位的时间戳,则直接转化成16进制,得到当前时间片段,通过不同方式获取的时间戳,根据时间单位毫秒、秒等单位之间的关系换算成需要的时间单位,转换成16进制,即可得到当前的时间片段。其中,时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起至现在的总秒数。If PHP (which is the abbreviation of Hypertext Preprocessor in English), the obtained timestamp is a timestamp in seconds, which is directly converted into hexadecimal, and the current time segment is obtained by different methods. The timestamp is converted into the required time unit according to the relationship between the unit of time unit milliseconds, seconds, etc., and converted into hexadecimal to obtain the current time segment. Among them, the time stamp refers to the total number of seconds from 01:00 to 00:00 on January 01, 1970 (Beijing time, January 01, 1970, 08:00:00).
在一个实施例中,根据实际需要对时间的敏感度,除了上述用秒为时间单位获取当前时间片段,还可以以分钟为时间单位来获取时间片段。比如,仍以JavaScript为例,由于终端生成的时间戳默认是以毫秒计算的,由于秒和毫秒之间是1000的倍数关系,所以以秒来获取时间片段的话,是去除后3位,除以1000;如果是以分钟,则是除以60×1000。In one embodiment, according to the actual need for time sensitivity, in addition to the above-mentioned time segment for acquiring the current time segment in seconds, the time segment may also be acquired in units of minutes. For example, JavaScript is still used as an example. Since the timestamp generated by the terminal is calculated in milliseconds by default, since the second and milliseconds are multiples of 1000, if the time segment is acquired in seconds, the last 3 bits are removed, divided by 1000; if it is in minutes, it is divided by 60×1000.
在一个实施例中,时间片段的设置,还可以通过将时间片段的顺序颠倒,比如从正到反,来定制时间片段,比如按上述算法获得的时间片段是12345,则可将12345顺序反过来,通过54321来表示时间片段,从而获得时间片段的定制。In one embodiment, the setting of the time segment can also be customized by reversing the order of the time segments, such as from front to back. For example, the time segment obtained by the above algorithm is 12345, and the sequence of 12345 can be reversed. The time segment is represented by 54321, thereby obtaining the customization of the time segment.
可见,通过上述方式获取当前时间片段的方式是多种多样的,从而实现当前时间片段定制的灵活性,进一步确保识别码的安全。It can be seen that the manner of obtaining the current time segment in the above manner is various, thereby realizing the flexibility of the current time segment customization, and further ensuring the security of the identification code.
在一个实施例中,根据实际情形对识别码时效性需求,以当前时间片段为基准,可通过服务器端定义识别码的生存时间,识别码的生存时间,也就是指识别码的有效时间,在生存时间内,识别码处于有效状态,超过生存时间,识别码处于失效状态,比如定义识别码的生存时间为5分钟,则从识别码生成的时间算起,在5分钟内,识别码有效,超过5分钟,识别码失效。服务器校验识别码时,服务器根据生成识别码的当前时间片段表示的识别码的生成时间与当前时间比较,判断识别码在定义的生存时间内,识别码有效,若服务器判断识别码超过了识别码定义的生存时间,则识别码失效。也就是识别码的生存时间是可以通过服务器根据需要定制的,例如5分钟、3分钟等,在生存时间内,则UUID有效,超过生存时间,则UUID失效,从而验证UUID的时效性,满足实际需要中对识别码有时效性要求的情形,比如扫码登录、扫码支付等,为了保证账户的安全,识别码需要满足一定的时效性要求,扫码登录,设置识别码为2分钟,在2分钟内,识别码有效,超过2分钟,识别码自动失效。In an embodiment, according to the actual situation, the time-sensitive requirement of the identification code is based on the current time segment, and the survival time of the identification code can be defined by the server, and the survival time of the identification code, that is, the effective time of the identification code, During the survival time, the identification code is in a valid state, exceeding the survival time, and the identification code is in a failure state. For example, if the survival time of the identification code is 5 minutes, the identification code is valid within 5 minutes from the time when the identification code is generated. The identification code is invalid for more than 5 minutes. When the server verifies the identification code, the server compares the generation time of the identification code represented by the current time segment of the generated identification code with the current time, and determines that the identification code is valid within the defined survival time, and if the server determines that the identification code exceeds the identification If the code defines the lifetime, the identifier will be invalid. That is, the survival time of the identification code can be customized according to the needs of the server, for example, 5 minutes, 3 minutes, etc. In the survival time, the UUID is valid, and the UUID is invalid after the survival time is exceeded, thereby verifying the timeliness of the UUID and satisfying the actual situation. In the case of need for the time-sensitive requirements of the identification code, such as scan code registration, scan code payment, etc., in order to ensure the security of the account, the identification code needs to meet certain timeliness requirements, scan code registration, set the identification code to 2 minutes, in Within 2 minutes, the identification code is valid. If it is more than 2 minutes, the identification code will automatically expire.
其中,校验位为奇偶校验、CRC校验、和校验或者MD5校验等。Among them, the check digit is parity, CRC check, and check or MD5 check.
在一个实施例中,校验位由当前时间片段根据第二预设规则获取。In one embodiment, the check digit is acquired by the current time segment according to a second preset rule.
具体地,第二预设规则为校验位的获取方式。校验位的获取方式为:(当前时间片段后k位+插入位,k≥1)%16 n,若校验位取1位时,n为1,也就是16 n=16 1=16,比如校验位取1位时,校验位的值可采取:(当前时间片段后3位+插入位)%16。其中,当前时间片段后k 位中的当前时间片段,可以是以十六进制表示的当前时间片段,也可以是以十进制表示的当前时间片段,从而进一步实现校验位获取方式的灵活多样性,根据当前时间片段的唯一性,从而获取的校验位也是唯一的,根据校验位和当前时间片段是否对应,从而校验识别码的真实性。 Specifically, the second preset rule is a manner of acquiring a check digit. The check bit is obtained by: (the current time segment is followed by k bit + insert bit, k ≥ 1)% 16 n , if the check bit takes 1 bit, n is 1, that is, 16 n = 16 1 = 16, For example, when the parity bit takes 1 bit, the value of the parity bit can take: (3 bits after the current time segment + insertion bit) %16. The current time segment in the k-bit after the current time segment may be a current time segment expressed in hexadecimal or a current time segment expressed in decimal, thereby further implementing flexible diversity of the check bit acquisition manner. According to the uniqueness of the current time segment, the obtained check digit is also unique, and the authenticity of the identifier is verified according to whether the check digit corresponds to the current time segment.
同样,若校验位为2位时,n取2,也就是16 n=16 2,若校验位为3位时,16 n=16 3,校验位为n位时,为16 n,因此,采取这种方式获取的校验位,校验覆盖插入位与生存时间相关的当前时间片段,校验规则简单,校验位也是可以灵活设置的。 Similarly, if the parity bit is 2 bits, n takes 2, which is 16 n = 16 2 . If the parity bit is 3 bits, 16 n = 16 3 , and when the parity bit is n bits, it is 16 n . Therefore, the check bit obtained in this way is verified, and the current time segment related to the survival time is covered by the overlay insertion bit, the verification rule is simple, and the check bit can also be flexibly set.
具体地,在插入位置插入当前时间片段,根据当前时间片段表示的时间与服务器判断识别码时的当时时间进行比较,根据时间的差值是否超过服务器定义的识别码的生存时间,判断识别码的时效性,通过在插入位置插入校验位,用来设置识别码的真实性,如果在位置同时插入当前时间片段和校验位,则可以同时验证识别码的时效性和真实性。Specifically, the current time segment is inserted at the insertion position, and the time represented by the current time segment is compared with the current time when the server determines the identification code, and the identification code is determined according to whether the difference of the time exceeds the survival time of the server-defined identification code. Timeliness, by inserting a check digit at the insertion position, it is used to set the authenticity of the identification code. If the current time segment and the check digit are simultaneously inserted in the position, the timeliness and authenticity of the identification code can be verified at the same time.
比如,以上述识别码:406fb0188d884cc3aff84b0f7ea2953c为例,插入位置为(首位值+末位值)+1,则插入位置为:4+c(十进制的12)+1=17,也就是插入位置为识别码的第17位,插入内容:当前时间片段+校验位。其中,由于识别码采取十六进制,识别码每个位置上的值最大为15,因此(首位值+末位值)+1获取的插入位置在识别码的首位和末位的中间。For example, taking the above identification code: 406fb0188d884cc3aff84b0f7ea2953c as an example, the insertion position is (first value + last value) +1, then the insertion position is: 4+c (12 in decimal) +1=17, that is, the insertion position is the identification code. 17th place, insert content: current time segment + check digit. Wherein, since the identification code adopts hexadecimal, the value at each position of the identification code is at most 15, so the insertion position obtained by (first value + last value) +1 is in the middle of the first and last bits of the identification code.
其中,当前时间片段:可以从秒截取,去除高位前k位(离生产时间较远的位),转十六进制进制,比如获取的十六进制的当前时间片段为:1d8b6f84。同时,可根据时效性需求,比如通过服务器设置识别码的生存时间为3分钟。Among them, the current time segment: can be intercepted from the second, remove the upper k position (bit far from the production time), and turn to hexadecimal, for example, the current time segment of the obtained hexadecimal is: 1d8b6f84. At the same time, according to the timeliness requirements, for example, the survival time of the identifier set by the server is 3 minutes.
校验位:1位,值为:(当前时间片段后3位+插入位)%16,比如,以十六进制表示当前时间片段,以当前时间片段的10进制表示方式的后3位获取校验位,则根据十六进制的当前时间片段为:1d8b6f84的十进制表示方式的后3位获取的校验位为5。Check digit: 1 bit, the value is: (3 bits after the current time segment + insert bit) %16, for example, the current time segment is expressed in hexadecimal, the last 3 digits of the current time segment in decimal notation To obtain the check digit, the current time segment according to hexadecimal is: the check digit of the last 3 digits of the decimal representation of 1d8b6f84 is 5.
新识别码生成结果如下:The new identifier generation result is as follows:
406fb0188d884cc3a            ff84b0f7ea2953c;406fb0188d884cc3a ff84b0f7ea2953c;
406fb0188d884cc3a 1d8b6f84 5 ff84b0f7ea2953c。406fb0188d884cc3a 1d8b6f84 5 ff84b0f7ea2953c.
对上述新生成的识别码,服务器进行新生成的识别码校验时,可采取如下方式:For the newly generated identification code, when the server performs the newly generated identification code verification, the following manner may be adopted:
1)、根据首位值4和末位值c,找到插入位置第17位,根据新UUID长度-32(原UUID长度),获取插入长度9位,从插入位置截取出插入内容1d8b6f84 5。1) According to the first value 4 and the last value c, the 17th position of the insertion position is found, and according to the new UUID length -32 (the original UUID length), the insertion length 9 bits is acquired, and the insertion content 1d8b6f84 5 is intercepted from the insertion position.
2)、取插入内容最后一位5用作校验,检验UUID的真实性。2), take the last bit of the inserted content 5 for verification, verify the authenticity of the UUID.
3)、取插入内容的其余片段与当前时间做比较,查看识别码是否超过服务器定义的生存时间(如3分钟),检验UUID的时效性。3), take the rest of the inserted content to compare with the current time, check whether the identification code exceeds the server-defined survival time (such as 3 minutes), and check the timeliness of the UUID.
因此,通过上述方式生成的识别码可校验识别码的真实性和时效性。Therefore, the identification code generated by the above manner can verify the authenticity and timeliness of the identification code.
在保持了新生成的UUID唯一性的前提下,改进后新UUID有如下有益效果:Under the premise of maintaining the uniqueness of the newly generated UUID, the improved new UUID has the following beneficial effects:
1)、新UUID的生成方式,可验证新UUID是可靠的、真实的;1) The new UUID is generated to verify that the new UUID is reliable and authentic;
2)、插入时间片段,并纳入校验,可为新UUID设定有效的存活时间;2) Insert a time segment and include a check to set a valid survival time for the new UUID;
3)、插入的时间片段、校验字段以及其生存周期皆可定制,因此,新UUID生成规则具有多样性;3), the inserted time segment, check field and its life cycle can be customized, therefore, the new UUID generation rules are diverse;
4)、生成与校验算法复杂度较低,耗时短。4) The generation and verification algorithm has low complexity and short time.
在一个实施例中,在插入位置插入当前时间片段和校验位,其中,当前时间片段在前,校验位在后,或者校验位在前,当前时间片段在后。In one embodiment, the current time segment and the check digit are inserted at the insertion position, wherein the current time segment is first, the parity bit is after, or the parity bit is first, and the current time segment is after.
具体地,当在识别码的插入位置同时插入当前时间片段和校验位时,当前时间片段和校验位的顺序可以设置为当前时间片段在前,也可以设置为校验位在前。Specifically, when the current time segment and the check bit are simultaneously inserted at the insertion position of the identification code, the order of the current time segment and the check bit may be set to the current time segment first, or may be set to the check bit first.
识别码在实际应用中,比如做一个二维码扫码登录功能开发时,需要一个唯一的字段代表二维码,通过一个唯一的字段UUID代表二维码,通过UUID的唯一性验证真实性,通过UUID的时效性来保证二维码的有效与失效,当验证二维码真实且有效时,允许用户通过扫码登录账户,从而保证登录账户的安全。In the actual application, for example, when developing a QR code scan code registration function, a unique field is required to represent the two-dimensional code, and a unique field UUID is used to represent the two-dimensional code, and the authenticity is verified by the uniqueness of the UUID. The validity and failure of the two-dimensional code are ensured by the timeliness of the UUID. When verifying that the two-dimensional code is true and valid, the user is allowed to log in to the account by scanning the code, thereby ensuring the security of the login account.
上述识别码的生成装置中各个模块的划分仅用于举例说明,在其他实施例中,可将识别码的生成装置按照需要划分为不同的模块,以完成上述识别码的生成装置的全部或部分功能。The division of each module in the above-mentioned identification code generating device is for illustrative purposes only. In other embodiments, the identification code generating device may be divided into different modules as needed to complete all or part of the above-mentioned identification code generating device. Features.
上述的识别码的生成装置可以实现为一种计算机可读指令的形式,计算机可读指令可在如图4所示的计算机设备上运行。The above-described identification code generating means can be implemented in the form of a computer readable instruction which can be run on a computer device as shown in FIG.
在一个实施例中,提供了一个或多个存储有计算机可读指令的非易失性可读存储介质,该计算机可读指令被一个或多个处理器执行时,使得一个或多个处理器执行以下步骤:若接收到产生识别码UUID的指令,产生UUID;及根据UUID预先指定位置上的值,按照预设获取方式,在UUID的首位和末位之间获取插入位置;在插入位置插入验证UUID的预设内容,生成新的识别码,预设内容按照第一预设规则生成。In one embodiment, one or more non-volatile readable storage media having computer readable instructions stored by one or more processors are provided, such that one or more processors are Performing the following steps: if receiving the instruction for generating the identification code UUID, generating the UUID; and pre-specifying the value according to the UUID, obtaining the insertion position between the first and last positions of the UUID according to the preset acquisition manner; inserting at the insertion position The preset content of the UUID is verified, and a new identification code is generated, and the preset content is generated according to the first preset rule.
在一个实施例中,UUID预先指定位置上的值包括以下至少一项:UUID的首位上的首位值,UUID的末位上的末位值。In one embodiment, the UUID pre-specified value includes at least one of the following: a first value on the first bit of the UUID and a last value on the last bit of the UUID.
在一个实施例中,处理器所执行的根据UUID预先指定位置上的值,按照预设获取方式,在UUID的首位和末位之间获取插入位置的步骤包括:根据首位值、末位值或者首位值与末位值,获取正整数;及按照UUID从左到右的顺序,或者按照UUID从右到左的顺序,根据正整数,在UUID的首位和末位之间获取插入位置。In an embodiment, the step of obtaining the insertion position between the first position and the last position of the UUID according to the preset acquisition manner by the processor according to the UUID pre-specified value includes: according to the first value, the last value or The first value and the last value are obtained as positive integers; and the insertion position is obtained between the first and last positions of the UUID according to the positive integer in the order from left to right in UUID or from right to left in accordance with the UUID.
在一个实施例中,处理器所执行的根据首位值与末位值,获取正整数的步骤包括:根据首位值与末位值的和,或者根据首位值与末位值的差的绝对值,获取正整数。In an embodiment, the step of obtaining a positive integer according to the first bit value and the last bit value performed by the processor comprises: according to the sum of the first bit value and the last bit value, or according to the absolute value of the difference between the first bit value and the last bit value, Get a positive integer.
在一个实施例中,处理器所执行的根据首位值、末位值或者首位值与末位值获取正整数的步骤包括:根据首位值加n1,末位值加n2,首位值与末位值之和加1,或者首位值与末位值之差的绝对值加n3,获取正整数,其中,1≤n1≤16,1≤n2≤16,1≤n3≤16。In an embodiment, the step of obtaining a positive integer according to the first bit value, the last bit value or the first bit value and the last bit value performed by the processor includes: adding n1 according to the first bit value, adding n2 to the last bit value, and the first bit value and the last bit value. The sum is incremented by 1, or the absolute value of the difference between the first bit value and the last bit value is added by n3 to obtain a positive integer, where 1 ≤ n1 ≤ 16, 1 ≤ n2 ≤ 16, and 1 ≤ n3 ≤ 16.
在一个实施例中,处理器所执行的在插入位置插入验证UUID的预设内容的步骤包括:在插入位置插入以下至少一项内容:当前时间片段,校验位。In one embodiment, the step of inserting, by the processor, the preset content of the verification UUID at the insertion position comprises: inserting at least one of the following contents at the insertion position: a current time segment, a parity bit.
在一个实施例中,校验位由当前时间片段根据第二预设规则获取。In one embodiment, the check digit is acquired by the current time segment according to a second preset rule.
本申请实施例还提供了一种计算机设备,计算机设备,包括存储器及处理器,存储器中储存有计算机可读指令,计算机可读指令被处理器执行时,使得处理器执行的识别码的生成方法的步骤。如图4所示,为了便于说明,仅示出了与本申请实施例相关的部分。该计算机设备可以为包括个人电脑或者服务器等计算机设备。The embodiment of the present application further provides a computer device, including a memory and a processor, where the computer stores readable instructions, and when the computer readable instructions are executed by the processor, the method for generating the identifier executed by the processor A step of. As shown in FIG. 4, for the convenience of description, only parts related to the embodiment of the present application are shown. The computer device can be a computer device including a personal computer or a server.
图4为与本申请实施例提供的计算机设备的内部结构图。如图4所示,该计算机设备包括通过系统总线连接的处理器、非易失性存储介质、内存储器和网络接口。其中,该计算机设备的非易失性存储介质存储有操作系统和计算机可读指令。该计算机可读指令被处理器执行时以实现一种识别码的生成方法。该计算机设备的处理器用于提供计算和控制能力,支撑整个计算机设备的运行。该计算机设备的网络接口用于据以与外部的终端通过网络连接通信,比如接收终端发送的扫码请求以及向终端返回包含识别码的二维码等。计算机设备可以用独立的服务器或者是多个服务器组成的服务器集群来实现。本领域技术人员可以理解,图4中示出的结构,仅仅是与本申请方案相关的部分结构的框图,并不构成对本申请方案所应用于其上的计算机设备的限定,具体的计算机设备可以包括比图中所示更多或更少的部件,或者组合某些部件,或者具有不同的部件布置。4 is a diagram showing the internal structure of a computer device provided by an embodiment of the present application. As shown in FIG. 4, the computer device includes a processor, a non-volatile storage medium, an internal memory, and a network interface connected by a system bus. Wherein, the non-volatile storage medium of the computer device stores an operating system and computer readable instructions. The computer readable instructions are executed by the processor to implement a method of generating an identification code. The processor of the computer device is used to provide computing and control capabilities to support the operation of the entire computer device. The network interface of the computer device is configured to communicate with an external terminal via a network connection, such as receiving a scan code request sent by the terminal and returning a two-dimensional code including the identification code to the terminal. The computer device can be implemented by a stand-alone server or a server cluster composed of multiple servers. It will be understood by those skilled in the art that the structure shown in FIG. 4 is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation of the computer device to which the solution of the present application is applied. The specific computer device may It includes more or fewer components than those shown in the figures, or some components are combined, or have different component arrangements.
在一个实施例中,提供了一种计算机设备,包括存储器和一个或多个处理器,该存储器中存储有计算机可读指令,该计算机可读指令被处理器执行时,使得一个或多个处理器执行以下步骤:若接收到产生识别码UUID的指令,产生UUID;及根据UUID预先指定位置上的值,按照预设获取方式,在UUID的首位和末位之间获取插入位置;在插入位置插入验证UUID的预设内容,生成新的识别码,预设内容按照第一预设规则生成。In one embodiment, a computer apparatus is provided comprising a memory and one or more processors having stored therein computer readable instructions that, when executed by a processor, cause one or more processes The device performs the following steps: if receiving the instruction for generating the identification code UUID, generating the UUID; and pre-specifying the value according to the UUID, and obtaining the insertion position between the first and last positions of the UUID according to the preset acquisition manner; The preset content of the verification UUID is inserted to generate a new identification code, and the preset content is generated according to the first preset rule.
在一个实施例中,UUID预先指定位置上的值包括以下至少一项:UUID的首位上的首位值,UUID的末位上的末位值。In one embodiment, the UUID pre-specified value includes at least one of the following: a first value on the first bit of the UUID and a last value on the last bit of the UUID.
在一个实施例中,处理器所执行的根据UUID预先指定位置上的值,按照预设获取方式,在UUID的首位和末位之间获取插入位置的步骤包括:根据首位值、末位值或者首位值与末位值,获取正整数;及按照UUID从左到右的顺序,或者按照UUID从右到左的顺序,根据正整数,在UUID的首位和末位之间获取插入位置。In an embodiment, the step of obtaining the insertion position between the first position and the last position of the UUID according to the preset acquisition manner by the processor according to the UUID pre-specified value includes: according to the first value, the last value or The first value and the last value are obtained as positive integers; and the insertion position is obtained between the first and last positions of the UUID according to the positive integer in the order from left to right in UUID or from right to left in accordance with the UUID.
在一个实施例中,处理器所执行的根据首位值与末位值,获取正整数的步骤包括:根据首位值与末位值的和,或者根据首位值与末位值的差的绝对值,获取正整数。In an embodiment, the step of obtaining a positive integer according to the first bit value and the last bit value performed by the processor comprises: according to the sum of the first bit value and the last bit value, or according to the absolute value of the difference between the first bit value and the last bit value, Get a positive integer.
在一个实施例中,处理器所执行的根据首位值、末位值或者首位值与末位值获取正整数的步骤包括:根据首位值加n1,末位值加n2,首位值与末位值之和加1,或者首位值与末位值之差的绝对值加n3,获取正整数,其中,1≤n1≤16,1≤n2≤16,1≤n3≤16。In an embodiment, the step of obtaining a positive integer according to the first bit value, the last bit value or the first bit value and the last bit value performed by the processor includes: adding n1 according to the first bit value, adding n2 to the last bit value, and the first bit value and the last bit value. The sum is incremented by 1, or the absolute value of the difference between the first bit value and the last bit value is added by n3 to obtain a positive integer, where 1 ≤ n1 ≤ 16, 1 ≤ n2 ≤ 16, and 1 ≤ n3 ≤ 16.
在一个实施例中,处理器所执行的在插入位置插入验证UUID的预设内容的步骤包括:在插入位置插入以下至少一项内容:当前时间片段,校验位。In one embodiment, the step of inserting, by the processor, the preset content of the verification UUID at the insertion position comprises: inserting at least one of the following contents at the insertion position: a current time segment, a parity bit.
在一个实施例中,校验位由当前时间片段根据第二预设规则获取。In one embodiment, the check digit is acquired by the current time segment according to a second preset rule.
本申请所使用的对存储器、存储、数据库或其它介质的任何引用可包括非易失性。合适的非易失性存储器可包括只读存储器(ROM)、可编程ROM(PROM)、电可编程ROM(EPROM)、电可擦除可编程ROM(EEPROM)或闪存。Any reference to a memory, storage, database, or other medium used herein may include non-volatile. Suitable non-volatile memories can include read only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory.
以上所述实施例仅表达了本申请的几种实施方式,其描述较为具体和详细,但并不能因此而理解为对本申请专利范围的限制。应当指出的是,对于本领域的普通技术人员来说,在不脱离本申请构思的前提下,还可以做出若干变形和改进,这些都属于本申请的保护范围。因此,本申请专利的保护范围应以所附权利要求为准。The above-mentioned embodiments are merely illustrative of several embodiments of the present application, and the description thereof is more specific and detailed, but is not to be construed as limiting the scope of the claims. It should be noted that a number of variations and modifications may be made by those skilled in the art without departing from the spirit and scope of the present application. Therefore, the scope of the invention should be determined by the appended claims.

Claims (20)

  1. 一种识别码的生成方法,包括:A method for generating an identification code, comprising:
    若接收到产生识别码UUID的指令,产生所述UUID;Generating the UUID if an instruction to generate the identification code UUID is received;
    根据所述UUID预先指定位置上的值,按照预设获取方式,在所述UUID的首位和末位之间获取插入位置;及Obtaining an insertion position between the first position and the last position of the UUID according to a preset acquisition manner according to a value of the UUID pre-specified position; and
    在所述插入位置插入验证所述UUID的预设内容,生成新的识别码,所述预设内容按照第一预设规则生成。A preset content for verifying the UUID is inserted at the insertion position to generate a new identification code, and the preset content is generated according to a first preset rule.
  2. 根据权利要求1所述的方法,其特征在于,所述UUID预先指定位置上的值包括以下至少一项:The method according to claim 1, wherein the value of the UUID pre-specified position comprises at least one of the following:
    所述UUID的首位上的首位值,所述UUID的末位上的末位值。a first value on the first bit of the UUID, and a last value on the last bit of the UUID.
  3. 根据权利要求2所述的方法,其特征在于,所述根据所述UUID预先指定位置上的值,按照预设获取方式,在所述UUID的首位和末位之间获取插入位置的步骤包括:The method according to claim 2, wherein the step of obtaining an insertion position between the first position and the last position of the UUID according to the preset acquisition manner according to the value of the UUID pre-specified position includes:
    根据所述首位值、所述末位值或者所述首位值与所述末位值,获取正整数;及Obtaining a positive integer according to the first value, the last value, or the first value and the last value; and
    按照所述UUID从左到右的顺序,或者按照所述UUID从右到左的顺序,根据所述正整数,在所述UUID的首位和末位之间获取插入位置。The insertion position is obtained between the first and last digits of the UUID according to the positive integer in the order from left to right of the UUID or from right to left in accordance with the UUID.
  4. 根据权利要求3所述的方法,其特征在于,所述根据所述首位值与所述末位值,获取正整数的步骤包括:The method according to claim 3, wherein the step of obtaining a positive integer according to the first bit value and the last bit value comprises:
    根据所述首位值与所述末位值的和,或者根据所述首位值与所述末位值的差的绝对值,获取正整数。A positive integer is obtained according to the sum of the first bit value and the last bit value, or according to the absolute value of the difference between the first bit value and the last bit value.
  5. 根据权利要求3所述的方法,其特征在于,所述根据所述首位值、所述末位值或者所述首位值与所述末位值获取正整数的步骤包括:The method according to claim 3, wherein the step of obtaining a positive integer according to the first bit value, the last bit value or the first bit value and the last bit value comprises:
    根据所述首位值加n1,所述末位值加n2,所述首位值与所述末位值之和加1,或者所述首位值与所述末位值之差的绝对值加n3,获取正整数,其中,1≤n1≤16,1≤n2≤16,1≤n3≤16。Adding n1 according to the first bit value, adding n2 to the last bit value, adding 1 to the sum of the first bit value and the last bit value, or adding n3 to the absolute value of the difference between the first bit value and the last bit value, A positive integer is obtained, where 1 ≤ n1 ≤ 16, 1 ≤ n2 ≤ 16, and 1 ≤ n3 ≤ 16.
  6. 根据权利要求1所述的方法,其特征在于,所述在所述插入位置插入验证所述UUID的预设内容的步骤包括:The method according to claim 1, wherein the step of inserting the preset content for verifying the UUID at the insertion position comprises:
    在所述插入位置插入以下至少一项内容:当前时间片段,校验位。At least one of the following contents is inserted at the insertion position: a current time segment, a parity bit.
  7. 根据权利要求6所述的方法,其特征在于,所述校验位由所述当前时间片段根据第二预设规则获取。The method according to claim 6, wherein the check bit is acquired by the current time segment according to a second preset rule.
  8. 一种识别码的生成装置,其特征在于,所述装置包括:An apparatus for generating an identification code, characterized in that the apparatus comprises:
    产生模块,用于若接收到产生识别码UUID的指令,产生所述UUID;a generating module, configured to generate the UUID if receiving an instruction to generate an identifier UUID;
    获取模块,用于根据所述UUID预先指定位置上的值,按照预设获取方式,在所述UUID的首位和末位之间获取插入位置;及An obtaining module, configured to obtain an insertion position between a first position and a last position of the UUID according to a preset acquisition manner according to a value in a pre-specified position of the UUID; and
    生成模块,用于在所述插入位置插入验证所述UUID的预设内容,生成新的识别码,所述预设内容按照第一预设规则生成。And a generating module, configured to insert a preset content for verifying the UUID at the insertion position, and generate a new identification code, where the preset content is generated according to a first preset rule.
  9. 一种计算机设备,包括存储器和一个或多个处理器,所述存储器中存储有计算机可读指令,所述计算机可读指令被所述处理器执行时,使得所述一个或多个处理器执行以下步骤:A computer device comprising a memory and one or more processors, the memory storing computer readable instructions, the computer readable instructions being executed by the processor, causing the one or more processors to execute The following steps:
    若接收到产生识别码UUID的指令,产生所述UUID;Generating the UUID if an instruction to generate the identification code UUID is received;
    根据所述UUID预先指定位置上的值,按照预设获取方式,在所述UUID的首位和末位之间获取插入位置;及Obtaining an insertion position between the first position and the last position of the UUID according to a preset acquisition manner according to a value of the UUID pre-specified position; and
    在所述插入位置插入验证所述UUID的预设内容,生成新的识别码,所述预设内容按照第一预设规则生成。A preset content for verifying the UUID is inserted at the insertion position to generate a new identification code, and the preset content is generated according to a first preset rule.
  10. 根据权利要求9所述的计算机设备,其特征在于,所述UUID预先指定位置上的值包括以下至少一项:The computer apparatus according to claim 9, wherein the value of the UUID pre-specified location comprises at least one of the following:
    所述UUID的首位上的首位值,所述UUID的末位上的末位值。a first value on the first bit of the UUID, and a last value on the last bit of the UUID.
  11. 根据权利要求10所述的计算机设备,其特征在于,所述处理器所执行的根据所述UUID预先指定位置上的值,按照预设获取方式,在所述UUID的首位和末位之间获取插入位置的步骤包括:The computer device according to claim 10, wherein the value of the pre-specified position according to the UUID executed by the processor is obtained between the first bit and the last bit of the UUID according to a preset acquisition manner. The steps to insert a location include:
    根据所述首位值、所述末位值或者所述首位值与所述末位值,获取正整数;及Obtaining a positive integer according to the first value, the last value, or the first value and the last value; and
    按照所述UUID从左到右的顺序,或者按照所述UUID从右到左的顺序,根据所述正整数,在所述UUID的首位和末位之间获取插入位置。The insertion position is obtained between the first and last digits of the UUID according to the positive integer in the order from left to right of the UUID or from right to left in accordance with the UUID.
  12. 根据权利要求11所述的计算机设备,其特征在于,所述处理器所执行的根据所述首位值与所述末位值,获取正整数的步骤包括:The computer device according to claim 11, wherein the step of obtaining, by the processor, the obtaining of a positive integer according to the first bit value and the last bit value comprises:
    根据所述首位值与所述末位值的和,或者根据所述首位值与所述末位值的差的绝对值,获取正整数。A positive integer is obtained according to the sum of the first bit value and the last bit value, or according to the absolute value of the difference between the first bit value and the last bit value.
  13. 根据权利要求12所述的计算机设备,其特征在于,所述处理器所执行的根据所述首位值、所述末位值或者所述首位值与所述末位值获取正整数的步骤包括:The computer device according to claim 12, wherein the step of the processor to obtain a positive integer according to the first bit value, the last bit value or the first bit value and the last bit value comprises:
    根据所述首位值加n1,所述末位值加n2,所述首位值与所述末位值之和加1,或者所述首位值与所述末位值之差的绝对值加n3,获取正整数,其中,1≤n1≤16,1≤n2≤16,1≤n3≤16。Adding n1 according to the first bit value, adding n2 to the last bit value, adding 1 to the sum of the first bit value and the last bit value, or adding n3 to the absolute value of the difference between the first bit value and the last bit value, A positive integer is obtained, where 1 ≤ n1 ≤ 16, 1 ≤ n2 ≤ 16, and 1 ≤ n3 ≤ 16.
  14. 根据权利要求10所述的计算机设备,其特征在于,所述处理器所执行的在所述插入位置插入验证所述UUID的预设内容的步骤包括:The computer device according to claim 10, wherein the step of inserting, by the processor, the verification of the preset content of the UUID at the insertion position comprises:
    在所述插入位置插入以下至少一项内容:当前时间片段,校验位。At least one of the following contents is inserted at the insertion position: a current time segment, a parity bit.
  15. 一个或多个存储有计算机可读指令的非易失性可读存储介质,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行以下步骤:One or more non-transitory readable storage mediums storing computer readable instructions, when executed by one or more processors, cause the one or more processors to perform the following steps:
    若接收到产生识别码UUID的指令,产生所述UUID;Generating the UUID if an instruction to generate the identification code UUID is received;
    根据所述UUID预先指定位置上的值,按照预设获取方式,在所述UUID的首位和末位之间获取插入位置;及Obtaining an insertion position between the first position and the last position of the UUID according to a preset acquisition manner according to a value of the UUID pre-specified position; and
    在所述插入位置插入验证所述UUID的预设内容,生成新的识别码,所述预设内容按 照第一预设规则生成。A preset content for verifying the UUID is inserted at the insertion position to generate a new identification code, and the preset content is generated according to the first preset rule.
  16. 根据权利要求15所述的存储介质,其特征在于,所述UUID预先指定位置上的值包括以下至少一项:The storage medium according to claim 15, wherein the value of the UUID pre-specified position comprises at least one of the following:
    所述UUID的首位上的首位值,所述UUID的末位上的末位值。a first value on the first bit of the UUID, and a last value on the last bit of the UUID.
  17. 根据权利要求16所述的存储介质,其特征在于,所述处理器所执行的根据所述UUID预先指定位置上的值,按照预设获取方式,在所述UUID的首位和末位之间获取插入位置的步骤包括:The storage medium according to claim 16, wherein the value of the pre-specified position according to the UUID executed by the processor is obtained between the first bit and the last bit of the UUID according to a preset acquisition manner. The steps to insert a location include:
    根据所述首位值、所述末位值或者所述首位值与所述末位值,获取正整数;及Obtaining a positive integer according to the first value, the last value, or the first value and the last value; and
    按照所述UUID从左到右的顺序,或者按照所述UUID从右到左的顺序,根据所述正整数,在所述UUID的首位和末位之间获取插入位置。The insertion position is obtained between the first and last digits of the UUID according to the positive integer in the order from left to right of the UUID or from right to left in accordance with the UUID.
  18. 根据权利要求17所述的存储介质,其特征在于,所述处理器所执行的根据所述首位值与所述末位值,获取正整数的步骤包括:The storage medium according to claim 17, wherein the step of obtaining, by the processor, the obtaining of a positive integer according to the first bit value and the last bit value comprises:
    根据所述首位值与所述末位值的和,或者根据所述首位值与所述末位值的差的绝对值,获取正整数。A positive integer is obtained according to the sum of the first bit value and the last bit value, or according to the absolute value of the difference between the first bit value and the last bit value.
  19. 根据权利要求17所述的存储介质,其特征在于,所述处理器所执行的根据所述首位值、所述末位值或者所述首位值与所述末位值获取正整数的步骤包括:The storage medium according to claim 17, wherein the step of the processor to obtain a positive integer according to the first bit value, the last bit value or the first bit value and the last bit value comprises:
    根据所述首位值加n1,所述末位值加n2,所述首位值与所述末位值之和加1,或者所述首位值与所述末位值之差的绝对值加n3,获取正整数,其中,1≤n1≤16,1≤n2≤16,1≤n3≤16。Adding n1 according to the first bit value, adding n2 to the last bit value, adding 1 to the sum of the first bit value and the last bit value, or adding n3 to the absolute value of the difference between the first bit value and the last bit value, A positive integer is obtained, where 1 ≤ n1 ≤ 16, 1 ≤ n2 ≤ 16, and 1 ≤ n3 ≤ 16.
  20. 根据权利要求15所述的存储介质,其特征在于,所述处理器所执行的在所述插入位置插入验证所述UUID的预设内容的步骤包括:The storage medium according to claim 15, wherein the step of inserting, by the processor, the verification of the preset content of the UUID at the insertion position comprises:
    在所述插入位置插入以下至少一项内容:当前时间片段,校验位。At least one of the following contents is inserted at the insertion position: a current time segment, a parity bit.
PCT/CN2018/077283 2017-10-30 2018-02-26 Method and device for generating identifier, computer device, and storage medium WO2019085350A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201711035194.9A CN107861833B (en) 2017-10-30 2017-10-30 Method and device for generating identification code, computer equipment and readable storage medium
CN201711035194.9 2017-10-30

Publications (1)

Publication Number Publication Date
WO2019085350A1 true WO2019085350A1 (en) 2019-05-09

Family

ID=61697520

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2018/077283 WO2019085350A1 (en) 2017-10-30 2018-02-26 Method and device for generating identifier, computer device, and storage medium

Country Status (2)

Country Link
CN (1) CN107861833B (en)
WO (1) WO2019085350A1 (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110149312B (en) * 2019-04-09 2021-10-15 北京奇艺世纪科技有限公司 Data processing method, device, system and computer readable storage medium
CN113055760A (en) * 2019-12-26 2021-06-29 中兴通讯股份有限公司 Log processing method, device, equipment and storage medium
CN111679932B (en) * 2020-06-01 2021-03-09 北京和德宇航技术有限公司 Error code data generation method and device, computer equipment and storage medium
CN112579566B (en) * 2020-12-14 2023-03-31 浪潮云信息技术股份公司 Distributed ID generation method and device
CN114943205A (en) * 2022-06-08 2022-08-26 北京金橙子科技股份有限公司 Method, system, storage medium and electronic equipment for generating identity recognition code UUID

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106210161A (en) * 2016-06-24 2016-12-07 中国银联股份有限公司 A kind of short chain delivers a child into method and system
CN106571953A (en) * 2016-10-21 2017-04-19 东莞市大易产业链服务有限公司 Distributed unique ID generation method
CN106603586A (en) * 2015-10-14 2017-04-26 阿里巴巴集团控股有限公司 Method for generating equipment identification, apparatus and system thereof
CN106657429A (en) * 2016-10-24 2017-05-10 珠海市魅族科技有限公司 Equipment identifier generating method and device

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102298716B (en) * 2011-09-02 2014-05-07 北京地拓科技发展有限公司 Identifier generation method and device and application method of identifier
CN102769667B (en) * 2012-06-29 2015-01-28 北京奇虎科技有限公司 Method, equipment and system for generating ID
CN104836664B (en) * 2015-03-27 2019-05-14 腾讯科技(深圳)有限公司 A kind of methods, devices and systems executing business processing
KR101650287B1 (en) * 2016-03-08 2016-08-23 주식회사 시큐브 File access control system based on volume guid and method thereof
CN107181771A (en) * 2016-03-09 2017-09-19 北京优朋普乐科技有限公司 The generation method of Quick Response Code and the response method of two-dimensional code scanning event

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106603586A (en) * 2015-10-14 2017-04-26 阿里巴巴集团控股有限公司 Method for generating equipment identification, apparatus and system thereof
CN106210161A (en) * 2016-06-24 2016-12-07 中国银联股份有限公司 A kind of short chain delivers a child into method and system
CN106571953A (en) * 2016-10-21 2017-04-19 东莞市大易产业链服务有限公司 Distributed unique ID generation method
CN106657429A (en) * 2016-10-24 2017-05-10 珠海市魅族科技有限公司 Equipment identifier generating method and device

Also Published As

Publication number Publication date
CN107861833B (en) 2020-01-21
CN107861833A (en) 2018-03-30

Similar Documents

Publication Publication Date Title
WO2019085350A1 (en) Method and device for generating identifier, computer device, and storage medium
CN112446785B (en) Cross-chain transaction method, system, device, equipment and storage medium
CN108848148B (en) Transaction information confirmation method and device based on block chain
TW559695B (en) A system and method for verifying the integrity of stored information within an electronic device
CN110535639A (en) Block chain assets disposition method and relevant device based on more asset models
US20100220853A1 (en) Method and Apparatus for Compound Hashing Via Iteration
CN110914849A (en) System and method for securing transactions in a blockchain network
EP3178011A1 (en) Method and system for facilitating terminal identifiers
CN109255232B (en) Software loading method and software loading device
CN111045856A (en) Method, apparatus and computer program product for managing application systems
CN113051622A (en) Index construction method, device, equipment and storage medium
CN111147477B (en) Verification method and device based on block chain network
US11431476B2 (en) Install time creation of forward error correction data and integrity checksums
CN111949996B (en) Method, system, equipment and medium for generating and encrypting security private key
CN111698227A (en) Information synchronization management method, device, computer system and readable storage medium
CN112052256A (en) Multi-version request returning method and device, computer equipment and readable storage medium
AU2019346606B2 (en) Validation and installation of a file system into a transient, non-persistent storage circuit
CN114978646B (en) Access right determining method, device, equipment and storage medium
Gedeon et al. Secure boot and firmware update on a microcontroller-based embedded board
CN111459899B (en) Log sharing method and device and terminal equipment
CN103198258B (en) The method of compound system and transmission data
CN112163224A (en) Android software integrity verification method and device
JP2014524210A (en) Generate variable length nonce
CN113765651A (en) Safety communication method suitable for chips in vehicle-mounted ECU
CN112637160A (en) Login verification method, device, equipment and storage medium

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 18872083

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 23.09.2020)

122 Ep: pct application non-entry in european phase

Ref document number: 18872083

Country of ref document: EP

Kind code of ref document: A1