CN115641130A - Method, device and equipment for generating transaction record ID based on improved snowflake algorithm - Google Patents

Method, device and equipment for generating transaction record ID based on improved snowflake algorithm Download PDF

Info

Publication number
CN115641130A
CN115641130A CN202211054065.5A CN202211054065A CN115641130A CN 115641130 A CN115641130 A CN 115641130A CN 202211054065 A CN202211054065 A CN 202211054065A CN 115641130 A CN115641130 A CN 115641130A
Authority
CN
China
Prior art keywords
transaction record
millisecond
snowflake algorithm
snowflake
algorithm
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211054065.5A
Other languages
Chinese (zh)
Inventor
黄步添
李慧
梁逸敏
刘振广
殷昱煜
何钦铭
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hangzhou Yunxiang Network Technology Co Ltd
Original Assignee
Hangzhou Yunxiang Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hangzhou Yunxiang Network Technology Co Ltd filed Critical Hangzhou Yunxiang Network Technology Co Ltd
Priority to CN202211054065.5A priority Critical patent/CN115641130A/en
Publication of CN115641130A publication Critical patent/CN115641130A/en
Pending legal-status Critical Current

Links

Images

Abstract

The invention relates to a method for generating a transaction record ID based on an improved snowflake algorithm, which comprises the steps of obtaining and analyzing a transaction request, wherein the information obtained by analysis comprises a current timestamp, a server MAC address and a digital RMB number; generating an ID (identity) from information based on an improved snowflake algorithm model, and taking the ID as a transaction record ID of the digital RMB transaction service; encrypting the transaction record ID based on a TwoFish algorithm model to obtain an encrypted transaction record ID; and taking the encrypted transaction record ID and the digital RMB number as main keys of a database transaction record table, and uniquely identifying each transaction record. The ID generated based on the improved snowflake algorithm model is used as the transaction record ID of the digital RMB transaction service in the database, the TwoFish algorithm model is used for encrypting the transaction record ID to ensure the data security, the encrypted transaction record ID and the digital RMB number form a main key of a transaction record table together, and the digital RMB transaction record is uniquely identified.

Description

