One-time password generation and verification method, device, equipment and storage medium
By generating passwords at the password generation end and verifying them at the verification end, the problem of offline one-time password generation and verification occupying storage space is solved, thereby reducing the storage space occupied.
Patent Information
- Application Number
- CN202111550150.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-17
- Publication Date
- 2025-11-28
- Estimated Expiration
- 2041-12-17
AI Technical Summary
Existing offline one-time password generation and verification methods require additional maintenance of the password database on the verification end, which consumes storage space.
The time key parameter and sequence key parameter are calculated by the password generation terminal to encrypt the preset data, generate a one-time password, and verify it at the password verification terminal, thereby reducing the storage space occupied.
It enables offline one-time password generation and verification, reducing storage space usage.
Smart Images

Figure CN116266227B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present application relate to the technical field of intelligent lock, in particular to a one-time password generation and verification method, device and equipment and storage medium. BACKGROUND
[0002] The one-time password function of the intelligent lock is to generate a one-time password in a valid time period by a password generation end, and then save the one-time password to a verification end, and then input the one-time password by a user to the verification end for verification.
[0003] In order to make the one-time password function applicable offline, the same one-time password generation algorithm is usually used in the password generation end and the verification end in the prior art, and a large number of one-time passwords are generated and saved to a one-time password library in the verification end, and when the user uses the one-time password generated by the password generation end for verification, the verification end compares the input one-time password with the one-time password library, and if the input one-time password exists in the one-time password library, the verification is passed. However, this offline one-time password generation and verification method needs to maintain the one-time password library of the verification end, which occupies storage space. SUMMARY
[0004] Embodiments of the present application provide a one-time password generation and verification method, device, equipment and storage medium to realize offline one-time password generation and verification and reduce the occupation of storage space.
[0005] In a first aspect, the present application provides a one-time password generation method applied to a password generation end, which comprises:
[0006] According to the cycle start time of the one-time password, a time key parameter is calculated, and a time parameter is determined according to the time key parameter;
[0007] A serial number key parameter is determined according to the serial number of the one-time password, and a preset data is encrypted according to the time key parameter and the serial number key parameter to determine an encrypted number;
[0008] The time parameter, the serial number key parameter and the encrypted number are combined into a one-time password, and the one-time password is provided to the user, so that the user inputs the one-time password in the password verification end for verification.
[0009] In a second aspect, the present application further provides a one-time password verification method applied to a password verification end, which comprises:
[0010] A user input one-time password is obtained, and a to-be-verified time parameter, a serial number key parameter and a to-be-verified encrypted number are determined according to the user input one-time password;
[0011] According to the current time, a current time key parameter is calculated, and according to the current time key parameter, a current time parameter is determined;
[0012] According to the to-be-verified time parameter and the current time parameter, a target time key parameter is determined;
[0013] According to the target time key parameter and the serial number key parameter, preset data is encrypted to determine a current encrypted number;
[0014] According to the current encrypted number and the to-be-verified encrypted number, a one-time password input by a user is verified.
[0015] In a third aspect, an embodiment of the present application further provides a one-time password generation device, which is arranged at a password generation end, and comprises:
[0016] A time parameter determination module is configured to calculate a time key parameter according to a cycle start time of the one-time password, and determine a time parameter according to the time key parameter;
[0017] An encrypted number determination module is configured to determine a serial number key parameter according to a serial number of the one-time password, and encrypt preset data according to the time key parameter and the serial number key parameter to determine an encrypted number;
[0018] A one-time password generation module is configured to combine the time parameter, the serial number key parameter and the encrypted number into a one-time password, and provide the one-time password to a user, so that the user inputs the one-time password at a password verification end for verification.
[0019] In a fourth aspect, an embodiment of the present application further provides a one-time password verification device, which is arranged at a password verification end, and comprises:
[0020] A one-time password analysis module is configured to acquire a one-time password input by a user, and determine a to-be-verified time parameter, a serial number key parameter and a to-be-verified encrypted number according to the one-time password input by the user;
[0021] A current time parameter determination module is configured to calculate a current time key parameter according to a current time, and determine a current time parameter according to the current time key parameter;
[0022] A target time key parameter determination module is configured to determine a target time key parameter according to the to-be-verified time parameter and the current time parameter;
[0023] A current encrypted number determination module is configured to encrypt preset data according to the target time key parameter and the serial number key parameter to determine a current encrypted number;
[0024] The one-time password verification module is used for verifying the one-time password input by the user according to the current encrypted number and the encrypted number to be verified.
[0025] In a fifth aspect, an embodiment of the present application further provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the one-time password generation method or the one-time password verification method according to any of the embodiments of the present application when executing the program.
[0026] In a sixth aspect, an embodiment of the present application further provides a storage medium containing computer executable instructions, which are used for executing the one-time password generation method or the one-time password verification method according to any of the embodiments of the present application when executed by a computer processor.
[0027] The embodiment of the present application calculates the time key parameter according to the cycle start time of the one-time password by the password generation end, determines the time parameter according to the time key parameter, determines the serial number key parameter according to the serial number of the one-time password, encrypts the preset data according to the time key parameter and the serial number key parameter, determines the encrypted number, combines the time parameter, the serial number key parameter and the encrypted number into the one-time password, and the user inputs the one-time password at the password verification end for verification. The embodiment of the present application solves the problem of the off-line one-time password generation and verification mode in the prior art, needs to additionally maintain the one-time password library of the verification end, and occupies the storage space. The embodiment of the present application realizes the off-line one-time password generation and verification, and reduces the occupation of the storage space. BRIEF DESCRIPTION OF DRAWINGS
[0028] Figure 1 is a flowchart of the one-time password generation method in the first embodiment of the present application;
[0029] Figure 2 is another flowchart of the one-time password generation method in the second embodiment of the present application;
[0030] Figure 3 is a flowchart of the one-time password verification method in the third embodiment of the present application;
[0031] Figure 4 is another flowchart of the one-time password verification method in the fourth embodiment of the present application;
[0032] Figure 5 is a structural schematic diagram of the one-time password generation device in the fifth embodiment of the present application;
[0033] Figure 6 is a structural schematic diagram of the one-time password verification device in the sixth embodiment of the present application;
[0034] Figure 7 is a structural schematic diagram of a computer device in embodiment seven of the present application. DETAILED DESCRIPTION
[0035] The present application will be further described below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are intended to be merely illustrative of the present application and not in limitation thereof. It should also be noted that, for the purpose of description, only the parts related to the present application are shown in the drawings rather than all the parts.
[0036] Embodiment one
[0037] Figure 1 is a flowchart of a one-time password generation method provided in embodiment one of the present application. The present embodiment is applicable to the case where the password generation end generates a one-time password for the user to verify the one-time password when the password generation end and the password verification end are offline. The method can be executed by a one-time password generation device, which can be realized by software and / or hardware and is generally integrated in the password generation end, typically, in a cloud server.
[0038] As shown in Figure 1 , the technical solution of the present embodiment includes the following steps:
[0039] S110, calculate the time key parameter according to the cycle start time of the one-time password, and determine the time parameter according to the time key parameter.
[0040] In the present embodiment, there are three parties, the password generation end, the password verification end and the client. Typically, the password generation end can be a cloud server, the password verification end is a lock device end, and the client is an application program set in a smart computer device.
[0041] The cycle start time refers to the start time of the one-time password cycle, which is set in advance. For example, if it is set in advance that the lock device supports generating 16 one-time passwords every 24 hours, the cycle start time can be set to zero o'clock of the day.
[0042] The time key parameter is a parameter related to time used to calculate the encryption key, and the time parameter is used to represent information related to the effective start time of the currently generated one-time password.
[0043] In the embodiment of the present application, the purpose of calculating the time key parameter is that the encryption key can be generated according to the time key parameter subsequently, so that the preset data is encrypted by the encryption key to determine the encryption number. In the one-time password verification, whether the input one-time password can pass the verification is judged by comparing the encryption number. The purpose of calculating the time parameter is that, in the one-time password verification, whether the input one-time password is within the effective time period of the one-time password is judged by comparing the time parameter.
[0044] In S120, the sequence number key parameter is determined according to the sequence number of the one-time password, and the preset data is encrypted according to the time key parameter and the sequence number key parameter to determine the encryption number.
[0045] The sequence number of the one-time password refers to the sequence generated by the one-time password in a one-time password period, and the maximum value is determined according to the maximum number of one-time passwords that can be supported in a one-time password period. For example, if it is set in advance that the lock device supports generating 16 one-time passwords per 24 hours, the sequence number of the first one-time password generated on the same day can be 0. The sequence number key parameter is an identifier for indicating the sequence number of the one-time password.
[0046] Optionally, the encryption key can be generated according to the time key parameter and the sequence number key parameter by a fixed key generation algorithm. For example, the key generation algorithm can be a standard HASH algorithm, for example, it can be HMAC-SHA-1 (Hash-based Message Authentication Code-Secure Hash Algorithm 1, Hash Message Authentication Code-Secure Hash Algorithm 1). The key generation algorithm is not limited in the embodiment.
[0047] In the embodiment of the present application, in a one-time password period, since the time key parameter is obtained according to the starting time of the one-time password period, the starting time of the period is the same each time the one-time password is generated. In a one-time password period, the sequence number key parameter is accumulated each time the one-time password is generated until the maximum value of the sequence number of the one-time password is reached, and the sequence number key parameter starts to accumulate again after the one-time password period is updated.
[0048] In the embodiment of the present application, after the encryption key is generated, the preset data is encrypted according to the encryption key to obtain the encryption number.
[0049] Optionally, the preset data can be fixed 16-byte data, and after the preset data is encrypted by the generated encryption key, 16-byte intermediate data is obtained. After the intermediate data is reduced, the encrypted number is obtained. The preset data can also be set as data with a smaller byte number, and after the preset data is encrypted by the generated encryption key, the encrypted number is directly obtained.
[0050] The encryption algorithm used for encrypting the preset data by the encryption key can be AES (Advanced Encryption Standard), but the encryption algorithm is not limited in the embodiment. If the intermediate data needs to be reduced, the reduction algorithm can be realized by Truncate in the HOTP (HMAC-based One-Time Password) standard, and Truncate represents a reduction function, but the selection of the reduction function is not limited in the embodiment. Meanwhile, the number of bits of the encrypted number is also not limited in the embodiment.
[0051] In S130, the time parameter, the serial number key parameter and the encrypted number are combined to obtain a one-time password, and the one-time password is provided to the user, so that the user inputs the one-time password in the password verification end for verification.
[0052] In the embodiment, the time parameter, the serial number key parameter and the encrypted number are combined to obtain a one-time password. The combination mode can be splicing, or exclusive or operation with preset initial data, and the combination mode is not limited in the embodiment, but it needs to be noted that the combination mode needs to be reversely restored, and the reverse combination mode matched with the combination mode needs to be pre-stored in the password verification end, so that the password verification end can restore the time parameter, the serial number key parameter and the encrypted number from the one-time password input by the user through the reverse combination mode.
[0053] In a specific example, after the password generation end generates the one-time password, the one-time password is sent to the client, the user of the client provides the one-time password to the temporary visitor, and the temporary visitor inputs the obtained one-time password in the password verification end for verification. In another specific example, the temporary visitor can also submit a verification application in the temporary visitor client, and after the verification application is passed by the authority user in the authority user client, the password generation end generates the one-time password, sends the one-time password to the temporary visitor client, and the temporary visitor inputs the obtained one-time password in the password verification end for verification.
[0054] The technical scheme of the embodiment comprises the following steps: the password generation end calculates a time key parameter according to a period start time of the one-time password, determines a time parameter according to the time key parameter, determines a serial number key parameter according to a serial number of the one-time password, encrypts preset data according to the time key parameter and the serial number key parameter, determines an encrypted number, combines the time parameter, the serial number key parameter and the encrypted number into the one-time password, and the user inputs the one-time password into the password verification end for verification. The one-time password generation and verification mode in the prior art needs to additionally maintain a one-time password library of the password verification end, and occupies storage space. The technical scheme of the embodiment realizes the generation of the one-time password when the password generation end and the password verification end are offline, and reduces the occupation of storage space.
[0055] Embodiment two
[0056] Figure 2 is a flowchart of a one-time password generation method provided by the embodiment two of the application. The embodiment two of the application further specifically realizes the process of calculating the time key parameter and the process of determining the encrypted number on the basis of the above-mentioned embodiment.
[0057] Correspondingly, as shown in Figure 2 , the technical scheme of the embodiment of the application specifically comprises the following steps:
[0058] S210, converting the period start time of the one-time password into universal coordinated time, and obtaining an integer by dividing the universal coordinated time by a valid time period of the one-time password, and taking the integer as the time key parameter.
[0059] The universal coordinated time is also referred to as UTC (Universal Time Coordinated, coordinated universal time), which can be expressed by the number of seconds from 00:00:00 on January 1, 1970 to the period start time. The valid time period of the one-time password refers to the length of time from the generation of the one-time password to the invalidation of the one-time password. For example, the valid time period of the one-time password can be half an hour. Since the universal coordinated time is expressed by the number of seconds, the valid time period also needs to be expressed by the number of seconds.
[0060] For example, if the universal coordinated time corresponding to the zero point of a day is 1633017600s, and the valid time period of the one-time password is half an hour, i.e. 30*60s, therefore, the time key parameter is 1633017600 / (30*60) = 907232.
[0061] S220, taking the number corresponding to the preset bit of the time key parameter as the time parameter.
[0062] Exemplarily, a number corresponding to the last six bits of the time key parameter can be taken as the time parameter. Taking the time key parameter 907232 as an example, after converting 907232 into binary, the number corresponding to the last six bits is taken, converted into decimal, and the time parameter corresponding thereto is calculated to be 32.
[0063] S230, determining the serial number key parameter according to the serial number of the one-time password.
[0064] The serial number of the one-time password is the cumulative number of the one-time passwords generated in one one-time password period. For example, the serial number key parameter corresponding to the first one-time password generated in one one-time password period can be 0.
[0065] S240, generating the encryption key according to the time key parameter, the serial number key parameter, the device identifier, and the preset token.
[0066] The device identifier is the device identifier that can uniquely represent the password verification end and is sent by the password verification end to the password generation end. The device identifier can be the SN (Series Number) of the device, or the Mac address, i.e., the physical address or the hardware address. The type of the device identifier is not limited in the embodiment. In the embodiment, after the password verification end and the password generation end establish a connection, the password verification end sends the device identifier to the password generation end.
[0067] The preset token is the token that is sent by the password generation end to the password verification end after the password verification end and the password generation end establish a connection, and the password verification end accesses the password generation end according to the token.
[0068] In the embodiment, by adding the device identifier and the preset token when generating the encryption key, different encryption keys can be generated for different password verification end devices, thereby improving the security of the one-time password generation.
[0069] S250, encrypting the preset data according to the encryption key to obtain intermediate data.
[0070] S260, performing reduction processing on the intermediate data to obtain the encrypted number. For example, the preset data can be fixed 16-byte data, the preset data is encrypted by using the encryption key to obtain the intermediate data.
[0071] The reduction algorithm has been exemplified in the above embodiment, and will not be repeated here.
[0072] S270, combine the time parameter, the serial number key parameter and the encrypted number into a one-time password to provide the one-time password to the user to make the user input the one-time password to the password verification end to verify.
[0073] The combination of the time parameter, the serial number key parameter and the encrypted number and the way of providing the one-time password to the user have been described in the above embodiment, and will not be repeated here.
[0074] Embodiment three
[0075] Figure 3 is a flowchart of a one-time password verification method provided by the third embodiment of the present application, the third embodiment can be applied to the case that the password verification end verifies the one-time password input by the user when the password generation end and the password verification end are offline, and the method can be executed by a one-time password verification device, which can be realized by software and / or hardware and is generally integrated in the password verification end, typically, in a lock device.
[0076] As shown in Figure 3 , the technical scheme of the embodiment of the present application specifically includes the following steps:
[0077] S310, obtain the one-time password input by the user and determine the to-be-verified time parameter, the to-be-verified serial number key parameter and the to-be-verified encrypted number according to the one-time password input by the user.
[0078] After the user inputs the one-time password in the password verification end, the password verification end reversely combines the one-time password input by the user to extract the to-be-verified time parameter, the to-be-verified serial number key parameter and the to-be-verified encrypted number.
[0079] In the embodiment of the present application, after the password generation end and the password verification end are connected, various algorithms are synchronized. Since the password generation end combines the time parameter, the serial number key parameter and the encrypted number into a one-time password through a combination algorithm, the password verification end needs to pre-store a reverse combination algorithm to restore the one-time password input by the user into the to-be-verified time parameter, the to-be-verified serial number key parameter and the to-be-verified encrypted number.
[0080] S320, calculate a current time key parameter according to the current time and determine a current time parameter according to the current time key parameter.
[0081] The current time is the current system time of the password verification end, and in the embodiment of the present application, the current time key parameter is calculated according to the current time in the same way as the password generation end, and the current time parameter is determined according to the current time key parameter in the same way as the password generation end.
[0082] Specifically, the current time is converted into the world coordinated time, and an integer obtained by dividing the world coordinated time by the validity time period of the one-time password is taken as the current time key parameter. A number corresponding to a preset bit of the current time key parameter is taken as the current time parameter.
[0083] For example, if the current time converted into the world coordinated time is 1633050000, the current time key parameter is 1633050000 / (30*60)=907250. A number corresponding to the last six bits of the current time key parameter is taken as the time parameter. Taking the current time key parameter 907250 as an example, the number corresponding to the last six bits of 907250 converted into binary is taken as a decimal number, and the time parameter corresponding thereto is calculated to be 50.
[0084] S330, determining a target time key parameter according to the to-be-verified time parameter and the current time parameter.
[0085] In the embodiment of the application, the to-be-verified one-time password can be determined to be in the current one-time password cycle by comparing the to-be-verified time parameter and the current time parameter. Since the time key parameter is obtained according to the cycle start time of the one-time password in a one-time password cycle, the cycle start time is the same each time the one-time password is generated, and thus each time key parameter generated in a one-time password cycle is the same. If the to-be-verified one-time password is determined to be in the current one-time password cycle, a target time key parameter matching the one-time password cycle can be calculated according to the current time key parameter, the to-be-verified time parameter and the current time parameter.
[0086] S340, encrypting preset data according to the target time key parameter and the serial number key parameter to determine a current encrypted number.
[0087] In the embodiment of the application, the password verification end generates an encryption key according to the target time key parameter and the serial number key parameter in the same way as the password generation end, and encrypts preset data by using the encryption key to determine an encrypted number.
[0088] Specifically, a current encryption key is generated according to the target time key parameter, the serial number key parameter, the device identifier and a preset token. The preset data is encrypted according to the current encryption key to obtain current intermediate data. The current intermediate data is processed to obtain a current encrypted number.
[0089] S350, verifying the one-time password input by the user according to the current encrypted number and the to-be-verified encrypted number.
[0090] The password verification end compares the current encryption number calculated with the to-be-verified encryption number obtained by inversely combining the one-time password input by the user, and if the current encryption number and the to-be-verified encryption number are the same, it is determined that the one-time password input by the user is verified, otherwise, it is determined that the one-time password input by the user is not verified.
[0091] The technical scheme of the embodiment obtains the one-time password input by the user through the password verification end, parses the one-time password to obtain the to-be-verified time parameter, the serial number key parameter and the to-be-verified encryption number, calculates the current time key parameter and determines the current time parameter, determines the target time key parameter according to the to-be-verified time parameter and the current time parameter, encrypts the preset data according to the target time key parameter and the serial number key parameter, determines the current encryption number, and verifies the one-time password input by the user by comparing the current encryption number with the to-be-verified encryption number. The password verification end and the password generation end adopt the same time key parameter calculation method, time parameter determination method and encryption number determination method, which solves the problem of the offline one-time password generation and verification method in the prior art, which needs to maintain an additional one-time password library of the verification end and occupies storage space, realizes the verification of the one-time password when the password generation end and the password verification end are offline, and reduces the occupation of storage space.
[0092] Embodiment Four
[0093] Figure 4 is a flowchart of another one-time password verification method provided by Embodiment Four of the application, and the embodiment of the application further specifies the process of determining the target time key parameter according to the to-be-verified time parameter and the current time parameter and the process of verifying the one-time password input by the user on the basis of the above-mentioned embodiments.
[0094] Correspondingly, as shown in Figure 4 The technical scheme of the embodiment of the application specifically comprises the following steps:
[0095] S410, obtaining the one-time password input by the user and determining the to-be-verified time parameter, the serial number key parameter and the to-be-verified encryption number according to the one-time password input by the user.
[0096] The above-mentioned embodiments have described the process of restoring the one-time password input by the user into the to-be-verified time parameter, the serial number key parameter and the to-be-verified encryption number through the inverse combination algorithm, which will not be described herein again.
[0097] S420, calculating the current time key parameter according to the current time and determining the current time parameter according to the current time key parameter.
[0098] It needs to be explained that the password verification end calculates the current time key parameter according to the current time, and the current time parameter is determined according to the current time key parameter, which needs to be consistent with the password generation end, and this embodiment will not be repeated here.
[0099] S430, according to the time parameter to be verified, the one-time password period and the effective time period of the one-time password, determine the time threshold.
[0100] In one one-time password period, if the one-time password input by the user is correct, the time parameter to be verified is determined according to the time key parameter calculated according to the start time of the one-time password period, and the ratio of the one-time password period to the effective time period of the one-time password is added to the time parameter to be verified as the time threshold.
[0101] For example, if the one-time password period is set to 24h in advance, the effective time period of the one-time password is half an hour, and the time parameter to be verified obtained by reverse combination according to the one-time password input by the user is 32, then the time threshold is 32+(24*60*60 / 30*60) = 80.
[0102] S440, judge whether the current time parameter is greater than or equal to the time parameter to be verified, if yes, execute S450, otherwise execute S470.
[0103] S450, judge whether the current time parameter is less than or equal to the time threshold, if yes, execute S460, otherwise execute S4180.
[0104] S460, the difference between the current time key parameter and the current time parameter and the sum of the time parameter to be verified is taken as the target time key parameter.
[0105] If the current time parameter falls within the range of the time parameter to be verified and the time threshold, it means that the one-time password input by the user to be verified is in the current one-time password period. The difference between the current time key parameter and the current time parameter and the sum of the time parameter to be verified can be directly taken as the target time key parameter.
[0106] For example, taking the time parameter to be verified as 32 and the time threshold as 80, if the current time key parameter is 907250 and the current time parameter is 50, it means that the one-time password input by the user to be verified is in the current one-time password period, and the target time key parameter is calculated as 907250-50+32 = 907232.
[0107] S470, judge whether the time threshold is greater than or equal to the value matched with the preset bit, if yes, execute S480, otherwise execute S4180.
[0108] In the embodiment of the present application, since the time parameter is a number corresponding to the last preset number of bits of the time key parameter, the time parameter has an overflow condition.
[0109] For example, when the time parameter is the last 6 bits of the time key parameter, the one-time password period is 24 hours, the one-time password period is updated in the early morning, if the time parameter to be verified is 32, the time threshold is 80, in a one-time password period, the current time key parameter corresponding to 09:00:00 is 907250, the current time parameter corresponding to 09:00:00 is 50, which is within the range of the time parameter to be verified and the time threshold. However, the current time key parameter corresponding to 23:00:00 of the same day is 907278, the current time parameter corresponding to 23:00:00 is 14, which is in the case of overflow of the current time parameter.
[0110] If the current time parameter is less than the time parameter to be verified, the time threshold is greater than or equal to the value matched with the preset bit, and the current time parameter is less than the difference between the time threshold and the value matched with the preset bit, it is indicated that the current time parameter is overflow, the one-time password to be verified input by the user is within the current one-time password period, but the target time key parameter needs to be calculated according to the current time key parameter, the current time parameter, the time parameter to be verified and the value matched with the preset bit. Except for the above conditions and the condition that the current time parameter is within the range of the time parameter to be verified and the time threshold, the remaining conditions indicate that the one-time password to be verified input by the user is not within the current one-time password period, and the one-time password verification fails.
[0111] For example, when the time parameter is the last 6 bits of the time key parameter, 6 times of 2 is 64, and the value matched with the preset bit is 64. When the current time parameter is 14, since the current time parameter 14 is less than the time parameter to be verified 32, and the time threshold is greater than 64, the difference between the time threshold 80 and 64 is 16, and the current time parameter 14 is less than 16, so the one-time password to be verified input by the user is within the current one-time password period.
[0112] S480, determining whether the current time parameter is less than the difference between the time threshold and the value matched with the preset bit, if yes, performing S490, otherwise performing S4180.
[0113] S490, subtracting the value obtained by subtracting the value matched with the preset bit from the sum of the difference between the current time key parameter and the current time parameter and the time parameter to be verified, as the target time key parameter.
[0114] Taking the above example as an example, at 23:00:00 of the day, the current time key parameter is 907278, the current time parameter is 14, and the target time key parameter is 907278-14+32-64=907232.
[0115] S4100, encrypt the preset data according to the target time key parameter and the serial number key parameter, and determine a current encryption number.
[0116] In the embodiment of the application, the password verification end generates an encryption key according to the target time key parameter and the serial number key parameter, and encrypts the preset data through the encryption key to determine an encryption number, which will not be described herein.
[0117] S4110, determine whether the current encryption number is the same as the encryption number to be verified, if yes, execute S4120, otherwise execute S4180.
[0118] If the current encryption number is not the same as the encryption number to be verified, it means that the verification fails at this time, otherwise, further verification is continued.
[0119] S4120, obtain current one-time password cycle start time information.
[0120] In the embodiment of the application, two static variables or global variables are set, the current one-time password cycle start time information is used to save the start time of the current one-time password cycle, and the initial value of the current one-time password cycle start time information can be set to 0. The bitmap is used to save the number of one-time passwords generated in the current one-time password cycle, and the byte length of the bitmap is related to the maximum number of one-time passwords supported in a one-time password cycle. Each bit represents a one-time password. For example, if a maximum of 16 one-time passwords are generated in 24 hours, the length of the bitmap is 2 bytes; if a maximum of 32 one-time passwords are generated, the length of the bitmap is 4 bytes.
[0121] S4130, determine whether the target time key parameter is the same as the current one-time password cycle start time information, if yes, execute S4140, otherwise execute S4160.
[0122] If the target time key parameter is the same as the current one-time password cycle start time information, it means that the one-time password to be verified is in a valid one-time password cycle.
[0123] S4140, determine whether the bit position matched with the serial number key parameter in the bitmap satisfies the numerical condition, if yes, execute S4150, otherwise execute S4180.
[0124] In the embodiment of the present application, the initial value of the bitmap can be set as 0, and if the one-time password corresponding to the serial number bit is successfully verified, the value of the bitmap is updated to 1. Therefore, after the target time key parameter is verified, it is determined according to the serial number key parameter whether the value of the bitmap at the corresponding position is 0. If it is 1, it means that the one-time password has been successfully verified, and at this time, it is still a verification failure. If it is 0, it means that the one-time password verification is successful, and at this time, the bitmap needs to be updated according to the serial number key parameter. For example, when the serial number key parameter is 0, if the one-time password verification is successful, the first position of the bitmap is updated to 1.
[0125] S4150, determining that the one-time password is successfully verified, and updating the value of the bit in the bitmap corresponding to the serial number key parameter.
[0126] S4160, determining whether the target time key parameter is greater than the current one-time password cycle start time information. If yes, S4170 is executed, otherwise S4180 is executed.
[0127] When the target time key parameter is greater than the current one-time password cycle start time information, it means that the one-time password cycle start time saved locally by the password verification end has expired. According to the target time key parameter, the local one-time password cycle start time is updated to a new one-time password cycle start time, and the bitmap is emptied to enter a new round of one-time password cycle.
[0128] At the same time, the value of the bit corresponding to the serial number key parameter in the bitmap is updated to indicate that the one-time password has been successfully verified, so that the one-time password can be successfully verified only once.
[0129] S4170, determining that the one-time password is successfully verified, and updating the value of the bit in the bitmap corresponding to the serial number key parameter.
[0130] S4180, determining that the one-time password is not successfully verified.
[0131] In the embodiment of the present application, if the target time key parameter is less than the current one-time password cycle start time information, it means that the one-time password input by the user is no longer in the current one-time password cycle, and is an expired one-time password. At this time, the one-time password is not successfully verified. Optionally, the user can be prompted that the one-time password has expired, and if it is determined according to the bitmap that the number of one-time passwords generated in the current one-time password cycle has not reached the maximum number of one-time passwords, the user can be prompted to obtain a one-time password again.
[0132] Embodiment five
[0133] Figure 5 is a structural schematic diagram of a one-time password generation device provided by the fifth embodiment of the present application. The device can be implemented by software and / or hardware, and is generally integrated in a password generation end, typically, in a cloud server. The device comprises a time parameter determination module 510, an encryption number determination module 520, and a one-time password generation module 530. Wherein:
[0134] The time parameter determination module 510 is configured to calculate a time key parameter according to a period start time of the one-time password, and determine a time parameter according to the time key parameter.
[0135] The encryption number determination module 520 is configured to determine a serial number key parameter according to a serial number of the one-time password, and encrypt preset data according to the time key parameter and the serial number key parameter to determine an encryption number.
[0136] The one-time password generation module 530 is configured to combine the time parameter, the serial number key parameter, and the encryption number into a one-time password, so as to provide the one-time password to a user, and enable the user to input the one-time password in a password verification end for verification.
[0137] The technical solution of the embodiment calculates a time key parameter according to a period start time of a one-time password by a password generation end, determines a time parameter according to the time key parameter, determines a serial number key parameter according to a serial number of the one-time password, encrypts preset data according to the time key parameter and the serial number key parameter to determine an encryption number, combines the time parameter, the serial number key parameter, and the encryption number into a one-time password, and enables a user to input the one-time password in a password verification end for verification. The solution solves the problem of the prior art that an offline one-time password generation and verification mode needs to maintain a one-time password library of the verification end, and occupies storage space, realizes offline one-time password generation and verification, and reduces the occupation of storage space.
[0138] On the basis of the above embodiment, the time parameter determination module 510 comprises:
[0139] A time key parameter determination unit is configured to convert the period start time of the one-time password into a universal time coordinated, and take an integer obtained by dividing the universal time coordinated by a valid time period of the one-time password as the time key parameter.
[0140] A time parameter determination unit is configured to take a number corresponding to a preset bit of the time key parameter as the time parameter.
[0141] On the basis of the above embodiment, the encryption number determination module 520 comprises:
[0142] The encryption key generation unit is configured to generate an encryption key according to a time key parameter, a serial number key parameter, a device identifier, and a preset token.
[0143] The intermediate data acquisition unit is configured to encrypt preset data according to the encryption key to obtain intermediate data.
[0144] The encrypted number acquisition unit is configured to perform reduction processing on the intermediate data to obtain an encrypted number.
[0145] The one-time password generation device provided by the embodiments of the present application can execute the one-time password generation method provided by any of the embodiments of the present application, and has the corresponding function modules and beneficial effects of the execution method.
[0146] Embodiment six
[0147] Figure 6 FIG. 6 is a structural schematic diagram of a one-time password verification device provided by the sixth embodiment of the present application. The device can be realized by software and / or hardware, and is generally integrated in a password verification end, typically, in a lock device. The device includes a one-time password analysis module 610, a current time parameter determination module 620, a target time key parameter determination module 630, a current encrypted number determination module 640, and a one-time password verification module 650. Among them:
[0148] The one-time password analysis module 610 is configured to acquire a one-time password input by a user, and determine a to-be-verified time parameter, a serial number key parameter, and a to-be-verified encrypted number according to the one-time password input by the user.
[0149] The current time parameter determination module 620 is configured to calculate a current time key parameter according to a current time, and determine a current time parameter according to the current time key parameter.
[0150] The target time key parameter determination module 630 is configured to determine a target time key parameter according to the to-be-verified time parameter and the current time parameter.
[0151] The current encrypted number determination module 640 is configured to encrypt preset data according to the target time key parameter and the serial number key parameter, and determine a current encrypted number.
[0152] The one-time password verification module 650 is configured to verify the one-time password input by the user according to the current encrypted number and the to-be-verified encrypted number.
[0153] The technical scheme of the embodiment is that after the password verification end obtains the one-time password input by the user, the one-time password is parsed to obtain a to-be-verified time parameter, a serial number key parameter and a to-be-verified encrypted number, a current time key parameter is calculated and a current time parameter is determined, the target time key parameter is determined according to the to-be-verified time parameter and the current time parameter, the preset data is encrypted according to the target time key parameter and the serial number key parameter, the current encrypted number is determined, and the one-time password input by the user is verified by comparing the current encrypted number with the to-be-verified encrypted number. The password verification end and the password generation end adopt the same time key parameter calculation mode, time parameter determination mode and encrypted number determination mode, solve the problem of the off-line one-time password generation and verification mode in the prior art, the need for additional maintenance of the one-time password library of the verification end and the occupation of storage space, realize the verification of the one-time password when the password generation end and the password verification end are off-line, and reduce the occupation of storage space.
[0154] On the basis of the above embodiment, the target time key parameter determination module 630 comprises:
[0155] The time threshold determination unit is configured to determine a time threshold according to the to-be-verified time parameter, the one-time password period and the effective time period of the one-time password.
[0156] The first target time key parameter determination unit is configured to, if it is determined that the current time parameter is greater than or equal to the to-be-verified time parameter and less than or equal to the time threshold, take the sum of the difference between the current time key parameter and the current time parameter and the to-be-verified time parameter as the target time key parameter.
[0157] The second target time key parameter determination unit is configured to, if it is determined that the current time parameter is less than the to-be-verified time parameter, the time threshold is greater than or equal to the value matched with the preset bit, and the current time parameter is less than the difference between the time threshold and the value matched with the preset bit, take the value obtained by subtracting the value matched with the preset bit from the sum of the difference between the current time key parameter and the current time parameter and the to-be-verified time parameter as the target time key parameter.
[0158] On the basis of the above embodiment, the one-time password verification module 650 comprises:
[0159] The current one-time password period start time information acquisition unit is configured to, if the current encrypted number is the same as the to-be-verified encrypted number, acquire the current one-time password period start time information.
[0160] The first one-time password verification unit is configured to determine that the one-time password passes verification and update the value of the bit position in the bitmap corresponding to the serial number key parameter if it is determined that the target time key parameter is the same as the current one-time password cycle start time information and the bit position in the bitmap corresponding to the serial number key parameter satisfies the value condition.
[0161] The second one-time password verification unit is configured to determine that the one-time password passes verification and update the value of the bit position in the bitmap corresponding to the serial number key parameter if it is determined that the target time key parameter is greater than the current one-time password cycle start time information, update the current one-time password cycle start time information to the target time key parameter, clear the bitmap, and update the value of the bit position in the bitmap corresponding to the serial number key parameter.
[0162] The third one-time password verification unit is configured to determine that the one-time password fails verification if it is determined that the target time key parameter is less than the current one-time password cycle start time information.
[0163] The one-time password verification device provided by the embodiments of the present application can perform the one-time password verification method provided by any of the embodiments of the present application, and has the corresponding function modules and beneficial effects of the execution method.
[0164] Embodiment seven
[0165] Figure 7 A structural schematic diagram of a computer device provided by embodiment seven of the present application is shown in FIG. 7, which includes a processor 70, a memory 71, an input device 72, and an output device 73. Figure 7 The number of processors 70 in the computer device can be one or more, and one processor 70 is taken as an example in the embodiment. Figure 7 The processor 70, the memory 71, the input device 72, and the output device 73 in the computer device can be connected through a bus or other means, and the connection through the bus is taken as an example in the embodiment. Figure 7
[0166] The memory 71, as a computer readable storage medium, can be used to store software programs, computer executable programs and modules, such as the modules corresponding to the one-time password generation method (for example, the time parameter determination module 510, the encrypted number determination module 520 and the one-time password generation module 530 in the one-time password generation device) in the embodiment of the present application, or the modules corresponding to the one-time password verification method (for example, the one-time password analysis module 610, the current time parameter determination module 620, the target time key parameter determination module 630, the current encrypted number determination module 640 and the one-time password verification module 650 in the one-time password verification device) in the embodiment of the present application. The processor 70 executes the software programs, instructions and modules stored in the memory 71, so as to perform various function applications and data processing of the computer device, that is, to realize the one-time password generation method described above. The method comprises:
[0167] According to the cycle start time of the one-time password, the time key parameter is calculated, and the time parameter is determined according to the time key parameter;
[0168] According to the serial number of the one-time password, the serial number key parameter is determined, and the preset data is encrypted according to the time key parameter and the serial number key parameter, to determine the encrypted number;
[0169] The time parameter, the serial number key parameter and the encrypted number are combined into the one-time password, so as to provide the one-time password to the user, and the user inputs the one-time password in the password verification end for verification.
[0170] Or realize the one-time password verification method described above. The method comprises:
[0171] The one-time password input by the user is obtained, and the to-be-verified time parameter, the serial number key parameter and the to-be-verified encrypted number are determined according to the one-time password input by the user;
[0172] According to the current time, the current time key parameter is calculated, and the current time parameter is determined according to the current time key parameter;
[0173] According to the to-be-verified time parameter and the current time parameter, the target time key parameter is determined;
[0174] According to the target time key parameter and the serial number key parameter, the preset data is encrypted to determine the current encrypted number;
[0175] According to the current encrypted number and the to-be-verified encrypted number, the one-time password input by the user is verified.
[0176] The memory 71 can include a program storage area and a data storage area. The program storage area can store an operating system, application programs required for at least one function, and the like. The data storage area can store data created according to the use of the terminal, and the like. In addition, the memory 71 can include a high-speed random access memory, and can further include a non-volatile memory such as at least one of a magnetic disk storage device, a flash memory device, or other non-volatile solid state memory device. In some examples, the memory 71 can further include a memory disposed remotely with respect to the processor 70, which can be connected to the computer device through a network. Examples of the network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0177] The input device 72 can be used to receive input digital or character information, and to generate key signal inputs related to the user settings and function controls of the computer device. The output device 73 can include a display device such as a display screen.
[0178] Embodiment Eight
[0179] Embodiment eight of the present application also provides a storage medium containing computer executable instructions for performing a one-time password generation method when executed by a computer processor.
[0180] The method includes:
[0181] According to the cycle start time of the one-time password, a time key parameter is calculated, and according to the time key parameter, a time parameter is determined;
[0182] According to the serial number of the one-time password, a serial number key parameter is determined, and according to the time key parameter and the serial number key parameter, a preset data is encrypted to determine an encrypted number;
[0183] The time parameter, the serial number key parameter, and the encrypted number are combined into a one-time password, so as to provide the one-time password to the user, and make the user input the one-time password at a password verification end for verification.
[0184] Or a one-time password verification method is performed. The method includes:
[0185] A one-time password input by a user is obtained, and according to the one-time password input by the user, a to-be-verified time parameter, a serial number key parameter, and a to-be-verified encrypted number are determined;
[0186] According to the current time, a current time key parameter is calculated, and according to the current time key parameter, a current time parameter is determined;
[0187] According to the to-be-verified time parameter and the current time parameter, a target time key parameter is determined;
[0188] According to the target time key parameter and the serial number key parameter, the preset data is encrypted to determine a current encrypted number;
[0189] According to the current encrypted number and the to-be-verified encrypted number, the one-time password input by the user is verified.
[0190] Of course, the storage medium provided by the embodiment of the present application includes computer executable instructions, and the computer executable instructions are not limited to the method operations described above, but can also perform the related operations in the generation method of the one-time password and the verification method of the one-time password provided by any embodiment of the present application.
[0191] Through the above description of the embodiments, those skilled in the art can clearly understand that the present application can be realized by means of software and necessary general hardware, and of course can also be realized by hardware, but in many cases the former is a better embodiment. Based on such understanding, the technical solutions of the present application can be embodied in the form of a software product, which can be stored in a computer readable storage medium, such as a floppy disk, a read-only memory (ROM), a random access memory (RAM), a FLASH, a hard disk or an optical disk, etc., including a plurality of instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute the methods described in various embodiments of the present application.
[0192] It is worth noting that the embodiments of the above one-time password generation device and the one-time password verification device include various units and modules only according to functional logic, but are not limited to the above division, as long as the corresponding functions can be realized; in addition, the specific names of each functional unit are only for easy distinction, and do not limit the protection scope of the present application.
[0193] Note that the above is only the preferred embodiment of the present application and the technical principle applied. Those skilled in the art will understand that the present application is not limited to the specific embodiments described herein, and those skilled in the art can make various obvious changes, readjustments and substitutions without departing from the scope of the present application. Therefore, although the present application has been described in more detail through the above embodiments, the present application is not limited to the above embodiments, and can include more other equivalent embodiments without departing from the concept of the present application, and the scope of the present application is determined by the scope of the appended claims.
Claims
1. A method of generating a one-time password, characterized by, The application is applied to a password generation end, comprising: According to the cycle start time of the one-time password, a time key parameter is calculated, and according to the time key parameter, a time parameter is determined, comprising: Converting the cycle start time of the one-time password into world coordinated time, and obtaining an integer by dividing the world coordinated time by the effective time period of the one-time password, and taking the integer as the time key parameter; Taking the number corresponding to the preset bit of the time key parameter as the time parameter; According to the serial number of the one-time password, a serial number key parameter is determined, and according to the time key parameter and the serial number key parameter, preset data is encrypted to determine an encrypted number; The time parameter, the serial number key parameter and the encrypted number are combined into the one-time password, so that the one-time password is provided to the user, and the user inputs the one-time password in the password verification end for verification.
2. The method of claim 1, wherein, According to the time key parameter and the serial number key parameter, the preset data is encrypted to determine the encrypted number, comprising: According to the time key parameter, the serial number key parameter, the device identifier and the preset token, an encryption key is generated; According to the encryption key, the preset data is encrypted to obtain intermediate data; The intermediate data is processed to obtain the encrypted number.
3. A method of verifying a one-time password, characterized by, The application is applied to a password verification end, comprising: Obtaining the one-time password input by the user, and determining the to-be-verified time parameter, the serial number key parameter and the to-be-verified encrypted number according to the one-time password input by the user; According to the current time, a current time key parameter is calculated, and according to the current time key parameter, a current time parameter is determined; According to the to-be-verified time parameter and the current time parameter, a target time key parameter is determined, comprising: According to the to-be-verified time parameter, the one-time password cycle and the effective time period of the one-time password, a time threshold is determined; If it is determined that the current time parameter is greater than or equal to the to-be-verified time parameter and less than or equal to the time threshold, the sum of the difference between the current time key parameter and the current time parameter and the to-be-verified time parameter is taken as the target time key parameter; If it is determined that the current time parameter is less than the to-be-verified time parameter, the time threshold is greater than or equal to the number matching the preset bit, and the current time parameter is less than the difference between the time threshold and the number matching the preset bit, the sum of the difference between the current time key parameter and the current time parameter and the to-be-verified time parameter is subtracted by the number obtained by matching the number matching the preset bit, and the result is taken as the target time key parameter; According to the target time key parameter and the serial number key parameter, the preset data is encrypted to determine a current encrypted number; According to the current encrypted number and the to-be-verified encrypted number, the one-time password input by the user is verified.
4. The method of claim 3, wherein, According to the current encrypted number and the to-be-verified encrypted number, the one-time password input by the user is verified, comprising: If the current encrypted number is the same as the to-be-verified encrypted number, the current one-time password cycle start time information is obtained; If it is determined that the target time key parameter is the same as the current one-time password cycle start time information, and the bit matching the serial number key parameter in the bitmap satisfies the number condition, it is determined that the one-time password passes the verification, and the number of the bit matching the serial number key parameter in the bitmap is updated. If it is determined that the target time key parameter is greater than the current one-time password cycle start time information, it is determined that the one-time password is verified, the current one-time password cycle start time information is updated to the target time key parameter, the bitmap is cleared, and the value of the bit in the bitmap that matches the serial number key parameter is updated; If it is determined that the target time key parameter is less than the current one-time password cycle start time information, it is determined that the one-time password is not verified.
5. An apparatus for generating a one-time password, characterized by The device is deployed at a password generation end and includes: A time parameter determination module configured to calculate a time key parameter according to a one-time password cycle start time, and determine a time parameter according to the time key parameter; The time parameter determination module includes: A time key parameter determination unit configured to convert the one-time password cycle start time into a coordinated universal time, and obtain an integer by dividing the coordinated universal time by a valid time period of the one-time password, and use the integer as the time key parameter; The time key parameter determination unit is configured to use a number corresponding to a preset bit of the time key parameter as the time parameter; An encrypted number determination module configured to determine a serial number key parameter according to a serial number of the one-time password, and encrypt preset data according to the time key parameter and the serial number key parameter to determine an encrypted number; A one-time password generation module configured to combine the time parameter, the serial number key parameter, and the encrypted number into the one-time password, and provide the one-time password to a user so that the user inputs the one-time password at a password verification end for verification.
6. An authentication apparatus of a one-time password, characterized by, The device is deployed at a password verification end and includes: A one-time password analysis module configured to obtain a one-time password input by a user, and determine a to-be-verified time parameter, a serial number key parameter, and a to-be-verified encrypted number according to the one-time password input by the user; A current time parameter determination module configured to calculate a current time key parameter according to a current time, and determine a current time parameter according to the current time key parameter; A target time key parameter determination module configured to determine a target time key parameter according to the to-be-verified time parameter and the current time parameter; The target time key parameter determination module includes: A time threshold determination unit configured to determine a time threshold according to the to-be-verified time parameter, a one-time password cycle, and a valid time period of the one-time password; A first target time key parameter determination unit configured to, if it is determined that the current time parameter is greater than or equal to the to-be-verified time parameter and less than or equal to the time threshold, use a sum of the difference between the current time key parameter and the current time parameter and the to-be-verified time parameter as the target time key parameter; A second target time key parameter determination unit configured to, if it is determined that the current time parameter is less than the to-be-verified time parameter, the time threshold is greater than or equal to a value matching a preset bit, and the current time parameter is less than a difference between the time threshold and the value matching the preset bit, use a value obtained by subtracting the value matching the preset bit from a sum of the difference between the current time key parameter and the current time parameter and the to-be-verified time parameter as the target time key parameter; The current encryption number determining module is configured to determine a current encryption number by encrypting preset data according to a target time key parameter and a serial number key parameter; The one-time password verifying module is configured to verify a one-time password input by a user according to the current encryption number and a to-be-verified encryption number.
7. A computer device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, The processor implements the one-time password generation method of any one of claims 1-2 or the one-time password verification method of any one of claims 3-4 when executing the program.
8. A storage medium containing computer-executable instructions, characterized in that, The computer executable instructions are used to execute the one-time password generation method of any one of claims 1-2 or the one-time password verification method of any one of claims 3-4 when executed by the computer processor.
Citation Information
Patent Citations
One-time password generation method and device, intelligent door lock and storage medium
CN112348998A
Off-line control method and device of electronic lock and terminal device
CN113223210A