Method and device for implementing md5 algorithm using standard sql statements
Patent Information
- Application Number
- CN202310275005.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-20
- Publication Date
- 2026-10-30
- Estimated Expiration
- 2043-03-20
AI Technical Summary
[0008]目前多数数据库系统需要安装专用的扩展包,这可能造成特殊安装的工作量,或需要独立购置扩展包,增加了项目成本
[0034]本发明通过标准SQL语句实现了MD5算法,无需依赖于数据库厂家的扩展包即可完成MD5算法,无需额外安装扩展包,无需额外付费,降低了依赖于MD5运算的SQL应用的实现成本和运维成本,本发明也为无法实现MD5算法的数据库系统提供一种可选方案。
Smart Images

Figure CN116303539B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of database technology, and more specifically, to a method and apparatus for implementing the MD5 algorithm using standard SQL statements. Background Technology
[0002] Using the MD5 algorithm to process raw data or input strings in SQL operations is very common. Unlike ordinary SQL functions, the MD5 functions of existing database systems, also known as native MD5, are implemented using non-SQL languages at the database vendor's level. MD5 functions are usually provided in extension packages, which are themselves implemented in compiled languages such as C / C++ / Java. SQL only provides vendor-specific MD5 function interfaces. For example:
[0003] Oracle Database: Uses extension packages to provide dedicated functions. The core itself is written in C, and Java is used as an extension. The function descriptions are as follows.
[0004] Function DBMS_OBFUSCATION_TOOKIT.MD5(input_string IN varchar2);
[0005] MySQL database: Built-in support from MySQL version 4.1 onwards. It is written in C / C++. For versions earlier than 4.1, MySQL does not support the MD5 function.
[0006] OceanBase database: The basic package does not support the MD5 function. An extension package needs to be purchased and installed separately to support the MD5 function. The MD5 function itself is implemented using a low-level language instead of SQL.
[0007] Figure 2 This explains the calling process of the native MD5 function provided by the database vendor, such as... Figure 2 As shown, after an SQL application calls the natively provided "SQL MD5 external interface", the SQL interpreter will call the MD5 function implemented in the database system's dedicated extension package. This extension package is usually implemented in programming languages such as C / C++ / Java. These functions may call the relevant support interfaces of the operating system or language's underlying library.
[0008] Currently, most database systems require the installation of dedicated extension packages, which can lead to additional installation work or the need to purchase these packages separately, increasing project costs. Furthermore, for some databases and their extension packages that do not support MD5, or for older database systems that do not support MD5 at all, applications centered around these databases will be unable to use MD5 functions. Therefore, existing technology lacks a more convenient method for implementing the MD5 algorithm using standard SQL statements. Summary of the Invention
[0009] In order to solve at least one of the technical problems in the background art, the present invention proposes a method and apparatus for implementing the MD5 algorithm using standard SQL statements.
[0010] To achieve the above objectives, according to one aspect of the present invention, a method for implementing the MD5 algorithm using standard SQL statements is provided, the method comprising:
[0011] Initialize four magic numbers R1, R2, R3 and R4, four HEX string constant arrays T1, T2, T3 and T4, and integer constant arrays K1, K2, K3, K4, S1, S2, S3 and S4;
[0012] Call the conversion and fill functions to fill the original data to obtain a HEX string rawStr of length N×128, where the original data is an SQL varchar string of arbitrary length and N is an integer greater than or equal to 1;
[0013] N HEX strings `rawGrpStr` of length 128 are sequentially extracted from the string `rawStr`. For each string `rawGrpStr`, a loop calculation is performed to obtain the calculation results of R1, R2, R3, and R4 for each string `rawGrpStr`. Then, the calculation results of R1, R2, R3, and R4 for each string `rawGrpStr` are concatenated to obtain the MD5 result. Specifically, the loop calculation includes: dividing the string `rawGrpStr` into 16 groups of 8 HEX characters to obtain the array `pArr[1..16]`; initializing R1, R2, R3, and R4... Store the results in temporary variables tR1, tR2, tR3, and tR4. Loop through n = 1 to 4. After each n setting, set array variables TVal = T[n], KVal = K[n], and SVal = S[n]. After setting the array variables, loop through i = 1 to 16. Then, calculate R1, R2, R3, and R4 based on TVal[i], KVal[i], SVal[i], and pArr[i]. Based on the calculated R1, R2, R3, and R4, recalculate R1, R2, R3, and R4 using temporary variables tR1, tR2, tR3, and tR4 to obtain the calculation results of R1, R2, R3, and R4 corresponding to the string rawGrpStr.
[0014] Optionally, the calculation of R1, R2, R3, and R4 based on TVal[i], KVal[i], SVal[i], and pArr[i] specifically includes:
[0015] Calculate R1, R2, R3 and R4 based on TVal[i], KVal[i], SVal[i] and pArr[i], as well as the preset MD5 linear function, hexadecimal addition function and hexadecimal shift function.
[0016] Optionally, the recalculation of R1, R2, R3, and R4 based on the calculated R1, R2, R3, and R4 using temporary variables tR1, tR2, tR3, and tR4 specifically includes:
[0017] Based on the calculated R1, R2, R3, and R4, and the temporary variables tR1, tR2, tR3, and tR4, R1, R2, R3, and R4 are recalculated using a preset hexadecimal addition function.
[0018] Optionally, the method for implementing the MD5 algorithm using standard SQL statements further includes:
[0019] Establish conversion and fill functions, wherein the conversion and fill functions are used to convert SQL varchar strings of arbitrary length into SQL varchar strings of length N×128 in HEX format.
[0020] Optionally, the method for implementing the MD5 algorithm using standard SQL statements further includes:
[0021] An MD5 linear function is established, wherein the MD5 linear function implements four non-linear functions F, G, H and I of the MD5 algorithm. The MD5 linear function uses SQL int integers 1, 2, 3 and 4 to indicate the four non-linear functions respectively. The MD5 linear function uses three SQL varchar strings x, y and z to represent the three input parameters of the non-linear functions respectively. Each input parameter is represented by 8 HEX characters. The output of the MD5 linear function is 8 HEX characters.
[0022] Optionally, the method for implementing the MD5 algorithm using standard SQL statements further includes:
[0023] Establish a hexadecimal addition function, which is used to perform binary summation and conversion on the binary positive integers corresponding to two SQL varchar strings represented by 8 HEX characters, and output the result represented by 8 HEX characters.
[0024] Optionally, the method for implementing the MD5 algorithm using standard SQL statements further includes:
[0025] Establish a hexadecimal shift function, which is used to perform binary shift and conversion on the binary positive integer corresponding to the SQL varchar string represented by 8 HEX characters, and output the result represented by 8 HEX characters.
[0026] To achieve the above objectives, according to another aspect of the present invention, an apparatus for implementing the MD5 algorithm using standard SQL statements is provided, the apparatus comprising:
[0027] An initialization unit is used to initialize four magic numbers R1, R2, R3 and R4, four HEX string constant arrays T1, T2, T3 and T4, and integer constant arrays K1, K2, K3, K4, S1, S2, S3 and S4;
[0028] The raw data processing unit is used to call the transformation and filling functions to fill the raw data to obtain a HEX string rawStr of length N×128, wherein the raw data is an SQL varchar string of arbitrary length and N is an integer greater than or equal to 1;
[0029] The MD5 calculation unit is used to sequentially extract N HEX strings `rawGrpStr` of length 128 from the string `rawStr`, perform iterative calculations on each string `rawGrpStr` to obtain the calculation results of R1, R2, R3, and R4 for each string `rawGrpStr`, and then concatenate the calculation results of R1, R2, R3, and R4 for each string `rawGrpStr` to obtain the MD5 calculation result. Specifically, the iterative calculation includes: dividing the string `rawGrpStr` into 16 groups of 8 HEX characters to obtain the array `pArr[1..16]`; initializing R1, R... 2. Store R3 and R4 into temporary variables tR1, tR2, tR3, and tR4. Loop through n = 1 to 4. After each n setting, set array variables TVal = T[n], KVal = K[n], and SVal = S[n]. After setting the array variables, loop through i = 1 to 16. Then calculate R1, R2, R3, and R4 based on TVal[i], KVal[i], SVal[i], and pArr[i]. Recalculate R1, R2, R3, and R4 using temporary variables tR1, tR2, tR3, and tR4 based on the calculated R1, R2, R3, and R4 to obtain the calculation results of R1, R2, R3, and R4 corresponding to the string rawGrpStr.
[0030] To achieve the above objectives, according to another aspect of the present invention, a computer device is also provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps of the method described above for implementing the MD5 algorithm using standard SQL statements.
[0031] To achieve the above objectives, according to another aspect of the present invention, a computer-readable storage medium is also provided, on which a computer program / instructions are stored, which, when executed by a processor, implement the steps of the method for implementing the MD5 algorithm using standard SQL statements described above.
[0032] To achieve the above objectives, according to another aspect of the present invention, a computer program product is also provided, comprising a computer program / instructions that, when executed by a processor, implement the steps of the method for implementing the MD5 algorithm using standard SQL statements.
[0033] The beneficial effects of this invention are as follows:
[0034] This invention implements the MD5 algorithm using standard SQL statements. It can complete the MD5 algorithm without relying on database vendor extension packages, without the need for additional installation of extension packages or additional payment. This reduces the implementation and maintenance costs of SQL applications that rely on MD5 calculations. This invention also provides an alternative solution for database systems that cannot implement the MD5 algorithm. Attached Figure Description
[0035] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. In the drawings:
[0036] Figure 1 This is a flowchart illustrating a method for implementing the MD5 algorithm using standard SQL statements, as described in an embodiment of the present invention.
[0037] Figure 2 This is a diagram illustrating the calling process of the native MD5 function provided by the database vendor.
[0038] Figure 3 This is a schematic diagram of the calculation logic for the transformation and fill functions;
[0039] Figure 4 This is a schematic diagram of the calculation logic of the MD5 linear function;
[0040] Figure 5 This is a schematic diagram of the MD5 function calculation logic of the present invention;
[0041] Figure 6 This is a structural block diagram of the apparatus for implementing the MD5 algorithm using standard SQL statements according to an embodiment of the present invention;
[0042] Figure 7 This is a schematic diagram of a computer device according to an embodiment of the present invention. Detailed Implementation
[0043] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0044] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0045] It should be noted that the terms "comprising" and "having" and any variations thereof in the specification, claims and accompanying drawings of this invention are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are explicitly listed, but may include other steps or units that are not explicitly listed or that are inherent to such processes, methods, products or devices.
[0046] It should be noted that, unless otherwise specified, the embodiments and features described in the present invention can be combined with each other. The present invention will now be described in detail with reference to the accompanying drawings and embodiments.
[0047] It should be noted that the acquisition, storage, use, and processing of data in the technical solution of this application all comply with the relevant provisions of national laws and regulations.
[0048] It should be noted that the method and apparatus for implementing the MD5 algorithm using standard SQL statements of this invention can be used in the financial field, or in any field other than the financial field. The application field of the method and apparatus for implementing the MD5 algorithm using standard SQL statements of this invention is not limited.
[0049] This invention implements the complete MD5 algorithm using standard SQL, and is not limited by whether the underlying database system's extension packages are installed and implement the MD5 algorithm. Specifically, it includes:
[0050] 1. Implement the conversion and padding function bss_md5_fill: This function can convert any SQL varchar string into a hexadecimal (HEX) string (each byte can be represented by 2 hexadecimal characters), and pad the end according to the MD5 padding algorithm to represent a byte string that is a multiple of 64 bytes. After conversion to hexadecimal string representation, a string that is a multiple of 128 bytes in length is obtained.
[0051] 2. Implement the four non-linear functions of MD5: bss_md5_gen: Uses SQL to manipulate hexadecimal string numbers. Implements the four non-linear functions of the MD5 algorithm in one function. This function determines which non-linear function to use based on the input parameter identifier.
[0052] 3. Implement addition operation of numbers represented by HEX strings: bss_md5_add: Uses SQL statement to receive two parameters represented by 8 hexadecimal characters, and returns the binary addition of the 32-bit binary representations of the two parameters. The result value is also represented using the 8-character HEX format of SQL.
[0053] 4. Implement binary shift operation bss_md5_move for hexadecimal string data: Uses an SQL statement to receive a parameter 'a' represented by 8 HEX characters and a shift number parameter 'nbit'. Returns the result value after shifting the binary number represented by parameter 'a' to the left or right by n bits of absolute value. nbit>0 indicates a left shift, and nbit<0 indicates a right shift. The result value is also represented using the 8 HEX characters of SQL.
[0054] 5. Implement the MD5 function bss_md5: Implemented using SQL language. Input any SQL string, call the above 4 functions, use the MD5 loop algorithm, and output the MD5 conversion result value. The MD5 result value is represented using the 32-character HEX format of SQL.
[0055] This invention effectively overcomes the limitations of existing technologies that rely on extension packages and database vendor products, and provides a method for implementing the MD5 algorithm using standard SQL.
[0056] Figure 1 This is a flowchart illustrating a method for implementing the MD5 algorithm using standard SQL statements, as described in an embodiment of the present invention. Figure 1 As shown, in one embodiment of the present invention, the method of implementing the MD5 algorithm using standard SQL statements includes steps S101 to S103.
[0057] Step S101: Initialize four magic numbers R1, R2, R3 and R4, four HEX string constant arrays T1, T2, T3 and T4, and integer constant arrays K1, K2, K3, K4, S1, S2, S3 and S4.
[0058] Step S102: Call the conversion and fill functions to fill the original data to obtain a HEX string rawStr of length N×128, where the original data is an SQL varchar string of arbitrary length and N is an integer greater than or equal to 1.
[0059] Step S103: Extract N HEX strings `rawGrpStr` of length 128 sequentially from the string `rawStr`. Perform iterative calculations on each `rawGrpStr` to obtain the calculation results of R1, R2, R3, and R4 for each string. Then, concatenate the calculation results of R1, R2, R3, and R4 for each string `rawGrpStr` to obtain the MD5 result. Specifically, the iterative calculation includes: dividing the string `rawGrpStr` into 16 groups of 8 HEX characters to obtain the array `pArr[1..16]`; initializing R1, R2, R3... R1 and R2 are stored in temporary variables tR1, tR2, tR3 and tR4. The loop sets n = 1 to 4. After each n setting, the array variables TVal = T[n], KVal = K[n], and SVal = S[n] are set. After setting the array variables, the loop sets i = 1 to 16. Then, R1, R2, R3 and R4 are calculated based on TVal[i], KVal[i], SVal[i] and pArr[i]. Based on the calculated R1, R2, R3 and R4, the temporary variables tR1, tR2, tR3 and tR4 are used to recalculate R1, R2, R3 and R4, obtaining the calculation results of R1, R2, R3 and R4 corresponding to the string rawGrpStr.
[0060] This invention implements the MD5 function bss_md5 using standard SQL statements.
[0061] Input: Any SQL varchar string;
[0062] Returns: 32 HEX strings after MD5 calculation.
[0063] This function is the output function of the MD5 algorithm finally implemented using standard SQL in this invention. For example: bss_md5('12345') = '827CCB0EEA8A706C4C34A16891F84E7B'.
[0064] This function is implemented based on the four basic functions mentioned earlier that are implemented using standard SQL, and can be achieved by combining them with the publicly available MD5 algorithm.
[0065] The calculation logic of this function is as follows: Figure 5 As shown, Figure 5 The implementation details of the MD5 algorithm using standard SQL described in this invention are given below:
[0066] ① Initialize four magic numbers R1, R2, R3, R4, and four HEX string constant arrays T[1..4], four integer constant arrays K[1..4], and four integer constant arrays S[1..4].
[0067] In one embodiment of the present invention, the initialized R1, R2, R3, and R4 are specifically as follows:
[0068] R1:='67452301';
[0069] R2:='efcdab89'
[0070] R3:='98badcfe';
[0071] R4:='10325476';
[0072] R1..4 are all HEX strings of length 8.
[0073] T[1..4] are constant arrays of HEX strings of length 16, and each array member is a HEX string of length 8.
[0074] In one embodiment of the present invention, the initialized T[1..4] is specifically as follows:
[0075] T[1]:=['d76aa478','e8c7b756','242070db','c1bdceee',
[0076] 'f57c0faf','4787c62a','a8304613','fd469501',
[0077] '698098d8','8b44f7af','ffff5bb1','895cd7be',
[0078] '6b901122','fd987193','a679438e','49b40821'];
[0079] T2:=['f61e2562','c040b340','265e5a51','e9b6c7aa',
[0080] 'd62f105d','02441453','d8a1e681','e7d3fbc8',
[0081] '21e1cde6','c33707d6','f4d50d87','455a14ed',
[0082] 'a9e3e905','fcefa3f8','676f02d9','8d2a4c8a'];
[0083] T3:=['fffa3942','8771f681','6d9d6122','fde5380c',
[0084] 'a4beea44','4bdecfa9','f6bb4b60','bebfbc70',
[0085] '289b7ec6','eaa127fa','d4ef3085','04881d05',
[0086] 'd9d4d039','e6db99e5','1fa27cf8','c4ac5665'];
[0087] T4:=['f4292244','432aff97','ab9423a7','fc93a039',
[0088] '655b59c3','8f0ccc92','ffeff47d','85845dd1',
[0089] '6fa87e4f','fe2ce6e0','a3014314','4e0811a1',
[0090] 'f7537e82','bd3af235','2ad7d2bb','eb86d391'];
[0091] K[1..4] are all integer constant arrays of length 16. In one embodiment of the present invention, the initialized K[1..4] are specifically as follows:
[0092] K1:=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15];
[0093] K2:=[1,6,11,0,5,10,15,4,9,14,3,8,13,2,7,12];
[0094] K3:=[5,8,11,14,1,4,7,10,13,0,3,6,9,12,15,2];
[0095] K4:=[0,7,14,5,12,3,10,1,8,15,6,13,4,11,2,9];
[0096] S[1..4] are all integer constant arrays of length 16. In one embodiment of the present invention, the initialized S[1..4] is specifically as follows:
[0097] S1:=[7,12,17,22,7,12,17,22,7,12,17,22,7,12,17,22];
[0098] S2:=[5,9,14,20,5,9,14,20,5,9,14,20,5,9,14,20];
[0099] S3:=[4,11,16,23,4,11,16,23,4,11,16,23,4,11,16,23];
[0100] S4:=[6,10,15,21,6,10,15,21,6,10,15,21,6,10,15,21];
[0101] ② Call bss_md5_fill to fill the original data to obtain a HEX string rawStr of length N×128, and divide it into N fixed-length groups in order: the original input str is converted into N HEX strings of length 128.
[0102] ③ Sequentially extract the HEX string rawGrpStr of length 128, and loop the logic N times: extract each fixed-length group and perform the following logical loop, each time obtaining new R1, R2, R3, R4 values.
[0103] ④ Starting from the least significant character of the rawGrpStr string, divide it into 16 groups of 8 HEX characters each, and place them in the array pArr[1..16]. Divide the rawGrpStr string obtained each time into 16 groups as needed. Each group has a length of 8 HEX characters. Each group is then processed by reversing the order of every two characters. That is, the original character order 12345678 is converted into a new order 78563412. For example, the character 'a4beea44' is converted into '44eabea4'. The 16 divided and converted strings are put into the 1..16 elements of the array pArr. pArr[1..16] will be used in subsequent calculations.
[0104] ⑤ Store R1..4 into temporary variable tR1:=R1 tR2:=R2 tR3:=R3 tR4:=R4: Record the R1..4 before the operation and store it in tR1..4 for use after the loop operation.
[0105] ⑥ Set n = 1, 2, 3, 4 and execute the loop 4 times: Set the variable n to 1..4 respectively and execute the next two steps in a loop.
[0106] ⑦ Set array variables TVal = T[n], KVal = K[n], SVal = S[n]: Based on the value of the loop variable n, set the arrays with corresponding indices obtained from the constants T, K, and S and place them in TVal, KVal, and SVal.
[0107] ⑧ Set i = 1..16 and execute the loop 16 times: Complete the loop 16 times based on the value of the loop variable i.
[0108] ⑨ Use TVal[i], KVal[i], SVal[i], and pArr[i] to obtain R1, R2, R3, and R4: This part is the most important execution body in the MD5 algorithm. It calls the previously compiled function to recalculate the variables R1, R2, R3, and R4. The specific calculation method is as follows:
[0109] R1:=bss_md5_add(R1,
[0110] bss_md5_add(bss_md5_add(bss_md5_gen(n,R2,R3,R4),pArr(KVal(i)+1)),TVal(i)));
[0111] R1:=bss_md5_add(R2,bss_md5_move(R1,SVal(i))|
[0112] bss_md5_move(R1,SVal(i)-32));
[0113] Rtmp:=R4;
[0114] R4:=R3;
[0115] R3:=R2;
[0116] R2:=R1;
[0117] R1:=Rtmp;
[0118] ⑩ Recalculate R1, R2, R3, R4 using tR1, tR2, tR3, tR4: Call the bss_md5_add function to recalculate R1, R2, R3, R4 using the tR1, tR2, tR3, tR4 from before the loop started and the new R1, R2, R3, R4.
[0119] R1:=bss_md5_add(R1,tR1);
[0120] R2:=bss_md5_add(R2,tR2);
[0121] R3:=bss_md5_add(R3,tR3);
[0122] R4:=bss_md5_add(R4,tR4);
[0123] (11) Concatenating the final R1, R2, R3, R4 yields the final output: After all loops are completed, R1, R2, R3, and R4 are obtained. Concatenating them yields the final MD5 output. The concatenation method is as follows:
[0124] Return string = substr(R1,7,2)||substr(R1,5,2)||substr(R1,3,2)||substr(R1,1,2)||
[0125] substr(R2,7,2)||substr(R2,5,2)||substr(R2,3,2)||substr(R2,1,2)||
[0126] substr(R3,7,2)||substr(R3,5,2)||substr(R3,3,2)||substr(R3,1,2)||
[0127] substr(R4,7,2)||substr(R4,5,2)||substr(R4,3,2)||substr(R4,1,2)||”;
[0128] The function `substr(A,pos,len)` extracts a substring of A, starting from the `pos`th character and extracting a substring of length `len`. The `||` symbol represents concatenating strings.
[0129] In one embodiment of the present invention, the calculation of R1, R2, R3, and R4 based on TVal[i], KVal[i], SVal[i], and pArr[i] in step S103 specifically includes:
[0130] Calculate R1, R2, R3 and R4 based on TVal[i], KVal[i], SVal[i] and pArr[i], as well as the preset MD5 linear function, hexadecimal addition function and hexadecimal shift function.
[0131] In one embodiment of the present invention, step S103 above, which involves recalculating R1, R2, R3, and R4 based on the calculated R1, R2, R3, and R4 using temporary variables tR1, tR2, tR3, and tR4, specifically includes:
[0132] Based on the calculated R1, R2, R3, and R4, and the temporary variables tR1, tR2, tR3, and tR4, R1, R2, R3, and R4 are recalculated using a preset hexadecimal addition function.
[0133] In one embodiment of the present invention, the method for implementing the MD5 algorithm using standard SQL statements further includes:
[0134] Establish conversion and fill functions, wherein the conversion and fill functions are used to convert SQL varchar strings of arbitrary length into SQL varchar strings of length N×128 in HEX format.
[0135] To implement the MD5 algorithm, this invention establishes a transformation and fill function bss_md5_fill implemented using standard SQL.
[0136] Input: Any string represented by SQL varchar;
[0137] Output: A HEX formatted SQL varchar string of length N×128 (N>=1).
[0138] Figure 3 This is a schematic diagram of the transformation and fill function calculation logic, such as... Figure 3 As shown, the calculation logic of the conversion and filling function bss_md5_fill in this invention is as follows:
[0139] 1. Convert the str parameter into a HEX string according to the byte code corresponding to each character, with the high byte first and the low byte last. Each byte corresponds to 2 HEX characters. The converted HEX string is denoted as rawStr.
[0140] For example, if str = '12345', then rawStr = '3132333435'.
[0141] 2. Obtain the length of the byte array of the str internal code by multiplying it by 8 to get the binary bit length bitLen, and convert the length it represents into a HEX string, and add 0 characters to the high bits so that the number of HEX characters becomes 16. Then reverse these 16 characters to get bitLenHex.
[0142] For example, if str = '12345', the bit length = 5 × 8 = 40. After padding the high bits with 0, we get the string '0000000000000028'. After reversing the order, we get bitLenHex = '2800000000000000'.
[0143] 3. Divide rawStr into groups of 128 characters each, and obtain the length of the last group, restHexLen. If the length is less than 112, add '80' characters to the end of the group, and then start '00' characters in a loop until the length of the last group is expanded to 112 characters. If restHexLen is greater than 112, add '80' characters to the group, and then start '00' characters in a loop until the length of the last group is expanded to 128 characters. Then, add a new group based on the last group, using 56 '00' characters to obtain a new group of 112 characters at the end.
[0144] 4. Concatenate a 16-bit bitLenHex to the last group of length 112 in the above steps to obtain a complete group of 128 HEX characters. At this point, you can get N sequentially concatenated groups of 128 HEX characters each (N>=1). Concatenate the groups in order to get the complete function result return string, which contains N×128 HEX characters.
[0145] According to the calculation logic of bss_md5_fill above, if str = '12345', then the function returns the following value:
[0146] '31323334358000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000028000000000000000'.
[0147] It should be noted that for parameters str containing non-ASCII characters, it is necessary to use the database's built-in functions and a specific encoding method to convert each character into one or more byte codes. For example, the encoding method can be GBK or UTF-8. For the same non-ASCII character, different encoding methods will often produce different byte strings.
[0148] In one embodiment of the present invention, the method for implementing the MD5 algorithm using standard SQL statements further includes:
[0149] An MD5 linear function is established, wherein the MD5 linear function implements four non-linear functions F, G, H and I of the MD5 algorithm. The MD5 linear function uses SQL int integers 1, 2, 3 and 4 to indicate the four non-linear functions respectively. The MD5 linear function uses three SQL varchar strings x, y and z to represent the three input parameters of the non-linear functions respectively. Each input parameter is represented by 8 HEX characters. The output of the MD5 linear function is 8 HEX characters.
[0150] To implement the MD5 algorithm, this invention also establishes an MD5 linear function bss_md5_gen implemented using standard SQL.
[0151] Input: i: SQL int integers 1, 2, 3, 4 indicate the four non-linear functions F, G, H, I of the MD5 algorithm respectively; x, y, z are three SQL varchar strings that represent the three input parameters of the non-linear functions, and each parameter is represented by a fixed length of 8 HEX characters.
[0152] Output: 8 HEX characters of fixed length.
[0153] The meanings of the four MD5 nonlinear functions are as follows:
[0154] F(x,y,z)=(x&y)|((~x)&z);
[0155] G(x,y,z)=(x&z)|(y&(~z));
[0156] H(x,y,z) = x^y^z;
[0157] I(x,y,z)=y^(x|(~z));
[0158] In the above function, &|~^ represent the binary AND, OR, NOT, and XOR operators of the operation parameters, respectively.
[0159] The MD5 linear function bss_md5_gen uses SQL varchar type HEX strings. The parameters x, y, and z are all 8 characters long. When performing AND, OR, NOT, and XOR operations, they need to be converted to int data type first, and then binary-related logical operations are performed. Alternatively, they can be converted to binary form for operation, or the logical operation functions of HEX strings provided by the database system can be used. The result of the calculation also needs to be converted to 8 HEX characters. Finally, the results of the four non-linear functions can be obtained by combining the various basic operations.
[0160] Examples are given below:
[0161] Let: x = 'fffa3942', y = '8771f681', z = '6d9d6122'
[0162] x&y='87703000'~x='0005C6BD'
[0163] x|z='FFFF7962'x^y='788BCFC3'
[0164] F(x,y,z)='87757020'G(x,y,z)='EFF8B783'
[0165] H(x,y,z)='1516AEE1'I(x,y,z)='788B495E'
[0166] The calculation logic of the MD5 linear function bss_md5_gen is as follows: Figure 4 As shown.
[0167] In one embodiment of the present invention, the method for implementing the MD5 algorithm using standard SQL statements further includes:
[0168] Establish a hexadecimal addition function, which is used to perform binary summation and conversion on the binary positive integers corresponding to two SQL varchar strings represented by 8 HEX characters, and output the result represented by 8 HEX characters.
[0169] To implement the MD5 algorithm, this invention also establishes a hexadecimal addition function bss_md5_add implemented using standard SQL.
[0170] Input: Two SQL varchar string input parameters a and b, each of which is represented by a fixed length of 8 HEX characters.
[0171] Output: The binary summation of the two positive binary integers represented by parameters a and b, and the resulting conversion, returns 8 HEX characters of the same length.
[0172] It is important to note that any overflow from the summation of the highest bits should be discarded. When the highest bit of the binary representation of parameters a and b is 1, it does not indicate a negative number.
[0173] For example:
[0174] bss_md5_add('fffa3942','8771f681')='876C2FC3'.
[0175] In SQL, this function can be implemented by converting two HEX strings to positive integers, then adding the integers using SQL, converting them back to HEX strings, and extracting the lower 8 bits to get the returned result. If the converted result is less than 8 bits, 0s need to be padded to the bottom of the HEX string to get an 8-bit HEX string.
[0176] In one embodiment of the present invention, the method for implementing the MD5 algorithm using standard SQL statements further includes:
[0177] Establish a hexadecimal shift function, which is used to perform binary shift and conversion on the binary positive integer corresponding to the SQL varchar string represented by 8 HEX characters, and output the result represented by 8 HEX characters.
[0178] To implement the MD5 algorithm, this invention also establishes a hexadecimal shift function bss_md5_move implemented using standard SQL.
[0179] Input: 'a' is an SQL varchar string input parameter, which is represented by a fixed length of 8 HEX characters. 'nbit' represents the number of bits to shift the binary number represented by parameter 'a'. A value greater than 0 indicates a left shift of n bits, a value less than 0 indicates a right shift of n absolute bits, and a value equal to 0 indicates no shift.
[0180] Output: A binary positive integer represented by 'a' is shifted into binary bits and returned as an 8-bit HEX string of the same length.
[0181] It is important to note that when shifting to the left, the overflow portion is discarded, and when shifting to the right, the high-order bits must be padded with 0s.
[0182] For example:
[0183] bss_md5_move('fffa3942',4)='FFA39420';
[0184] bss_md5_move('fffa3942',-4)='0FFFA394'.
[0185] In SQL, this function converts the HEX string of parameter 'a' to a positive integer type, then uses a loop to obtain the result by left-shifting by 1 bit and multiplying by 2, then right-shifting by 1 bit and dividing by 2, discarding decimal places. Finally, it converts the result back to HEX format to obtain the lower 8 HEX characters, padding the lower bits with 0s if the result is less than 8 characters.
[0186] As can be seen from the above embodiments, the present invention employs a unique design and uses standard SQL to implement the complete MD5 algorithm, and its beneficial effects include:
[0187] (1) The MD5 algorithm can be completed without relying on the database vendor's extension package. No additional extension package needs to be installed, and no additional payment is required, which reduces the implementation cost and operation and maintenance cost of SQL applications that rely on MD5 calculation.
[0188] (2) It unifies the MD5 implementation of different database systems, ensuring smooth portability of upper-layer applications. It uses standard SQL statements to implement the MD5 algorithm and provides a unified access interface to the upper layer, which can ensure a unified interface for different database systems on the MD5 algorithm.
[0189] (3) This invention provides an alternative solution for database systems that cannot implement the MD5 algorithm. Some manufacturers' database systems or low-version database systems cannot support the extended package MD5 algorithm. This invention only requires standard SQL syntax to implement, so it can provide an alternative MD5 implementation solution for such database applications.
[0190] The following will explain some of the techniques used in this invention:
[0191] SQL is short for Structured Query Language, a programming language commonly used by application modules and maintenance personnel to access and manipulate relational database systems.
[0192] Standard SQL: refers to ANSI SQL, which is the international standard for SQL adopted by the International Organization for Standardization (ISO). The standard SQL described in this article refers to the general SQL language supported by various database vendors, rather than the SQL syntax implemented by database vendors that can only support their own or special databases.
[0193] MD5: Also known as the MD5 function, it is a widely used hash transformation function. For a byte string of any length, the MD5 operation can produce a 16-byte hash value. Different input strings will usually produce different MD5 hash values. The probability of different input strings producing the same MD5 hash value is extremely low. The MD5 function is often used in non-highly secure conventional application scenarios such as encrypted storage and data fingerprint recognition.
[0194] SQL implementation of MD5: This is the main content of this invention, namely, the MD5 function implemented using standard SQL.
[0195] HEX strings: These are strings represented in hexadecimal. Each raw byte of data is an 8-bit binary code, which can be represented using two hexadecimal characters. The first four bits are represented by one hexadecimal character, and the last four bits by one hexadecimal character. Hexadecimal characters include: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. Case sensitivity applies below.
[0196] SQL varchar: refers to the standard SQL variable-length string type.
[0197] SQL int: Refers to the standard SQL integer data type.
[0198] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.
[0199] Based on the same inventive concept, embodiments of the present invention also provide an apparatus for implementing the MD5 algorithm using standard SQL statements, which can be used to implement the method for implementing the MD5 algorithm using standard SQL statements described in the above embodiments, as described in the following embodiments. Since the principle of the apparatus for implementing the MD5 algorithm using standard SQL statements is similar to that of the method for implementing the MD5 algorithm using standard SQL statements, embodiments of the apparatus for implementing the MD5 algorithm using standard SQL statements can refer to embodiments of the method for implementing the MD5 algorithm using standard SQL statements, and repeated details will not be repeated. As used below, the terms "unit" or "module" can refer to a combination of software and / or hardware that performs a predetermined function. Although the apparatus described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0200] Figure 6 This is a structural block diagram of an apparatus for implementing the MD5 algorithm using standard SQL statements, as described in an embodiment of the present invention. Figure 6 As shown, in one embodiment of the present invention, the apparatus for implementing the MD5 algorithm using standard SQL statements includes:
[0201] Initialization unit 1 is used to initialize four magic numbers R1, R2, R3 and R4, four HEX string constant arrays T1, T2, T3 and T4, and integer constant arrays K1, K2, K3, K4, S1, S2, S3 and S4;
[0202] The raw data processing unit 2 is used to call the conversion and filling functions to fill the raw data to obtain a HEX string rawStr of length N×128, wherein the raw data is an SQL varchar string of arbitrary length and N is an integer greater than or equal to 1;
[0203] The MD5 calculation unit 3 is used to sequentially extract N HEX strings `rawGrpStr` of length 128 from the string `rawStr`, perform iterative calculations on each string `rawGrpStr` to obtain the calculation results of R1, R2, R3, and R4 for each string `rawGrpStr`, and then concatenate the calculation results of R1, R2, R3, and R4 for each string `rawGrpStr` to obtain the MD5 calculation result. Specifically, the iterative calculation includes: dividing the string `rawGrpStr` into 16 groups of 8 HEX characters to obtain the array `pArr[1..16]`; initializing R1, R... 2. Store R3 and R4 into temporary variables tR1, tR2, tR3, and tR4. Loop through n = 1 to 4. After each n setting, set array variables TVal = T[n], KVal = K[n], and SVal = S[n]. After setting the array variables, loop through i = 1 to 16. Then calculate R1, R2, R3, and R4 based on TVal[i], KVal[i], SVal[i], and pArr[i]. Recalculate R1, R2, R3, and R4 using temporary variables tR1, tR2, tR3, and tR4 based on the calculated R1, R2, R3, and R4 to obtain the calculation results of R1, R2, R3, and R4 corresponding to the string rawGrpStr.
[0204] In one embodiment of the present invention, the MD5 operation result calculation unit 3 specifically calculates R1, R2, R3 and R4 based on TVal[i], KVal[i], SVal[i] and pArr[i], as well as preset MD5 linear function, hexadecimal addition function and hexadecimal shift function.
[0205] In one embodiment of the present invention, the MD5 operation result calculation unit 3 specifically recalculates R1, R2, R3 and R4 based on the calculated R1, R2, R3 and R4, as well as temporary variables tR1, tR2, tR3 and tR4, using a preset hexadecimal addition function.
[0206] In one embodiment of the present invention, the apparatus for implementing the MD5 algorithm using standard SQL statements further includes:
[0207] A conversion and fill function creation unit is used to create conversion and fill functions, wherein the conversion and fill functions are used to convert an SQL varchar string of arbitrary length into a HEX format SQL varchar string of length N×128.
[0208] In one embodiment of the present invention, the apparatus for implementing the MD5 algorithm using standard SQL statements further includes:
[0209] An MD5 linear function creation unit is used to create an MD5 linear function. This MD5 linear function implements four nonlinear functions F, G, H, and I of the MD5 algorithm. The MD5 linear function uses SQL int integers 1, 2, 3, and 4 to indicate the four nonlinear functions. The MD5 linear function uses three SQL varchar strings x, y, and z to represent the three input parameters of the nonlinear functions. Each input parameter is represented by eight HEX characters. The output of the MD5 linear function is eight HEX characters.
[0210] In one embodiment of the present invention, the apparatus for implementing the MD5 algorithm using standard SQL statements further includes:
[0211] A hexadecimal addition function creation unit is used to create a hexadecimal addition function, wherein the hexadecimal addition function is used to perform binary summation and conversion on the binary positive integers corresponding to two SQL varchar strings represented by 8 HEX characters, and output the result represented by 8 HEX characters.
[0212] In one embodiment of the present invention, the apparatus for implementing the MD5 algorithm using standard SQL statements further includes:
[0213] The hexadecimal shift function establishment unit is used to establish a hexadecimal shift function, wherein the hexadecimal shift function is used to perform binary shift and conversion on the binary positive integer corresponding to the SQL varchar string represented by 8 HEX characters, and output the result represented by 8 HEX characters.
[0214] To achieve the above objectives, according to another aspect of this application, a computer device is also provided. For example... Figure 7 As shown, the computer device includes a memory, a processor, a communication interface, and a communication bus. The memory stores a computer program that can run on the processor. When the processor executes the computer program, it implements the steps in the method of the above embodiments.
[0215] The processor can be a central processing unit (CPU). The processor can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or combinations of the above types of chips.
[0216] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs, non-transitory computer-executable programs, and units, such as the program units corresponding to the above-described method embodiments of the present invention. The processor executes various functional applications and data processing of the processor by running the non-transitory software programs, instructions, and modules stored in the memory, thereby implementing the methods described in the above-described method embodiments.
[0217] The memory may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function; the data storage area may store data created by the processor, etc. Furthermore, the memory may include high-speed random access memory and non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, the memory may optionally include memory remotely located relative to the processor, which can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0218] The one or more units are stored in the memory and, when executed by the processor, perform the methods described in the above embodiments.
[0219] The specific details of the aforementioned computer equipment can be understood by referring to the relevant descriptions and effects in the above embodiments, and will not be repeated here.
[0220] To achieve the above objectives, according to another aspect of this application, a computer-readable storage medium is also provided, which stores a computer program that, when executed in a computer processor, implements the steps in the method for implementing the MD5 algorithm using standard SQL statements. Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), random access memory (RAM), flash memory, hard disk drive (HDD), or solid-state drive (SSD), etc.; the storage medium may also include combinations of the above types of memory.
[0221] To achieve the above objectives, according to another aspect of this application, a computer program product is also provided, including a computer program / instructions that, when executed by a processor, implement the steps of the method for implementing the MD5 algorithm using standard SQL statements.
[0222] Obviously, those skilled in the art will understand that the modules or steps of the present invention described above can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. Optionally, they can be implemented using computer-executable program code, thereby storing them in a storage device for execution by a computing device, or fabricating them separately as individual integrated circuit modules, or fabricating multiple modules or steps as a single integrated circuit module. Thus, the present invention is not limited to any particular hardware and software combination.
[0223] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for implementing the MD5 algorithm using standard SQL statements, characterized in that, include: Initialize four magic numbers R1, R2, R3 and R4, four HEX string constant arrays T[1], T[2], T[3] and T[4], and integer constant arrays K[1], K[2], K[3], K[4], S[1], S[2], S[3] and S[4]; The conversion and padding functions are called to pad the original data to obtain a HEX string rawStr of length N×128. The original data is an SQL varchar string of arbitrary length, and N is an integer greater than or equal to 1. The conversion and padding functions are used to convert the original data into a hexadecimal string and pad the end of the string according to the MD5 padding algorithm so that the length of the padded hexadecimal string is a multiple of 128, thus obtaining a HEX string of length N×128. N HEX strings `rawGrpStr` of length 128 are sequentially extracted from the string `rawStr`. For each string `rawGrpStr`, a loop calculation is performed to obtain the calculation results of R1, R2, R3, and R4 for each string `rawGrpStr`. Then, the calculation results of R1, R2, R3, and R4 for each string `rawGrpStr` are concatenated to obtain the MD5 result. Specifically, the loop calculation includes: dividing the string `rawGrpStr` into 16 groups of 8 HEX characters to obtain the array `pArr[1..16]`; initializing R1, R2, R3, and R4... Store the results in temporary variables tR1, tR2, tR3, and tR4; loop through n = 1 to 4, and after each n setting, set array variables TVal = T[n], KVal = K[n], and SVal = S[n]. After setting the array variables, loop through i = 1 to 16, and then calculate R1, R2, R3, and R4 based on TVal[i], KVal[i], SVal[i], and pArr[i]. Based on the calculated R1, R2, R3, and R4, recalculate R1, R2, R3, and R4 using temporary variables tR1, tR2, tR3, and tR4 to obtain the calculation results of R1, R2, R3, and R4 corresponding to the string rawGrpStr. The calculation of R1, R2, R3, and R4 based on TVal[i], KVal[i], SVal[i], and pArr[i] includes: Based on TVal[i], KVal[i], SVal[i] and pArr[i], as well as the preset MD5 linear function, hexadecimal addition function and hexadecimal shift function, calculate R1, R2, R3 and R4; The recalculation of R1, R2, R3, and R4 based on the calculated R1, R2, R3, and R4 using temporary variables tR1, tR2, tR3, and tR4 includes: Based on the calculated R1, R2, R3 and R4, and the temporary variables tR1, tR2, tR3 and tR4, R1, R2, R3 and R4 are recalculated using a preset hexadecimal addition function; The MD5 linear function implements four nonlinear functions F, G, H, and I of the MD5 algorithm within a single function. The MD5 linear function uses SQL int integers 1, 2, 3, and 4 to indicate the four nonlinear functions. The MD5 linear function determines the corresponding nonlinear function based on the input parameter identifier. The MD5 linear function uses three SQL varchar strings, x, y, and z, to represent the three input parameters of the nonlinear function. Each input parameter is represented by eight HEX characters. The output of the MD5 linear function is also eight HEX characters. The meanings of the four nonlinear functions F, G, H, and I are as follows: F(x,y,z) = (x&y)|((~x)&z); G(x,y,z) = (x&z)|(y&(~z)); H(x,y,z) = x^y^z; I(x,y,z) = y^(x|(~z)); In these functions, &|~^ represent the binary AND, OR, NOT, and XOR operators of the operation parameters, respectively. The hexadecimal addition function is used to perform binary summation and conversion on the binary positive integers corresponding to two SQL varchar strings represented by 8 HEX characters, and output the result represented by 8 HEX characters; The hexadecimal shift function is used to perform binary shift on the binary positive integer corresponding to the SQLvarchar string represented by 8 HEX characters. It receives a shift number nbit, shifts left by nbit when nbit is greater than 0, and shifts right by nbit absolute value when nbit is less than 0; and outputs the result represented by 8 HEX characters. Based on TVal[i], KVal[i], SVal[i], and pArr[i], as well as the preset MD5 linear function, hexadecimal addition function, and hexadecimal shift function, the calculation of R1, R2, R3, and R4 includes: R1 = hexadecimal addition function( R1, hexadecimal addition function( hexadecimal addition function( MD5 linear function(n, R2, R3, R4), pArr[ KVal[i] + 1 ] ), TVal[i] ) ); R1 = hexadecimal addition function(R2, hexadecimal shift function(R1, SVal[i])|hexadecimal shift function(R1,SVal(i)-32)); Assign the value of R4 to the temporary variable Rtmp; Assign the value of R3 to R4; Assign the value of R2 to R3; Assign the value of R1 to R2; Assign the value of Rtmp to R1.
2. The method for implementing the MD5 algorithm using standard SQL statements according to claim 1, characterized in that, Also includes: Establish conversion and fill functions, wherein the conversion and fill functions are used to convert SQL varchar strings of arbitrary length into SQL varchar strings of length N×128 in HEX format.
3. An apparatus for implementing the MD5 algorithm using standard SQL statements, characterized in that, include: An initialization unit is used to initialize four magic numbers R1, R2, R3 and R4, four HEX string constant arrays T[1], T[2], T[3] and T[4], and integer constant arrays K[1], K[2], K[3], K[4], S[1], S[2], S[3] and S[4]; The raw data processing unit is used to call the conversion and padding function to fill the raw data to obtain a HEX string rawStr of length N×128, wherein the raw data is an SQL varchar string of arbitrary length, N is an integer greater than or equal to 1, and the conversion and padding function is used to convert the raw data into a hexadecimal string and pad the end of the string according to the MD5 padding algorithm so that the length of the padded hexadecimal string is an integer multiple of 128, thus obtaining a HEX string of length N×128; The MD5 calculation unit is used to sequentially extract N HEX strings of length 128, `rawGrpStr`, from the string `rawStr`, perform iterative calculations on each `rawGrpStr` to obtain the calculation results of R1, R2, R3, and R4 for each `rawGrpStr`, and then concatenate the calculation results of R1, R2, R3, and R4 for each `rawGrpStr` to obtain the MD5 calculation result. Specifically, the iterative calculation includes: dividing the string `rawGrpStr` into 16 groups of 8 HEX characters to obtain the array `pArr[1]`. ...16]; Store the initialized R1, R2, R3, and R4 into temporary variables tR1, tR2, tR3, and tR4; Loop through n = 1 to 4, and after each n setting, set array variables TVal = T[n], KVal = K[n], and SVal = S[n]. After setting the array variables, loop through i = 1 to 16, and then calculate R1, R2, R3, and R4 based on TVal[i], KVal[i], SVal[i], and pArr[i]; Based on the calculated R1, R2, R3, and R4, recalculate R1, R2, R3, and R4 using temporary variables tR1, tR2, tR3, and tR4 to obtain the calculation results of R1, R2, R3, and R4 corresponding to the string rawGrpStr; The calculation of R1, R2, R3, and R4 based on TVal[i], KVal[i], SVal[i], and pArr[i] includes: Based on TVal[i], KVal[i], SVal[i] and pArr[i], as well as the preset MD5 linear function, hexadecimal addition function and hexadecimal shift function, calculate R1, R2, R3 and R4; The recalculation of R1, R2, R3, and R4 based on the calculated R1, R2, R3, and R4 using temporary variables tR1, tR2, tR3, and tR4 includes: Based on the calculated R1, R2, R3 and R4, and the temporary variables tR1, tR2, tR3 and tR4, R1, R2, R3 and R4 are recalculated using a preset hexadecimal addition function; The MD5 linear function implements four nonlinear functions F, G, H, and I of the MD5 algorithm within a single function. The MD5 linear function uses SQL int integers 1, 2, 3, and 4 to indicate the four nonlinear functions. The MD5 linear function determines the corresponding nonlinear function based on the input parameter identifier. The MD5 linear function uses three SQL varchar strings, x, y, and z, to represent the three input parameters of the nonlinear function. Each input parameter is represented by eight HEX characters. The output of the MD5 linear function is also eight HEX characters. The meanings of the four nonlinear functions F, G, H, and I are as follows: F(x,y,z) = (x&y)|((~x)&z); G(x,y,z) = (x&z)|(y&(~z)); H(x,y,z) = x^y^z; I(x,y,z) = y^(x|(~z)); In these functions, &|~^ represent the binary AND, OR, NOT, and XOR operators of the operation parameters, respectively. The hexadecimal addition function is used to perform binary summation and conversion on the binary positive integers corresponding to two SQL varchar strings represented by 8 HEX characters, and output the result represented by 8 HEX characters; The hexadecimal shift function is used to perform binary shift on the binary positive integer corresponding to the SQLvarchar string represented by 8 HEX characters. It receives a shift number nbit, shifts left by nbit when nbit is greater than 0, and shifts right by nbit absolute value when nbit is less than 0; and outputs the result represented by 8 HEX characters. Based on TVal[i], KVal[i], SVal[i], and pArr[i], as well as the preset MD5 linear function, hexadecimal addition function, and hexadecimal shift function, the calculation of R1, R2, R3, and R4 includes: R1 = hexadecimal addition function( R1, hexadecimal addition function( hexadecimal addition function( MD5 linear function(n, R2, R3, R4), pArr[ KVal[i] + 1 ] ), TVal[i] ) ); R1 = hexadecimal addition function(R2, hexadecimal shift function(R1, SVal[i])|hexadecimal shift function(R1,SVal(i)-32)); Assign the value of R4 to the temporary variable Rtmp; Assign the value of R3 to R4; Assign the value of R2 to R3; Assign the value of R1 to R2; Assign the value of Rtmp to R1.
4. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 2.
5. A computer-readable storage medium having a computer program / instructions stored thereon, characterized in that, When the computer program / instructions are executed by the processor, they implement the steps of the method according to any one of claims 1 to 2.
6. A computer program product comprising a computer program / instructions, characterized in that, When the computer program / instructions are executed by the processor, they implement the steps of the method according to any one of claims 1 to 2.
Citation Information
Patent Citations
Calculating procedure and file verifying method for MD5
CN103886087A
Method and system for realizing inverted index based on character string segmentation on SQL On HBase
CN111625544A