Method, device and equipment for generating transaction record ID based on improved snowflake algorithm
Technical Field
The invention relates to a method, a device and equipment for generating a transaction record ID based on an improved snowflake algorithm.
Background
With the rapid development of technologies such as internet, artificial intelligence technology and 5G, the digital economy brings great promotion to the development, and online transactions become new transaction situations. In the data storage process of online transaction, a primary key is needed in a database to uniquely identify each transaction record, and the primary key has the requirements of global uniqueness, generation under a high-concurrency distributed scene and the like.
Application scenarios: when the digital RMB is transacted, each transaction record needs to be distinguished by a unique identifier, and the unique identifier cannot be repeated and is kept unique, and according to the existing data volume, the effect of the unique identifier cannot be achieved only by means of a timestamp accurate to millisecond, so that a method for generating the non-repeated id under a high-concurrency distributed scene is urgently needed. Based on the above requirements, the use of a distributed ID generation algorithm, the modified snowflake algorithm, in combination with the digital renminbi number as the primary key to the database transaction record table is the optimal solution.
Disclosure of Invention
In view of the above, the invention provides a method, a device and equipment for generating a transaction record ID based on an improved snowflake algorithm, which can generate a globally unique unrepeated ID under a high-concurrency distributed scene of digital rmb transaction, the ID generated by the improved snowflake algorithm is used as the transaction record ID of a digital rmb transaction service in a database, and the transaction record ID and a digital rmb number encrypted by using a TwoFish algorithm jointly uniquely identify the digital rmb transaction record.
According to one aspect of the invention, a method for generating a transaction record ID based on an improved snowflake algorithm is provided, and the method specifically comprises the following steps:
1) Acquiring and analyzing a transaction request, wherein the analyzed information comprises a current server timestamp, a server MAC address and a digital RMB number;
2) Based on an improved snowflake algorithm model, generating an ID according to the information obtained by the analysis, and taking the ID as a transaction record ID of the digital RMB transaction service;
3) Encrypting the transaction record ID based on a TwoFish algorithm model to obtain an encrypted transaction record ID;
4) And taking the encrypted transaction record ID and the digital RMB number as main keys of a database transaction record table, and uniquely identifying each transaction record.
The specific implementation method of the content 2) is as follows:
estimating the quantity of the transaction requests of the digital Renminbi per second according to the twenty-one transaction peak data, wherein million transactions per second are possible to be achieved at most, and considering the global population growth and the internationalization trend of the digital Renminbi, the hundred million transaction requests per second are expected to be generated at most; the rule of the bank for storing the data is to keep transaction records within at least 5 years, generally not keep data for too long years, or else, the data volume is too large and redundant;
improving the snowflake algorithm according to the estimated transaction request quantity of the digital RMB per second and the rule of bank storage data;
the sign bit field is the same as the sign bit of the original snowflake algorithm, and 1 bit is fixed as a positive number marked by 0;
the time stamp field records a time millisecond value, the original snowflake algorithm time stamp field is 41 bits, and the length of the original snowflake algorithm time stamp field is improved to meet the bank storage data rule;
the device number field is used for carrying out unique identification record on the device, the original snowflake algorithm device number field is a 10-bit self-increment device number, and the device number field is filled with the server MAC address in an improved mode;
the self-increment sequence number field records the number of the transaction requests in sequence, the self-increment sequence number field of the original snowflake algorithm is 12 bits, and the length is improved to the length meeting the number of the transaction requests of the digital RMB per second;
in the process of generating the ID by the snowflake algorithm, the processing of the callback of the server clock is divided into two situations, wherein the callback time is less than the set millisecond time range and the callback time is greater than the set millisecond time range, and two different processing modes are adopted.
The specific implementation method for generating the ID according to the information obtained by the analysis in the content 2) is as follows:
specifying a start timestamp for the transaction record;
subtracting the initial timestamp from the obtained current timestamp of the server, converting the obtained result into a binary string, and filling a timestamp field of the digital RMB transaction record ID;
converting the obtained server MAC address into a binary MAC address serving as a snowflake algorithm to generate an ID device number;
and generating a self-increment sequence number field of the ID according to the sequence self-increment of the transaction requests, and finishing the ID generation.
In the specific implementation method of the content 2), the specific implementation method of the processing of the occurrence of the server clock callback is as follows:
if the clock callback of the server occurs, if the callback time is less than the set millisecond time range, the snowflake algorithm pauses to generate the ID, the millisecond time value is acquired after the current thread blocks the clock callback millisecond number, if the millisecond time value acquired again is larger than the maximum millisecond number in the snowflake algorithm generated ID, the snowflake algorithm continues to generate the ID, otherwise, the abnormal state is thrown out and the abnormal data is prompted;
and if the callback time of the server is larger than the set millisecond time range, generating the ID by using the largest millisecond number in the ID generated by the snowflake algorithm as the current millisecond time stamp, and starting with the next bit of the largest serial number under the largest millisecond number to continuously generate the ID.
The descriptions of the contents 3), 4) are as follows:
in order to ensure the security of data, the digital RMB transaction record ID can not be stored in a database in a plaintext form, the transaction record ID is encrypted by using a TwoFish algorithm, and due to the characteristics of the digital RMB transaction, the encrypted transaction record ID and the digital RMB number are used as a main key of a transaction record table of the database together to uniquely identify each transaction record.
According to another aspect of the present invention, there is provided an apparatus for generating a transaction record ID based on a modified snowflake algorithm, comprising:
the device for generating the digital RMB transaction record ID by the snowflake algorithm is deployed at a digital RMB transaction terminal and comprises a snowflake algorithm generation ID module, a clock callback processing module, an algorithm encryption module and a transaction record table main key generation module, wherein the snowflake algorithm generation ID module is triggered in the digital RMB transaction business process, when the server clock callback occurs, the clock callback processing module is triggered, the algorithm encryption module is executed after the execution of the snowflake algorithm generation ID module is finished, and then the transaction record table main key generation module is executed;
the snowflake algorithm generation ID module is used for stipulating the starting time stamp of the transaction record, subtracting the starting time stamp from the current time stamp of the server, converting the obtained result into a binary string, and filling the binary string into the time stamp field of the ID generated by the snowflake algorithm; converting the obtained server MAC address into a binary MAC address serving as a snowflake algorithm to generate an ID device number; generating a self-increment sequence number field of the ID according to the sequence self-increment of the transaction requests;
the clock dial-back processing module generates an ID module in a snowflake algorithm, if the server clock dial-back occurs, the processing mode is as follows, if the dial-back time is less than the set millisecond time range, the snowflake algorithm suspends the generation of the ID, the millisecond time value is acquired after the current thread blocks the clock dial-back millisecond number, if the acquired millisecond time value is greater than the maximum millisecond number in the ID generated by the snowflake algorithm, the snowflake algorithm continues to generate the ID, otherwise, the abnormality is thrown out and the data abnormality is prompted, if the server dial-back time is greater than the set millisecond time range, the maximum millisecond number in the ID generated by the snowflake algorithm is used as the current millisecond timestamp, and the ID continues to be generated by the next bit of the maximum serial number under the maximum millisecond number;
the algorithm encryption module is used for encrypting the transaction record ID in the database by using the ID generated by the improved snowflake algorithm as the transaction record ID of the digital RMB transaction service and using the TwoFish algorithm;
and the encrypted transaction record ID and the digital RMB number are jointly used as the main key of the database transaction record table, and each transaction record is uniquely identified.
In accordance with another aspect of the present invention, there is provided an electronic device for generating a transaction record ID based on a modified snowflake algorithm, wherein the electronic device comprises:
a processor; and
a memory arranged to store computer executable instructions that, when executed, cause the processor to perform a method that implements the above.
According to another aspect of the present invention, there is provided a computer readable storage medium for generating a transaction record ID based on a modified snowflake algorithm, wherein the computer readable storage medium stores one or more programs which, when executed by a processor, implement the method described above.
The invention has the beneficial effects that:
the method is based on the requirement of digital RMB transaction on the transaction request quantity per second and bank stored data, improves the traditional snowflake algorithm, sets a clock callback processing operation, continuously and stably generates a trend-increasing globally unique unrepeated ID under the conditions of meeting the bank stored data rule and high concurrent digital RMB transaction scenes, improves the ID generated by the snowflake algorithm as a transaction record ID of a digital RMB transaction service in a database, encrypts the transaction record ID by using a TwoFish algorithm to ensure data security, and forms a main key of a transaction record table together with the digital RMB number to uniquely identify the digital RMB transaction record.
Drawings
The drawings are only for purposes of illustrating preferred embodiments and are not to be construed as limiting the invention, wherein:
FIG. 1 illustrates a transaction record ID number data structure generated using an improved snowflake algorithm model to custom set the field contents and lengths that satisfy a condition in an embodiment;
FIG. 2 shows a flow chart of a method embodying the present invention, which is triggered when a digital RMB transaction is conducted;
FIG. 3 illustrates a process for encrypting a transaction record ID using the TwoFish algorithm, according to which the transaction record ID is encrypted after the snowflake algorithm generates the ID as a digital RMB transaction record ID;
figure 4 shows an arrangement for generating a digital rmb transaction record ID using the modified snowflake algorithm.
Detailed Description
The foregoing description is only an overview of the technical solutions of the present invention, and in order to make the technical means of the present invention more clearly understood, the technical solutions of the present invention can be implemented according to the content of the description, and in order to more clearly clarify the above and other objects, features, and advantages of the present invention, the present invention will be further described in detail with reference to the accompanying drawings and the detailed description.
The invention is based on snowflake algorithm of Twitter company, the snowflake algorithm will generate a 64-bit binary data, the improvement is as follows, the time stamp field is improved to satisfy the length of the bank data storage rule, the device number field is improved to be filled by using the server MAC address, the self-numbering field is improved to satisfy the length of the number of the digital Renminbi transaction requests per second, the self-defining ID data structure satisfying the above conditions is shown in FIG. 1, comprising:
1 st position: a sign indicates a bit, 0 indicates a positive number, 1 indicates a negative number, and the bit is 0;
a second field: the 2 nd bit to the 40 th bit are millisecond time stamps which can identify millisecond values, the length of the 39 bit can identify a millisecond value and can mark the millisecond value for about 17 years, and the requirement of a bank for storing data is met;
a third field: the 41 st to 88 th bits, namely the equipment number, convert the MAC address of the server into a binary numerical string, and fill the equipment number with the binary numerical string, so that the equipment can be uniquely identified;
a fourth field: the 89 th to 128 th bits, the count number of 40 bits, support generation of billions of non-duplicate ID numbers per device per millisecond.
The ID generated by the snowflake algorithm is wholly sorted according to time increment, the algorithm acquires millisecond-level system time every millisecond, the millisecond time stamp field of the ID serial number of the digital RMB transaction record is filled with the system millisecond time, the equipment number field is filled with the binary numerical value string converted by the MAC address of the server, the transaction record is counted, and the counting serial number field is filled with the sequence.
The snowflake algorithm has the problem of depending on system time, and when a server clock is dialed back, the system time is wrong, and a globally unique non-repeated ID cannot be normally generated.
In view of the fact that convenience and safety need to be guaranteed in digital RMB transaction, influence of problems such as clock callback on the generation of an ID (identity) of a snowflake algorithm can be avoided in a clock synchronization mode of a server, and if the problem of clock callback occurs due to uncontrollable factors, the following mode is adopted for clock callback processing:
if the clock callback condition of the server occurs, if the callback time is smaller than the set millisecond time range, the snowflake algorithm suspends the generation of the ID, the millisecond time value is acquired after the current thread blocks the clock callback millisecond number, if the acquired millisecond time value is larger than the maximum millisecond number in the snowflake algorithm generated ID, the server time is recovered to be normal, the snowflake algorithm continues to generate the ID, otherwise, the abnormal state is thrown out and the data abnormal state is prompted;
and if the callback time of the server is larger than the set millisecond time range, generating the ID by using the largest millisecond number in the ID generated by the snowflake algorithm as the current millisecond time stamp, and starting with the next bit of the largest serial number under the largest millisecond number to continuously generate the ID.
And judging whether the server clock is back-dialed or not when the ID is requested to be generated, and if the millisecond value of the system timestamp of the currently identified server is smaller than the maximum millisecond value counted by the snowflake algorithm, judging that the server clock is back-dialed.
For example, assuming that the maximum milliseconds counted in the generated ID of the snowflake algorithm is X and the set time range is 5ms, when the ID is requested to be generated next time, the millisecond value of the server system timestamp is identified to be X-3, which indicates that 3-millisecond clock callback occurs in the server, at this time, the snowflake algorithm suspends the generation of the ID, the current thread blocks the clock callback milliseconds, namely, the time is acquired again after 3ms, assuming that the thread blocks 3ms, the acquired millisecond value of the server system timestamp is X +2, the server time is recovered to be normal, and the snowflake algorithm continues to generate the ID normally; and if the acquired server system timestamp millisecond value is X-1, throwing the exception and prompting data exception.
Assuming that the maximum number of milliseconds counted in the snowflake algorithm generation ID is X and the set time range is 5ms, and the next time the ID is requested to be generated, the millisecond value of the server system timestamp is identified to be X-8, the snowflake algorithm continues to generate the ID from the next bit of the maximum serial number under the X timestamp by taking X as the current number of milliseconds.
In the process of generating the ID by the snowflake algorithm, if the ID which can be generated by a certain device under the current millisecond timestamp is exhausted, the nearest server MAC address is selected, and the server MAC address is converted into a binary numerical string and then is filled with a device number;
in the process of generating the IDs by the snowflake algorithm, if the IDs which can be generated by all the devices under the current millisecond timestamp are exhausted, the millisecond timestamp is switched to the next millisecond, and the IDs are continuously generated.
The ID generated by the improved snowflake algorithm is used as a transaction record ID of the digital RMB transaction service in a database, and the TwoFish encryption algorithm is used for encrypting the ID generated by the snowflake algorithm, and the method comprises the following steps:
preparation before calculation: the 128bits plaintext ID is divided into 4 groups of data, assumed to be P 0 、P 1 、P 2 、P 3 Four parts, each group of data occupies 32 bits;
inputting a whitening stage: calculating R (0, i) according to the formula R (0, i) = P (i) xor K (i), where i = 0., 3, R (0, i) represents 4 parts of an ID xored with an extended key word, K (i) is an extended key word calculated by the twofish algorithm, and K (i) is 32 bits of data with a length identical to P (i);
and a circular encryption stage:
in each of 16 cycles, the first two sets of data R (R, 0), R (R, 1) and the current cycle number R are calculated by an F function, the calculated results are denoted as F (R, 0) and F (R, 1), the 3 rd set of data R (R, 2) is exclusive-ored with F (R, 0), then circularly moved one bit to the right, the result is recorded as R (R +1, 0), the 4 th set of data R (R, 3) is circularly moved one bit to the left, then exclusive-ored with F (R, 1), the result is recorded as R (R +1, 1), the first two sets of data R (R, 0), R (R, 1) are subjected to data interchange with R (R +1, 0), R (R +1, 1), and the data sequence calculated in the next cycle is R (R +1, 0), R (R +1, 1), R (R, 0), R (R = 0), R =0, 15, and is expressed by the formula:
(F(r,0),F(r,1))=F(R(r,0),R(r,1),r)
R(r+1,0)=ROR(R(r,2)xor F(r,0),1)
R(r+1,1)=ROL(R(r,3),1)xor F(r,1)
R(r+1,2)=R(r,0)
R(r+1,3)=R(r,1)
the first round of encryption:
(F(0,0),F(0,1))=F(R(0,0),R(0,1),0)
R(1,0)=ROR(R(0,2)xor F(0,0),1)
R(1,1)=ROL(R(0,3),1)xor F(0,1)
R(1,2)=R(0,0)
R(1,3)=R(0,1)
and (4) encryption of a second round:
(F(1,0),F(1,1))=F(R(1,0),R(1,1),1)
R(2,0)=ROR(R(1,2)xor F(1,0),1)
R(2,1)=ROL(R(1,3),1)xor F(1,1)
R(2,2)=R(1,0)
R(2,3)=R(1,1)
carrying out 16 rounds of encryption operation circularly according to the encryption method of each round;
and an output whitening stage: the 16 th cycle is the last cycle, and the output of the cycle is R (16, 2), R (16, 3), R (16, 0), R (16, 1), according to the formula
Figure BDA0003824844930000071
Wherein i = 0.., 3, calculating an intermediate ciphertext C (i);
calculating according to the following formula to obtain a ciphertext:
Figure BDA0003824844930000072
combining 16C (i) into ciphertext C;
the F function of the circular encryption stage is that the input content is firstly transformed by an S-box, then multiplied by an MDS matrix, then subjected to PHT transformation, and finally subjected to exclusive OR operation with the sub-key of K (i);
where K (i) is an extended key word associated with the key, the calculation is as follows:
m is a preset key consisting of 16 bytes, recorded as M (j), where j = 0.. 15;
converting the 16 bytes of data into 4 32-bit data, recorded as M (i), where i = 0.., 3;
two k-dimensional vectors are constructed from these 4 32-bit data: me = (M0, M2), mo = (M1, M3);
the calculation process and formula of k are as follows:
ρ=2 24 +2 16 +2 8 +2 0
A(i)=h(2iρ,Me)
B(i)=ROL(h((2i+1)ρ,Mo),8)
K(2i)=(A(i)+B(i))mod 2 32
K(2i+1)=ROL((A(i)+2B(i))mod 2 32 ,9)
wherein i = 0.
The flow of encrypting plaintext by the TwoFish encryption algorithm is shown in fig. 3.
The encrypted transaction record ID and the digital RMB number are jointly used as a main key of a database transaction record table to uniquely identify the transaction record.
Fig. 4 is a schematic content diagram of an apparatus for improving a snowflake algorithm applied to a digital rmb transaction service according to the present invention. As shown in FIG. 4, the device for generating the digital RMB transaction record ID by the improved snowflake algorithm provided by the invention comprises:
the snowflake algorithm generation ID module is used for stipulating the starting time stamp of the transaction record, subtracting the starting time stamp from the current time stamp of the server, converting the obtained result into a binary digit string and filling the binary digit string into the time stamp field of the snowflake algorithm generation ID; converting the obtained server MAC address into a binary MAC address serving as a snowflake algorithm to generate an ID device number; generating a self-increment sequence number field of the ID according to the sequence self-increment of the transaction requests;
the clock dial-back processing module generates an ID module in a snowflake algorithm, if the clock dial-back of the server occurs, the processing mode is as follows, if the dial-back time is smaller than the set millisecond time range, the snowflake algorithm pauses to generate the ID, the millisecond time value is acquired after the current thread blocks the clock dial-back millisecond number, if the millisecond time value acquired again is larger than the maximum millisecond number in the ID generated by the snowflake algorithm, the snowflake algorithm continues to generate the ID, otherwise, the abnormality is thrown out and the data abnormality is prompted, if the dial-back time of the server is larger than the set millisecond time range, the maximum millisecond number in the ID generated by the snowflake algorithm is used as the current millisecond time stamp, and the ID is continuously generated by starting from the next bit of the maximum serial number under the maximum millisecond number;
the algorithm encryption module is used for encrypting the transaction record ID by using the ID generated by the improved snowflake algorithm as the transaction record ID of the digital RMB transaction service in the database and using a TwoFish algorithm;
and the encrypted transaction record ID and the digital RMB number are jointly used as the main key of the database transaction record table, and each transaction record is uniquely identified.
The judgment condition for the occurrence of the server clock callback is as follows: the millisecond value of the system timestamp currently identifying the server is less than the maximum millisecond value in the snowflake algorithm generation ID.
The apparatus for generating a digital renminbi transaction record ID using the modified snowflake algorithm of the embodiment of the present invention can be used for implementing the above-mentioned method embodiments, and the principle and technical effects are similar.
It should be noted that the above-mentioned embodiments illustrate rather than limit the invention, and that those skilled in the art will be able to design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The invention can be implemented by means of hardware comprising several distinct elements, and by means of a suitably programmed computer.

