A method and device for generating and verifying a redemption code
By generating pseudo-random numbers and keys, and generating redemption codes based on the redemption code plaintext and entity object information, the problem of high cost and low performance of redemption code generation in the existing technology is solved, and efficient and low-cost redemption code generation and verification is achieved. , supports distributed generation and avoids database dependencies.
Patent Information
- Application Number
- CN201911172196.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-11-26
- Publication Date
- 2024-12-31
- Estimated Expiration
- 2039-11-26
AI Technical Summary
The existing redemption code generation and verification methods are costly and low in performance. Especially in the scenario of massive small coupon redemption coupons, the RSA algorithm has a large overhead and strong dependence on the database, resulting in a large overhead of databases and a fast random number generation speed. Not very random.
By obtaining the random number and the key, a pseudo-random number is generated based on the sequence number in the redemption code plain text, and split it into the first pseudo-random number and the second pseudo-random number. The second pseudo-random number is spliced and encrypted with the sequence number and entity object information. A pseudo-random number serves as a key to generate a message and encrypt it, form a redemption code body, encode it to generate a target redemption code, directly integrate service data, and reduce database access.
It realizes redemption code generation with high computing efficiency and low cost, supports distributed generation, avoids reuse of redemption coupons and tampering with database information, and has higher performance.
Smart Images

Figure CN112953716B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and device for generating and verifying a redemption code. Background Art
[0002] At present, the implementation methods of redemption code generation and verification include: using system random numbers, directly reading and generating from / dev / urandom. Or using language functions, such as java's Math.random(). And using redemption codes of public key systems, such as RSA, an algorithm based on large numbers. Among them, the RSA encryption algorithm is an asymmetric encryption algorithm.
[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0004] / dev / urandom is a pseudo random number generator (PRND) provided by the Linux system. It generates data very quickly, but the randomness of the data is not very high. In addition, whether you use / dev / urandom to read random numbers directly, or get random numbers from language functions and then encode and store them in the database. When exchanging, directly query the database and then modify the database record to prevent re-exchange. These two methods are pure random numbers, and there is no association between each exchange. The database overhead for saving, verifying, and preventing re-exchange is very large.
[0005] In addition, the redemption code using the public key system is secure enough. However, for a large number of small coupons / redemption vouchers, the algorithm overhead seems to be a bit too high, such as the RSA algorithm. One is whether the distribution of the ciphertext is random. At the same time, this mechanism has a strong reliance on the database like random numbers, and the overhead is not small. Summary of the invention
[0006] In view of this, an embodiment of the present invention provides a method and device for generating and verifying a redemption code, which can solve the problems of high cost and low performance of the existing redemption code generation and verification.
[0007] To achieve the above-mentioned purpose, according to one aspect of an embodiment of the present invention, a redemption code generation method is provided, comprising obtaining a random number and a key, generating a pseudo-random number based on a serial number in a redemption code plaintext, and then splitting the pseudo-random number to obtain a first pseudo-random number and a second pseudo-random number; wherein the second pseudo-random number is concatenated with the serial number and entity object information in the redemption code plaintext into a byte array and encrypted; the first pseudo-random number is used as the encryption key; a message is generated according to the entity object information and the encrypted byte array, and then a ciphertext is obtained based on the concatenated byte array; the plaintext generated according to the serial number in the redemption code plaintext and the ciphertext are concatenated into a redemption code body to encode the redemption code body to obtain a first redemption code; the redemption code body is encrypted to encode the encrypted redemption code body to obtain a second redemption code; the first redemption code and the second redemption code are concatenated to obtain a target redemption code.
[0008] Optionally, obtain a random number and a key, including:
[0009] Encrypt the serial number in the redemption code plaintext by using a stream cipher algorithm to obtain a key random number, and extract the key random number of preset bytes as a key; and
[0010] A random number is obtained through a counter with a preset number of bits.
[0011] Optionally, obtaining a random number and a key, and generating a pseudo-random number based on a sequence number in the plain text of the redemption code, includes:
[0012] The serial number in the redemption code plaintext is used together with the random number and the key to calculate a pseudo-random number using a stream cipher algorithm.
[0013] Optionally, a message is generated according to the entity object information and the encrypted byte array, and then a ciphertext is obtained based on the concatenated byte array, including:
[0014] Extracting a preset first digit from the encrypted byte array to concatenate it with the entity object information to generate a first message;
[0015] Extracting a preset second digit from the spliced byte array to obtain a second message;
[0016] Perform an XOR operation on the first message and the second message to obtain a ciphertext.
[0017] Optionally, encrypting the redemption code body to encode the encrypted redemption code body to obtain a second redemption code includes:
[0018] Encrypt the redemption code body using a stream cipher algorithm, sum the encrypted redemption code body bytes, and then take the modulus;
[0019] The result after taking the modulus is encoded to obtain a second redemption code.
[0020] In addition, according to one aspect of an embodiment of the present invention, a redemption code generating device is provided, comprising a preparation module, configured to obtain a random number and a key, generate a pseudo-random number based on a serial number in a plain text of the redemption code, and then split the pseudo-random number to obtain a first pseudo-random number and a second pseudo-random number; wherein the second pseudo-random number is concatenated with the serial number and entity object information in the plain text of the redemption code into a byte array and encrypted; the first pseudo-random number is used as the encryption key; a message is generated according to the store number and the encrypted byte array, and then a ciphertext is obtained based on the concatenated byte array;
[0021] The generation module is used to splice the plaintext generated according to the serial number in the redemption code plaintext and the ciphertext into a redemption code body, so as to encode the redemption code body and obtain a first redemption code; encrypt the redemption code body, so as to encode the encrypted redemption code body, and then obtain a second redemption code; splice the first redemption code with the second redemption code to obtain a target redemption code.
[0022] Optionally, the preparation module obtains a random number and a key, including:
[0023] Encrypt the serial number in the redemption code plaintext by using a stream cipher algorithm to obtain a key random number, and extract the key random number of preset bytes as a key; and
[0024] A random number is obtained through a counter with a preset number of bits.
[0025] Optionally, the preparation module obtains a random number and a key, and generates a pseudo-random number based on a sequence number in the plain text of the redemption code, including:
[0026] The serial number in the redemption code plaintext is used together with the random number and the key to calculate a pseudo-random number using a stream cipher algorithm.
[0027] Optionally, the preparation module generates a message according to the store number and the encrypted byte array, and then obtains the ciphertext based on the concatenated byte array, including:
[0028] Extracting a preset first digit from the encrypted byte array to concatenate it with the store number to generate a first message;
[0029] Extracting a preset second digit from the spliced byte array to obtain a second message;
[0030] Perform an XOR operation on the first message and the second message to obtain a ciphertext.
[0031] Optionally, the generating module encrypts the redemption code body to encode the encrypted redemption code body, thereby obtaining the second redemption code, including:
[0032] Encrypt the redemption code body using a stream cipher algorithm, sum the encrypted redemption code body bytes, and then take the modulus;
[0033] The result after taking the modulus is encoded to obtain a second redemption code.
[0034] In addition, according to one aspect of an embodiment of the present invention, a redemption code verification method is provided, including obtaining a redemption code for parsing, generating a redemption code body, so as to obtain a serial number plaintext and a ciphertext in the redemption code plaintext; encrypting the serial number plaintext in the redemption code plaintext, generating a random number, and then intercepting a preset byte in the random number to obtain a first result to be processed; performing an XOR operation on the first result to be processed and the ciphertext to obtain a message, so as to parse the message to obtain entity object information and a second result to be processed; splicing the serial number plaintext, the entity object information and the first result to be processed in the redemption code plaintext into a byte array, and encrypting the spliced byte array using the random number as a key; judging whether the encrypted byte array is consistent with the second result to be processed, if so, the verification is successful, otherwise the verification fails.
[0035] Optionally, the redemption code is obtained for parsing, and a redemption code body is generated to obtain a serial number plaintext and a ciphertext in the redemption code plaintext, including:
[0036] Get the redemption code for parsing, get the encoding method through the first digit and the redemption code body through the remaining digits;
[0037] The redemption code body is parsed in an encoding manner to obtain the serial number plaintext and ciphertext in the redemption code plaintext.
[0038] Optionally, encrypting the plaintext serial number in the plaintext redemption code to generate a random number includes:
[0039] The serial number plaintext in the redemption code plaintext is parsed in an integer type binary manner to restore it to the serial number in the integer redemption code plaintext, and then the serial number plaintext in the integer type redemption code plaintext is encrypted using a stream cipher algorithm to obtain a random number.
[0040] Optionally, before concatenating the serial number plaintext, the entity object information and the first to-be-processed result in the redemption code plaintext into a byte array, the method further includes:
[0041] Determine whether the entity object information is consistent with the current entity object information to be verified. If so, concatenate the serial number plaintext in the redemption code plaintext, the entity object information and the first result to be processed into a byte array. Otherwise, verification fails.
[0042] In addition, according to one aspect of an embodiment of the present invention, a redemption code verification device is provided, including a processing module, which is used to obtain a redemption code for parsing, generate a redemption code body, so as to obtain a serial number plaintext and a ciphertext in the redemption code plaintext; encrypt the serial number plaintext in the redemption code plaintext, generate a random number, and then intercept the preset bytes in the random number to obtain a first result to be processed; perform an XOR operation on the first result to be processed and the ciphertext to obtain a message, so as to parse the message to obtain a store number and a second result to be processed; splice the serial number plaintext, the store number and the first result to be processed in the redemption code plaintext into a byte array, and encrypt the spliced byte array using the random number as a key; and a verification module, which is used to determine whether the encrypted byte array is consistent with the second result to be processed, if so, the verification is successful, otherwise the verification fails.
[0043] Optionally, the processing module obtains the redemption code for parsing and generates a redemption code body to obtain a plaintext of a serial number and a ciphertext in the plaintext of the redemption code, including:
[0044] Get the redemption code for parsing, get the encoding method through the first digit and the redemption code body through the remaining digits;
[0045] The redemption code body is parsed in an encoding manner to obtain the serial number plaintext and ciphertext in the redemption code plaintext.
[0046] Optionally, the processing module encrypts the plaintext serial number in the plaintext redemption code to generate a random number, including:
[0047] The serial number plaintext in the redemption code plaintext is parsed in an integer type binary manner to restore it to the serial number in the integer redemption code plaintext, and then the serial number plaintext in the integer type redemption code plaintext is encrypted using a stream cipher algorithm to obtain a random number.
[0048] Optionally, before the processing module concatenates the serial number plaintext, the entity object information and the first to-be-processed result in the redemption code plaintext into a byte array, the processing module includes:
[0049] Determine whether the entity object information is consistent with the current entity object information to be verified. If so, concatenate the serial number plaintext in the redemption code plaintext, the entity object information and the first result to be processed into a byte array. Otherwise, verification fails.
[0050] According to another aspect of an embodiment of the present invention, there is further provided an electronic device, including:
[0051] one or more processors;
[0052] a storage device for storing one or more programs,
[0053] When the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any of the above redemption code generation embodiments or the method described in the redemption code verification embodiments.
[0054] According to another aspect of an embodiment of the present invention, a computer-readable medium is further provided, on which a computer program is stored. When the program is executed by a processor, the program implements any of the methods described in the above-mentioned redemption code generation embodiments or the methods described in the redemption code verification embodiments.
[0055] One embodiment of the above invention has the following advantages or beneficial effects: the present invention obtains a random number and a key, generates a pseudo-random number based on the serial number in the plain text of the redemption code, and then splits the pseudo-random number to obtain a first pseudo-random number and a second pseudo-random number; wherein the second pseudo-random number is spliced with the serial number and entity object information in the plain text of the redemption code into a byte array and encrypted; the first pseudo-random number is used as the encryption key; a message is generated according to the store number and the encrypted byte array, and then a ciphertext is obtained based on the spliced byte array; the plaintext generated according to the serial number in the plain text of the redemption code and the ciphertext are spliced into the redemption code body to encode the redemption code body to obtain a first redemption code; the redemption code body is encrypted to encode the encrypted redemption code body to obtain a second redemption code; the first redemption code is spliced with the second redemption code to obtain a target redemption code. Thus, the present invention can directly integrate business data into the redemption code, with high computational efficiency and low cost.
[0056] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0058] Figure 1 is a schematic diagram of the main process of the redemption code generation method according to the first embodiment of the present invention;
[0059] Figure 2 is a schematic diagram of the main process of the redemption code generation method according to the second embodiment of the present invention;
[0060] Figure 3 is a schematic diagram of the main process of the redemption code generation method according to the third embodiment of the present invention;
[0061] Figure 4 is a schematic diagram of main modules of a redemption code generating device according to an embodiment of the present invention;
[0062] Figure 5 is a schematic diagram of the main process of the redemption code verification method according to the first embodiment of the present invention;
[0063] Figure 6 is a schematic diagram of the main process of the redemption code verification method according to the second embodiment of the present invention;
[0064] Figure 7 is a schematic diagram of main modules of a redemption code verification device according to an embodiment of the present invention;
[0065] Figure 8 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0066] Fig. 9 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0067] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0068] Figure 1 is a schematic diagram of the main process of the redemption code generation method according to the first embodiment of the present invention. The redemption code generation method may include:
[0069] Step S101, obtaining a random number and a key, generating a pseudo-random number based on a serial number in the redemption code plaintext, and then splitting the pseudo-random number to obtain a first pseudo-random number and a second pseudo-random number.
[0070] Preferably, the serial number in the redemption code plain text is encrypted by a stream cipher algorithm to obtain a key random number, and the key random number of preset bytes is extracted as the key. And the random number is obtained by a counter with preset bits.
[0071] Furthermore, when generating a pseudo-random number, the serial number in the plain text of the redemption code can be used together with the random number and the key to calculate the pseudo-random number using a stream cipher algorithm.
[0072] Step S102: The second pseudo-random number is concatenated with the serial number and entity object information in the plain text of the redemption code into a byte array and encrypted; the first pseudo-random number is used as the encryption key.
[0073] Step S103, generating a message according to the entity object information and the encrypted byte array, and then obtaining a ciphertext based on the concatenated byte array.
[0074] Preferably, a preset first digit is extracted from the encrypted byte array to be concatenated with the entity object information to generate a first message, and a preset second digit is extracted from the concatenated byte array to obtain a second message, and the first message and the second message are XORed to obtain a ciphertext.
[0075] Step S104, concatenating the plain text generated according to the serial number in the redemption code plain text and the cipher text into a redemption code body, encoding the redemption code body, and obtaining a first redemption code. Encrypting the redemption code body, encoding the encrypted redemption code body, and then obtaining a second redemption code.
[0076] Preferably, the redemption code body is encrypted using a stream cipher algorithm, the bytes of the encrypted redemption code body are summed, and then modulo is performed, and the result after modulo is encoded to obtain the second redemption code.
[0077] Step S105: concatenate the first redemption code and the second redemption code to obtain a target redemption code.
[0078] Therefore, the present invention proposes a method for generating a redemption code, which directly integrates business data into the redemption code, is simple and efficient in calculation, and does not require access to a database or other equipment throughout the process. At the same time, the generation of the redemption code is based on memory, and supports a distributed generation method with higher performance. In other words, the present invention can directly integrate business data into the redemption code, which is simple and efficient in calculation. In addition, it can well avoid the reuse of the redemption voucher after tampering with the database information.
[0079] Figure 2 is a schematic diagram of the main process of a method for generating a redemption code according to a second embodiment of the present invention. The method for generating a redemption code may include:
[0080] Step S201, obtain a random number and a key, and generate a pseudo-random number based on the serial number in the plain text of the redemption code.
[0081] Preferably, the serial number in the redemption code plain text is encrypted by a stream cipher algorithm to obtain a key random number, and the key random number of preset bytes is extracted as the key. And the random number is obtained by a counter with preset bits.
[0082] Furthermore, when generating a pseudo-random number, the serial number in the plain text of the redemption code can be used together with the random number and the key to calculate the pseudo-random number using a stream cipher algorithm.
[0083] Step S202: Evenly split the pseudo-random number to obtain a first pseudo-random number and a second pseudo-random number.
[0084] Step S203: The second pseudo-random number is concatenated with the serial number and entity object information in the plain text of the redemption code into a byte array and encrypted, and the first pseudo-random number is used as the encryption key.
[0085] Step S204: extracting a preset first digit from the encrypted byte array to concatenate with the entity object information to generate a first message, and extracting a preset second digit from the concatenated byte array to obtain a second message.
[0086] Step S205, performing an XOR operation on the first message and the second message to obtain a ciphertext.
[0087] Step S206, concatenate the plain text generated according to the serial number in the redemption code plain text and the cipher text into a redemption code body, encode the redemption code body, and obtain a first redemption code. Encrypt the redemption code body, encode the encrypted redemption code body, and then obtain a second redemption code.
[0088] Preferably, the redemption code body is encrypted using a stream cipher algorithm, the bytes of the encrypted redemption code body are summed, and then modulo is performed, and the result after modulo is encoded to obtain the second redemption code.
[0089] Step S207: concatenate the first redemption code and the second redemption code to obtain a target redemption code.
[0090] Figure 3 is a schematic diagram of the main process of a method for generating a redemption code according to a third embodiment of the present invention. The method for generating a redemption code may include:
[0091] Step S301, generate a 256-bit random number N and a 64-bit key K.
[0092] Preferably, the serial number in the redemption code plaintext is encrypted by a stream cipher (chacha20) algorithm to obtain a key random number, and the key random number of a preset byte is extracted as the key. The chacha20 algorithm performs 20 rounds of encryption in bytes, and the encryption process is to XOR the key stream with the plaintext byte by byte to obtain the ciphertext. Conversely, the decryption process is to XOR the ciphertext with the key stream again to obtain the plaintext.
[0093] The plain text of the redemption code is composed of: store number (String), card number (String), serial number (int). The serial number (int) is encrypted using a stream cipher to obtain a 512-byte key random number.
[0094] In addition, a random number is obtained by a counter with a preset number of digits. Preferably, each time a new batch of redemption codes is generated, the random number N+1 is added to increase the randomness of the system.
[0095] Step S302: The serial number in the redemption code plaintext is used as the block number ic, together with the random number N and the key K, and a stream cipher algorithm is used to calculate a 512-bit pseudo-random number R.
[0096] In an embodiment, the serial number in the plain text of the redemption code consists of a fixed 16-digit code, all uppercase letters and numbers, and easily confused characters are excluded, for a total of 32 characters.
[0097] It should be noted that the stream cipher algorithm has four inputs, namely the plaintext of the inscription, the secret key, the secret key nonce, and the round initial counter. The block number refers to the round initial counter among these four parameters, referred to as ic.
[0098] Step S303, split the 512-bit pseudo-random number R into a first pseudo-random number R1 and a second pseudo-random number R2 on average, with each segment consisting of 256 bits.
[0099] Step S304: The second pseudo-random number R2 is concatenated with the serial number and the store number in the redemption code plain text into a byte array W and encrypted, and the first pseudo-random number R1 is used as the encryption key.
[0100] In an embodiment, the concatenated byte array W is encrypted using an HMAC algorithm, wherein the HMAC algorithm is a key-dependent hash operation message authentication code.
[0101] Step S305, taking the first 18 bits of the encrypted byte array H and concatenating it with the store number to generate a 45-bit first message, and taking the first 45 bits of the concatenated byte array W to obtain a second message.
[0102] In the embodiment, the store number is encoded as 27 bits.
[0103] Step S306: perform an XOR operation on the first message and the second message to obtain a ciphertext.
[0104] Step S307, concatenate the plain text generated according to the serial number in the redemption code plain text and the cipher text into a 75-bit redemption code body.
[0105] In an embodiment, the serial number in the redemption code plain text may be converted into 30-bit binary. Preferably, 0 is used to fill in the 30 bits.
[0106] Step S308, encode the 75-bit redemption code body to obtain a 15-bit 32-decimal first redemption code.
[0107] Preferably, when encoding the redemption code body, easily confused preset characters are removed, such as: number 0 and letter O, number 1 and letter I. In this way, there are 32 encoding tables in total: 23456789ABCDEFGHJKLMNPQRSTUVWXYZ. That is, after encoding the 75-bit redemption code body, a 15-digit 32-bit number is obtained.
[0108] Step S309, encrypt the 75-bit redemption code body using a stream cipher algorithm, then sum the bytes, modulo 32, and then perform base32 encoding to obtain a second redemption code in 32-hexadecimal.
[0109] Preferably, when performing base32 encoding, the 4B / 5b encoding which is efficient and easy to implement can be used. The 4B / 5b encoding table is as follows:
[0110]
[0111] In addition, the redemption code generation method described in the present invention supports multiple encoding rules. Any character in the redemption code needs to be decrypted in accordance with the rule encoding. This means that the same character may represent different numbers in different rules. The same character A can represent any number from 0 to 31. The specific encoding rule to be used is determined by the random number HASH after the redemption code body is encrypted by ChaCha20.
[0112] Step S310: concatenate the first redemption code and the second redemption code to obtain a target redemption code.
[0113] In an embodiment, a 16-bit target redemption code may be obtained.
[0114] Figure 4 is a schematic diagram of the main modules of the redemption code generating device according to an embodiment of the present invention, such as Figure 4 As shown, the redemption code generating device 400 includes a preparation module 401 and a generation module 402. The preparation module 401 obtains a random number and a key, generates a pseudo-random number based on the serial number in the redemption code plaintext, and then splits the pseudo-random number to obtain a first pseudo-random number and a second pseudo-random number; the second pseudo-random number is spliced with the serial number and entity object information in the redemption code plaintext into a byte array and encrypted; the first pseudo-random number is used as the encryption key; a message is generated according to the entity object information and the encrypted byte array, and then a ciphertext is obtained based on the spliced byte array. The generation module 402 splices the plaintext generated according to the serial number in the redemption code plaintext and the ciphertext into a redemption code body to encode the redemption code body to obtain a first redemption code; encrypts the redemption code body to encode the encrypted redemption code body to obtain a second redemption code; splices the first redemption code with the second redemption code to obtain a target redemption code.
[0115] Preferably, the preparation module 401 obtains the random number and the key in the following manner:
[0116] The serial number in the redemption code plaintext is encrypted by a stream cipher algorithm to obtain a key random number, and the key random number of preset bytes is extracted as the key. And a random number is obtained by a counter with preset bits.
[0117] In addition, when the preparation module 401 obtains a random number and a key and generates a pseudo-random number based on the serial number in the redemption code plaintext, the serial number in the redemption code plaintext can be used together with the random number and the key to calculate the pseudo-random number using a stream cipher algorithm.
[0118] As another embodiment, the preparation module 401 generates a message according to the entity object information and the encrypted byte array, and then obtains the ciphertext based on the concatenated byte array, including:
[0119] Extract the preset first digit from the encrypted byte array to concatenate with the entity object information to generate a first message. Then, extract the preset second digit from the concatenated byte array to obtain a second message. Finally, perform an XOR operation on the first message and the second message to obtain a ciphertext.
[0120] It is also worth noting that the generating module 402 encrypts the redemption code body to encode the encrypted redemption code body to obtain the second redemption code, including:
[0121] The redemption code body is encrypted using a stream cipher algorithm, the bytes of the encrypted redemption code body are summed, and then modulo is performed, and the result after modulo is encoded to obtain a second redemption code.
[0122] It should be noted that the redemption code generation method and the redemption code generation and verification device described in the present invention have a corresponding relationship in terms of specific implementation content, so the repeated content will not be described again.
[0123] Figure 5 is a schematic diagram of the main process of the redemption code verification method according to the first embodiment of the present invention. The redemption code verification method may include:
[0124] Step S501, obtain the redemption code for parsing, generate the redemption code body, and obtain the serial number plaintext and ciphertext in the redemption code plaintext.
[0125] Preferably, the redemption code is obtained for parsing, and the encoding method is obtained through the first bit and the redemption code body is obtained through the remaining bits. Then, the redemption code body is parsed through the encoding method to obtain the serial number plaintext and ciphertext in the redemption code plaintext.
[0126] Step S502, encrypt the serial number plaintext in the redemption code plaintext to generate a random number, and then intercept the last preset bytes in the random number to obtain the first result to be processed.
[0127] Preferably, the serial number plaintext in the redemption code plaintext is parsed in an integer type binary manner to restore it to the serial number in the integer redemption code plaintext, and then the serial number plaintext in the integer type redemption code plaintext is encrypted using a stream cipher algorithm to obtain a random number.
[0128] Step S503: performing an XOR operation on the first result to be processed and the ciphertext to obtain a message, and parsing the message to obtain entity object information and a second result to be processed.
[0129] Step S504: concatenate the serial number plaintext, entity object information and the first to-be-processed result in the redemption code plaintext into a byte array, and encrypt the concatenated byte array using a random number as a key.
[0130] Preferably, before executing step S504, it can be determined whether the entity object information (e.g., store information) is consistent with the current entity object information to be verified (e.g., the current store information to be verified). If so, the serial number plaintext, entity object information and the first result to be processed in the redemption code plaintext are concatenated into a byte array. Otherwise, the verification fails.
[0131] It is worth noting that the first preset bytes in the random number are taken as the encryption key. Further, the HMAC algorithm can be used for encryption.
[0132] Step S505, determining whether the encrypted byte array is consistent with the second result to be processed, if so, the verification is successful, otherwise the verification fails.
[0133] Preferably, after the encrypted byte array is converted into bits, the first preset bits are taken, and the first preset bits are compared with the second result to be processed for consistency.
[0134] Figure 6 is a schematic diagram of the main process of the redemption code verification method according to the second embodiment of the present invention. The redemption code verification method may include:
[0135] Step S601, obtain the redemption code for parsing, extract the first digit as the base32 encoded serial number, and the remaining digits as the redemption code body.
[0136] In an embodiment, the 16-digit redemption code is parsed, and the first digit is taken out to obtain a 32-digit number as a base32 encoding serial number, and the remaining 15 32-digit numbers are taken out. Preferably, a set of Base32 encoding methods is obtained by taking the first digit as the base32 encoding serial number.
[0137] Step S602, parse the redemption code body through the base32 encoded serial number to obtain the serial number plain text and cipher text in the redemption code plain text.
[0138] Preferably, the redemption code body is parsed using Base32 encoding to obtain a 75-bit redemption code body, of which 30 bits are the serial number plaintext in the redemption code plaintext and 45 bits are the ciphertext.
[0139] Step S603, using a stream cipher algorithm to encrypt the serial number plaintext in the redemption code plaintext to obtain a random number.
[0140] Preferably, the serial number plaintext in the redemption code plaintext is parsed in an integer type binary manner to restore it to the serial number in the integer redemption code plaintext, and then the serial number plaintext in the integer type redemption code plaintext is encrypted using a stream cipher algorithm to obtain a 512-byte random number.
[0141] Step S604, intercepting the last preset byte in the random number to obtain a first result to be processed, performing an XOR operation on the first result to be processed and the ciphertext to obtain a message.
[0142] In the embodiment, the number of preset bytes is consistent with the number of R2 bytes in step S303 when generating the redemption code. For example, the last 256 bytes of the 512-byte random number are intercepted, that is, the preset bytes are 256. In addition, a 45-bit message is obtained in step S604.
[0143] Step S605, parse the message to obtain the store number and the second result to be processed.
[0144] In the embodiment, the 45-bit message contains a 27-bit store number and an 18-bit second result to be processed, wherein the second result to be processed is a result encrypted by the HMAC algorithm.
[0145] Step S606, determine whether the store number is consistent with the current store number to be verified, if they are consistent, proceed to step S607, otherwise the verification fails.
[0146] Step S607, concatenate the serial number plaintext, the store number and the first to-be-processed result in the redemption code plaintext into a byte array.
[0147] Step S608, using the random number as a key, encrypt the concatenated byte array using the HMAC algorithm.
[0148] In the embodiment, the first 256 bytes of the 512-byte random number are taken as the key of the HMAC algorithm.
[0149] Step S609, determining whether the encrypted byte array is consistent with the second result to be processed, if so, the verification is successful, otherwise the verification fails.
[0150] In an embodiment, the encrypted byte array is converted into bits and the first 18 bits are taken.
[0151] Figure 7 is a schematic diagram of the main modules of the redemption code verification device according to an embodiment of the present invention, such as Figure 7As shown, the redemption code verification device 700 includes a processing module 701 and a verification module 702. Among them, the processing module 701 obtains the redemption code for parsing, generates the redemption code body, and obtains the serial number plaintext and ciphertext in the redemption code plaintext; encrypts the serial number plaintext in the redemption code plaintext, generates a random number, and then intercepts the preset bytes in the random number to obtain the first result to be processed; the first result to be processed is XORed with the ciphertext to obtain a message, and the message is parsed to obtain the store number and the second result to be processed; the serial number plaintext, the store number and the first result to be processed in the redemption code plaintext are spliced into a byte array, and the random number is used as the key to encrypt the spliced byte array. The verification module 702 determines whether the encrypted byte array is consistent with the second result to be processed. If so, the verification is successful, otherwise the verification fails.
[0152] As a further embodiment, the processing module 701 obtains the redemption code for parsing and generates a redemption code body to obtain a serial number plaintext and a ciphertext in the redemption code plaintext, including:
[0153] Get the redemption code for parsing, get the encoding method through the first bit and the redemption code body through the remaining bits. Parse the redemption code body through the encoding method to obtain the serial number plaintext and ciphertext in the redemption code plaintext.
[0154] In addition, the processing module 701 encrypts the serial number plaintext in the redemption code plaintext to generate a random number, including:
[0155] The serial number plaintext in the redemption code plaintext is parsed in an integer type binary manner to restore it to the serial number in the integer redemption code plaintext, and then the serial number plaintext in the integer type redemption code plaintext is encrypted using a stream cipher algorithm to obtain a random number.
[0156] As a preferred embodiment, the processing module 701 can determine whether the entity object information is consistent with the current entity object information to be verified. If so, the serial number plaintext, entity object information and the first result to be processed in the redemption code plaintext are spliced into a byte array. Otherwise, the verification fails.
[0157] It should be noted that the redemption code verification method and the redemption code verification device of the present invention have a corresponding relationship in terms of specific implementation contents, so the repeated contents will not be described again.
[0158] Figure 8 An exemplary system architecture 800 is shown to which the method for generating and verifying a redemption code or the apparatus for generating and verifying a redemption code according to the embodiments of the present invention can be applied.
[0159] like Figure 8As shown, system architecture 800 may include terminal devices 801, 802, 803, a network 804, and a server 805. Network 804 is used to provide a medium for communication links between terminal devices 801, 802, 803 and server 805. Network 804 may include various connection types, such as wired, wireless communication links, or optical fiber cables, etc.
[0160] Users can use terminal devices 801, 802, and 803 to interact with server 805 through network 804 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 801, 802, and 803, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only examples).
[0161] The terminal devices 801 , 802 , and 803 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.
[0162] The server 805 may be a server that provides various services, such as a backend management server (only an example) that provides support for shopping websites browsed by users using the terminal devices 801, 802, and 803. The backend management server may analyze and process the received data such as product information query requests, and feed back the processing results (such as target push information, product information - only an example) to the terminal device.
[0163] It should be noted that the redemption code generation and verification method provided in the embodiment of the present invention are generally executed by the server 805 , and accordingly, the redemption code generation and verification device are generally arranged in the server 805 .
[0164] It should be understood that Figure 8 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0165] Reference below Fig. 9 , which shows a schematic diagram of the structure of a computer system 900 of a terminal device suitable for implementing an embodiment of the present invention. Fig. 9 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0166] like Fig. 9As shown, the computer system 900 includes a central processing unit (CPU) 901, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 902 or a program loaded from a storage part 908 into a random access memory (RAM) 903. In the RAM 903, various programs and data required for the operation of the system 900 are also stored. The CPU 901, the ROM 902, and the RAM 903 are connected to each other via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.
[0167] The following components are connected to the I / O interface 905: an input section 906 including a keyboard, a mouse, etc.; an output section 907 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 908 including a hard disk, etc.; and a communication section 909 including a network interface card such as a LAN card, a modem, etc. The communication section 909 performs communication processing via a network such as the Internet. A drive 910 is also connected to the I / O interface 905 as needed. A removable medium 911, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 910 as needed, so that a computer program read therefrom is installed into the storage section 908 as needed.
[0168] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 909, and / or installed from the removable medium 911. When the computer program is executed by the central processing unit (CPU) 901, the above-mentioned functions defined in the system of the present invention are executed.
[0169] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0170] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0171] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be set in a processor, for example, it may be described as: a processor includes a preparation module and a generation module. The names of these modules do not constitute limitations on the modules themselves in some cases.
[0172] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently and not be assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: obtaining a random number and a key, generating a pseudo-random number based on the serial number in the plain text of the exchange code, and then splitting the pseudo-random number to obtain a first pseudo-random number and a second pseudo-random number; wherein the second pseudo-random number is spliced with the serial number and entity object information in the plain text of the exchange code into a byte array and encrypted; the first pseudo-random number is used as the encryption key; a message is generated according to the entity object information and the encrypted byte array, and then a ciphertext is obtained based on the spliced byte array; the plaintext generated according to the serial number in the plain text of the exchange code and the ciphertext are spliced into an exchange code body to encode the exchange code body to obtain a first exchange code; the exchange code body is encrypted to encode the encrypted exchange code body to obtain a second exchange code; the first exchange code and the second exchange code are spliced to obtain a target exchange code.
[0173] The technical solution according to the embodiment of the present invention can solve the problems of high cost and low performance of existing redemption code generation and verification.
[0174] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for generating a redemption code, characterized in that: include: Obtain a random number and a key, generate a pseudo-random number based on the serial number in the plain text of the redemption code, and then split the pseudo-random number to obtain a first pseudo-random number and a second pseudo-random number; wherein the second pseudo-random number is concatenated with the serial number and entity object information in the plain text of the redemption code into a byte array and encrypted; the first pseudo-random number is used as the encryption key; Generate a message based on the entity object information and the encrypted byte array, and then obtain a ciphertext based on the concatenated byte array; splicing the plain text generated according to the serial number in the redemption code plain text and the cipher text into a redemption code body, so as to encode the redemption code body and obtain a first redemption code; encrypting the redemption code body, so as to encode the encrypted redemption code body and obtain a second redemption code; The first redemption code and the second redemption code are concatenated to obtain a target redemption code.
2. The method according to claim 1, characterized in that Obtain random numbers and keys, including: Encrypt the serial number in the redemption code plaintext by using a stream cipher algorithm to obtain a key random number, and extract the key random number of preset bytes as a key; and A random number is obtained through a counter with a preset number of bits.
3. The method according to claim 1, characterized in that Obtain a random number and a key, and generate a pseudo-random number based on the serial number in the redemption code plaintext, including: The serial number in the redemption code plaintext is used together with the random number and the key to calculate a pseudo-random number using a stream cipher algorithm.
4. The method according to claim 1, characterized in that Generate a message based on the entity object information and the encrypted byte array, and then obtain a ciphertext based on the concatenated byte array, including: Extracting a preset first digit from the encrypted byte array to concatenate it with the entity object information to generate a first message; Extracting a preset second digit from the spliced byte array to obtain a second message; Perform an XOR operation on the first message and the second message to obtain a ciphertext.
5. The method according to any one of claims 1 to 4, characterized in that: Encrypting the redemption code body to encode the encrypted redemption code body to obtain a second redemption code includes: Encrypt the redemption code body using a stream cipher algorithm, sum the encrypted redemption code body bytes, and then take the modulus; The result after taking the modulus is encoded to obtain a second redemption code.
6. A redemption code generating device, characterized in that: A preparation module, used to obtain a random number and a key, generate a pseudo-random number based on the serial number in the plain text of the redemption code, and then split the pseudo-random number to obtain a first pseudo-random number and a second pseudo-random number; wherein the second pseudo-random number is concatenated with the serial number and the entity object information in the plain text of the redemption code into a byte array and encrypted; the first pseudo-random number is used as the encryption key; a message is generated according to the entity object information and the encrypted byte array, and then a ciphertext is obtained based on the concatenated byte array; The generation module is used to splice the plaintext generated according to the serial number in the redemption code plaintext and the ciphertext into a redemption code body, so as to encode the redemption code body and obtain a first redemption code; encrypt the redemption code body, so as to encode the encrypted redemption code body, and then obtain a second redemption code; splice the first redemption code with the second redemption code to obtain a target redemption code.
7. A redemption code verification method, characterized in that: include: Obtain the redemption code for parsing, generate the redemption code body, and obtain the serial number plaintext and ciphertext in the redemption code plaintext; Encrypting the plaintext of the serial number in the plaintext of the redemption code to generate a random number, and then intercepting the last preset bytes in the random number to obtain a first result to be processed; The first result to be processed is XORed with the ciphertext to obtain a message, and the message is parsed to obtain the entity object information and the second result to be processed; splicing the serial number plaintext, the entity object information and the first pending result in the redemption code plaintext into a byte array, and encrypting the spliced byte array using a random number as a key; Determine whether the encrypted byte array is consistent with the second result to be processed. If so, the verification is successful, otherwise the verification fails.
8. A redemption code verification device, characterized in that: A processing module is used to obtain the redemption code for parsing, generate the redemption code body, and obtain the serial number plaintext and ciphertext in the redemption code plaintext; encrypt the serial number plaintext in the redemption code plaintext, generate a random number, and then intercept the last preset byte in the random number to obtain the first result to be processed; The first result to be processed is XORed with the ciphertext to obtain a message, and the message is parsed to obtain the entity object information and the second result to be processed; splicing the serial number plaintext, the entity object information and the first pending result in the redemption code plaintext into a byte array, and encrypting the spliced byte array using a random number as a key; The verification module is used to determine whether the encrypted byte array is consistent with the second result to be processed. If so, the verification is successful, otherwise the verification fails.
9. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 5 or the method according to claim 7.
10. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 5 or the method according to claim 7 is implemented.