Claims (10)

1. A method for generating a transaction record ID based on an improved snowflake algorithm is characterized by comprising the following steps:
acquiring and analyzing a transaction request, wherein the information obtained by analysis comprises a current server timestamp, a server MAC address and a digital RMB number;
based on an improved snowflake algorithm model, generating an ID (identity) from the information obtained by analysis, and taking the ID as a transaction record ID of the digital RMB transaction service;
encrypting the transaction record ID based on a TwoFish algorithm model to obtain an encrypted transaction record ID;
and taking the encrypted transaction record ID and the digital RMB number as main keys of a database transaction record table, and uniquely identifying each transaction record.
2. The method for generating transaction record ID based on modified snowflake algorithm as claimed in claim 1, wherein: the improved snowflake algorithm model and the construction process comprise the following steps:
setting various fields including a symbol bit field, a timestamp field, a device number field and a self-incrementing sequence number field;
improving the original snowflake algorithm model based on various set fields to obtain an improved snowflake algorithm model;
wherein, the sign bit field is the same as the sign bit of the original snowflake algorithm, 1 bit is fixed as a positive number marked by 0;
the time stamp field records a time millisecond value, the original snowflake algorithm time stamp field is 41 bits, and the length of the original snowflake algorithm time stamp field is improved to meet the bank storage data rule;
the device number field is used for carrying out unique identification record on the device, the original snowflake algorithm device number field is a 10-bit self-increment device number, and the device number field is filled with the server MAC address in an improved mode;
the self-increment sequence number field records the number of the transaction requests in sequence, the original snowflake algorithm self-increment sequence number field is 12 bits, and the length is improved to the length meeting the number of the transaction requests of the digital RMB money per second.
3. The method for generating transaction record ID based on modified snowflake algorithm of claim 2, wherein: the step of generating the ID from the analyzed information comprises the following steps:
specifying a start timestamp for the transaction record;
subtracting the initial timestamp from the obtained current timestamp of the server, converting the obtained result into a binary string, and filling a timestamp field of the digital RMB transaction record ID;
converting the obtained server MAC address into a binary MAC address serving as a snowflake algorithm to generate an ID device number;
and generating a self-increment sequence number field of the ID according to the sequence self-increment of the transaction requests, and finishing the ID generation.
4. The method for generating transaction record ID based on modified snowflake algorithm as claimed in claim 3, wherein: further comprising the steps of: in the process of generating the ID, the processing of the callback of the server clock is divided into two situations, wherein the callback time is less than the set millisecond time range, and the callback time is greater than the set millisecond time range, and two different processing modes are adopted;
when the dial-back time is smaller than the set millisecond time range, the snowflake algorithm model is improved to suspend ID generation, the millisecond time value is acquired after the current thread blocks the clock and dials back milliseconds, if the acquired millisecond time value is larger than the maximum millisecond number in the ID generation of the snowflake algorithm model, the snowflake algorithm model is improved to continue ID generation, otherwise, the abnormal condition is thrown out and the abnormal data is prompted;
and when the callback time of the server is larger than the set millisecond time range, taking the maximum millisecond number in the ID generated by the improved snowflake algorithm model as the current millisecond timestamp, and starting with the next bit of the maximum serial number under the maximum millisecond number to continuously generate the ID.
5. The method for generating transaction record ID based on modified snowflake algorithm as claimed in claim 1, further comprising the steps of:
in the process of generating the ID by the improved snowflake algorithm model, if the ID number which can be generated by a certain device under the current millisecond timestamp is exhausted, the MAC address of the server with the closest distance is selected, and the MAC address of the server is converted into a binary system to be filled with the device number.
6. The method for generating transaction record ID based on modified snowflake algorithm as claimed in claim 1, further comprising the steps of:
in the process of generating the IDs by the improved snowflake algorithm model, if the IDs which can be generated by all the devices under the current millisecond timestamp are exhausted, the millisecond timestamp is switched to the next millisecond, and the IDs are continuously generated.
7. The method for generating transaction record ID based on modified snowflake algorithm as claimed in claim 1, wherein: the encrypting of the transaction record ID using the TwoFish algorithm model comprises the following steps:
preparation before calculation: the generated IDs are evenly divided into 4 groups of data, recorded as P (i), where i =0,. 3;
inputting a whitening stage: calculating R (0, i) according to a formula R (0, i) = P (i) xor K (i), where i = 0., 3, R (0, i) represents 4 parts of an ID obtained by performing an exclusive or operation in the above formula, K (i) is an extended key word calculated by the twofish algorithm, and K (i) and P (i) are identical in length;
and a circular encryption stage:
in each round of 16 rounds, the first two groups of data R (R, 0), R (R, 1) and the current round number R are calculated by a twofish algorithm F function, the calculated results are recorded as F (R, 0) and F (R, 1), the 3 rd group of data R (R, 2) is exclusive-ored with F (R, 0), then is circularly moved by one bit to the right, the result is recorded as R (R +1, 0), the 4 th group of data R (R, 3) is circularly moved by one bit to the left, then is exclusive-ored with F (R, 1), the result is recorded as R (R +1, 1), the first two groups of data R (R, 0), R (R, 1) are data-exchanged with R (R +1, 0), R (R +1, 1), and the data sequence calculated in the next round is R (R +1, 0), R (R +1, 1), R (R, 0), R (R, 1), R =0,. 1, 15;
carrying out 16 rounds of encryption operation circularly according to the encryption method of each round;
and an output whitening stage: the 16 th cycle is the last cycle, the output of the cycle is R (16, 2), R (16, 3), R (16, 0), R (16, 1), an intermediate ciphertext C (i) is calculated according to the formula C (i) = R (16, (i + 2) mod 4) × K (i + 4), where i = 0.
Figure FDA0003824844920000031
16C (i) are combined into ciphertext C.
8. A device for generating a transaction record ID based on an improved snowflake algorithm is characterized by comprising an acquisition and analysis module, an ID generation module, an algorithm encryption module and a main key generation module;
the acquisition and analysis module is used for acquiring and analyzing the transaction request, and the information obtained by analysis comprises a current server timestamp, a server MAC address and a digital RMB number;
the ID generation module generates an ID from the information obtained by analysis based on an improved snowflake algorithm model, and the ID is used as a transaction record ID of the digital RMB transaction service;
the algorithm encryption module encrypts the transaction record ID based on a TwoFish algorithm model to obtain an encrypted transaction record ID;
and the primary key generation module is used for taking the encrypted transaction record ID and the digital RMB number as a primary key of a database transaction record table and uniquely identifying each transaction record.
9. An electronic device, wherein the electronic device comprises:
a processor; and
a memory storing computer-executable instructions that, when executed, the processor performs the method of any of claims 1-8.
10. A computer readable storage medium, wherein the computer readable storage medium stores one or more programs which, when executed by a processor, implement the method of any of claims 1-8.
CN202211054065.5A 2022-08-31 2022-08-31 Method, device and equipment for generating transaction record ID based on improved snowflake algorithm Pending CN115641130A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211054065.5A CN115641130A (en) 2022-08-31 2022-08-31 Method, device and equipment for generating transaction record ID based on improved snowflake algorithm

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211054065.5A CN115641130A (en) 2022-08-31 2022-08-31 Method, device and equipment for generating transaction record ID based on improved snowflake algorithm

Publications (1)

Publication Number Publication Date
CN115641130A true CN115641130A (en) 2023-01-24

Family

ID=84939901

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211054065.5A Pending CN115641130A (en) 2022-08-31 2022-08-31 Method, device and equipment for generating transaction record ID based on improved snowflake algorithm

Country Status (1)

Country Link
CN (1) CN115641130A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116071164A (en) * 2023-04-06 2023-05-05 江苏金寓信息科技有限公司 Digital asset tracing method based on blockchain management
CN116866427A (en) * 2023-09-04 2023-10-10 杭州比智科技有限公司 Unified pushing method and system for heterogeneous messages

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116071164A (en) * 2023-04-06 2023-05-05 江苏金寓信息科技有限公司 Digital asset tracing method based on blockchain management
CN116866427A (en) * 2023-09-04 2023-10-10 杭州比智科技有限公司 Unified pushing method and system for heterogeneous messages
CN116866427B (en) * 2023-09-04 2023-12-12 杭州比智科技有限公司 Unified pushing method and system for heterogeneous messages

Similar Documents

Publication Publication Date Title
CN115641130A (en) Method, device and equipment for generating transaction record ID based on improved snowflake algorithm
US8284933B2 (en) Encrypting variable-length passwords to yield fixed-length encrypted passwords
CN111310222B (en) File encryption method
JP2003535377A (en) Pseudo random number generator
CN107276744B (en) File storage encryption method and system
WO2019237550A1 (en) Encryption method and apparatus, terminal device, and storage medium
US20120269340A1 (en) Hierarchical encryption/decryption device and method thereof
CN110689349A (en) Transaction hash value storage and search method and device in block chain
CN111325535A (en) Block chain private key management method, system and storage medium based on elliptic curve migration
CN115659409A (en) Financial asset transaction data safe storage method
CN110543778A (en) linear random encryption and decryption algorithm for character data
JP2003535378A (en) Parallel modulo operations using bitwise logical operations
CN115048664A (en) Data security storage method, device, equipment and medium based on solid state disk
US20070277043A1 (en) Methods for Generating Identification Values for Identifying Electronic Messages
WO2021217939A1 (en) Data processing method and apparatus for blockchain, and readable storage medium
CN116894273B (en) File encryption method, decryption method, equipment and medium based on exclusive or sum remainder
CN109766342B (en) Data storage and query method based on block chain
JP2003535363A (en) How to protect your cryptosystem from multiple outbound attacks
CN114218582A (en) Database data encryption method and terminal
US6301361B1 (en) Encoding and decoding information using randomization with an alphabet of high dimensionality
JP2003535362A (en) Decryption of cryptographic polynomial
JP2003535500A (en) How to check the validity of an encrypted message
JP2003535499A (en) End of message marker
CN115344875A (en) File encryption method, file decryption method and device
CN116484443B (en) Trusted security storage method and device based on hong Monte-go system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination