Digital Signature Processing Method, System, Electronic Device and Computer Storage Medium
By formatting conversion and reorganizing ASN.1 format signature data, the problem of client signature verification failure is solved, and the compatibility of digital signatures and the success rate of signature verification is improved.
Patent Information
- Application Number
- CN202211561235.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-07
- Publication Date
- 2025-08-01
- Estimated Expiration
- 2042-12-07
AI Technical Summary
In the prior art, when a client uses ASN.1 format digital signature data signed by a third-party certificate, it is easy to cause the signature verification to fail, reducing the success rate of digital signature verification.
By judging the type of the target signature data, if it is ASN.1 format, the format conversion is performed, the reorganization is reorganized into a standard format, and sent to the server for verification. The specific method includes cutting and recombining the ASN.1 format target signature data to obtain standard format signature data according to the lengths of the data header, the first data segment and the second data segment of the standard ASN.1 format signature data.
Improves the compatibility of client with ASN.1 format signature data and enhances the success rate of digital signature verification.
Smart Images

Figure CN115988094B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of mobile security. Specifically, it relates to a digital signature processing method, system, electronic device, and computer storage medium. Background Art
[0002] A digital signature is a piece of data generated by an information sender that cannot be forged. This data string is also a valid proof of the authenticity and integrity of the information sent by the information sender.
[0003] There are processes of signing and verifying digital signatures. Currently, the signing and verifying of digital signatures can be actively performed by the client using local certificates or third-party certificates for signing; further, the obtained data signature data is directly sent to the server in the obtained form for verification. However, when the signature obtained by the client is a digital signature in a non-standard format, it is likely to cause the verification to fail. Summary of the Invention
[0004] The purpose of the embodiments of this application is to provide a digital signature processing method, system, electronic device, and computer storage medium, which can improve the compatibility of the client with ASN.1 format signature data that may exist in third-party certificates by judging and converting the signature data format.
[0005] In a first aspect, the embodiments of this application provide a digital signature processing method. The digital signature processing method includes: judging the type of target signature data; where the type of the target signature includes standard format signature data and ASN.1 format signature data; if it is determined that the type of the target signature data is ASN.1 format signature data, then perform format conversion on the ASN.1 format target signature data to obtain standard format target signature data; send the standard format target signature data to the target server; where the way of performing format conversion on the ASN.1 format target signature data includes: reorganizing the ASN.1 format target signature data according to a preset format.
[0006] In the above implementation process, after obtaining the target signature data, judge whether its data type is standard format signature data or ASN.1 format signature data; if it is ASN.1 format signature data, convert the ASN.1 format target signature data into standard format target signature through data format conversion, and then send the reorganized standard format target signature to the server for verification. Using the digital signature processing method provided by the embodiments of this application can improve the compatibility of the client data format and further increase the probability of successful digital signature verification.
[0007] Optionally, in the embodiments of the present application, the reorganization of the ASN.1 format target signature data according to a preset format includes: obtaining a preset data header, a preset first data segment, and a preset second data segment of the ASN.1 format target signature data according to the data header length, the length of the first data segment, and the length of the second data segment of the standard ASN.1 format signature data; reorganizing the ASN.1 format target signature data according to the preset data header, the preset first data segment, the preset second data segment, and the ASN.1 format target signature data to obtain the standard format target signature data.
[0008] In the above implementation process, when the target signature data is in ASN.1 format, the ASN.1 format target signature is cropped and reorganized according to the standard ASN.1 format and the ASN.1 format target signature, so as to obtain the standard format target signature data.
[0009] Optionally, in the embodiments of the present application, obtaining a preset data header, a preset first data segment, and a preset second data segment of the ASN.1 format target signature data according to the data header length, the length of the first data segment, and the length of the second data segment of the standard ASN.1 format signature data includes: starting from the first bit of the ASN.1 format target signature data, excluding the preset data header according to the data header length of the standard ASN.1 format signature data; for the ASN.1 format target signature data after excluding the preset data header, starting from the first bit of the ASN.1 format target signature data after excluding the preset data header, obtaining the preset first data segment according to the length of the first data segment; for the ASN.1 format target signature data after excluding the preset data header, sequentially excluding the preset first data segment and the preset data header; and starting from the first bit of the ASN.1 format target signature data after excluding the preset first data segment and the preset data header, obtaining the length of the preset second data segment according to the length of the second data segment.
[0010] In the above implementation process, in the digital signature processing method provided in the embodiments of the present application, according to the data header length, the length of the first data segment, and the length of the second data segment of the standard ASN.1 format signature data, the preset data header, the preset first data segment, and the preset second data segment of the ASN.1 format target signature data can be accurately obtained, which is convenient for subsequent reorganization of the target signature data.
[0011] Optionally, in the embodiments of the present application, restructuring the ASN.1 format target signature data according to a preset data header, a preset first data segment, a preset second data segment, and the ASN.1 format target signature data to obtain the standard format target signature data includes: obtaining the total data length of the ASN.1 format target signature data; obtaining the sum of the lengths of the preset data header, the preset first data segment, and the preset second data segment, and comparing it with the total data length of the ASN.1 format target signature data to obtain a length comparison result; restructuring the ASN.1 format target signature data according to the length comparison result to obtain the standard format target signature data.
[0012] In the above implementation process, restructuring the ASN.1 format target signature data according to a preset data header, a preset first data segment, a preset second data segment, and the ASN.1 format target signature data, thereby obtaining the standard format target signature data. Using the digital signature processing method provided by the embodiments of the present application can restructure the target signature data according to the total length of the preset extracted data segments and the total length of the ASN.1 format target signature data itself to obtain the target signature data in the standard format.
[0013] Optionally, in the embodiments of the present application, the length comparison result includes that the sum of the lengths is greater than the total data length; restructuring the ASN.1 format target signature data according to the length comparison result to obtain the standard format target signature data includes: respectively obtaining the target bit data lengths of the preset first data segment and the preset second data segment to obtain a first processed data segment and a second processed data segment; wherein, the lengths of the first processed data segment and the second processed data segment are respectively the same as the lengths of the first data segment and the second data segment; restructuring the first processed data segment and the second processed data segment to obtain the standard format target signature data.
[0014] In the above implementation process, when the sum of the lengths of the preset data header, the preset first data segment, and the preset second data segment is greater than the total data length, that is, when the data header is too long, directly take the last 256 bits from the first data segment and the second data segment of the ASN.1 format target signature data, and further restructure the extracted data segments to obtain the standard format target signature data.
[0015] Optionally, in the embodiments of the present application, the length comparison result further includes that the sum of the lengths is less than the total data length; restructuring the ASN.1 format target signature data according to the length comparison result to obtain the standard format target signature data further includes: obtaining the length difference between the total data length and the sum of the lengths; padding 0 to the data segment of the length difference; restructuring the preset first data segment and the preset second data segment after padding 0 to obtain the standard format target signature data.
[0016] In the above implementation process, when the sum of the lengths of the preset data header, the preset first data segment, and the preset second data segment is greater than the total data length, zero-padding is performed on the ASN.1 format target signature data according to the difference between the sum of the total data lengths and the sum of the lengths of the preset data header, the preset first data segment, and the preset second data segment, so as to obtain the target signature data in the standard format.
[0017] Optionally, in the embodiments of the present application, the length comparison result further includes that the sum of the lengths is equal to the total data length; restructuring the ASN.1 format target signature data according to the length comparison result to obtain the target signature data in the standard format further includes: restructuring the preset first data segment and the preset second data segment to obtain the target signature data in the standard format.
[0018] In the above implementation process, when the sum of the lengths of the preset data header, the preset first data segment, and the preset second data segment is greater than the total data length, the preset first data segment and the preset second data segment are restructured to obtain the target signature data in the standard format.
[0019] In a second aspect, an embodiment of the present application provides a digital signature processing system, which includes a data type judgment module, a data format conversion module, and a data sending module; the data type judgment module is used to judge the type of the target signature data; wherein, the type of the target signature includes the standard format signature data and the ASN.1 format signature data; the data format conversion module is used to perform format conversion on the ASN.1 format target signature data to obtain the target signature data in the standard format when the type of the target signature data is the ASN.1 format signature data; the data sending module is used to send the target signature data in the standard format to the target server; wherein, when performing format conversion on the ASN.1 format target signature data, the data format conversion module is specifically used to restructure the ASN.1 format target signature data according to a preset format.
[0020] In a third aspect, an embodiment of the present application provides an electronic device, which includes a memory and a processor. When the processor reads and runs the program instructions stored in the memory, it executes the steps in any of the above implementation manners.
[0021] In a fourth aspect, an embodiment of the present application further provides a computer-readable storage medium, in which computer program instructions are stored. When the computer program instructions are read and run by a processor, the steps in any of the above implementation manners are executed. Description of the Drawings
[0022] To more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings required for use in the embodiments of the present application. It should be understood that the following drawings only show some embodiments of the present application and should not be regarded as limiting the scope. For those of ordinary skill in the art, without creative efforts, other related drawings can also be obtained based on these drawings.
[0023] Figure 1 The first flowchart of the digital signature processing method provided by the embodiment of the present application;
[0024] Figure 2 The flowchart of data format conversion provided by the embodiment of the present application;
[0025] Figure 3 The flowchart of data clipping provided by the embodiment of the present application;
[0026] Figure 4 The first flowchart of the target signature data recombination provided by the embodiment of the present application;
[0027] Figure 5 The second flowchart of the target tag name data recombination provided by the embodiment of the present application;
[0028] Figure 6 The third flowchart of the target tag name data recombination provided by the embodiment of the present application;
[0029] Figure 7 The second flowchart of the digital signature processing method provided by the embodiment of the present application;
[0030] Figure 8 The schematic diagram of the standard ASN.1 data format provided by the embodiment of the present application;
[0031] Figure 9 The schematic diagram of the ASN.1 format digital signature data provided by the embodiment of the present application;
[0032] Figure 10 The schematic diagram of the standard format signature data provided by the embodiment of the present application;
[0033] Figure 11 The schematic diagram of the recombined digital signature data provided by the embodiment of the present application
[0034] Figure 12 The module schematic diagram of the digital signature processing system provided by the embodiment of the present application;
[0035] Figure 13 The structural schematic diagram of the electronic device provided by the embodiment of the present application. Detailed implementation manners
[0036] The following will describe the technical solutions in the embodiments of the present application in conjunction with the accompanying drawings in the embodiments of the present application. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architectures, functions, and operations of systems, methods, and computer program products according to multiple embodiments of the present invention. In this regard, each block in the flowchart or block diagram may represent a module, a program segment, or a part of code, and the part of the module, program segment, or code includes one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than that marked in the accompanying drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, as well as the combination of blocks in the block diagram and / or flowchart, may be implemented by a dedicated hardware-based system for performing the specified functions or actions, or may be implemented by a combination of dedicated hardware and computer instructions. In addition, the functional modules in various embodiments of the present invention may be integrated together to form an independent part, or each module may exist alone, or two or more modules may be integrated to form an independent part.
[0037] During the research process, the applicant found that currently, the signing and verification of digital signatures can be actively performed by the client using local certificates or third-party certificates for signing; further, the obtained data signature data is directly sent to the server in the obtained form for verification.
[0038] Although some servers use a verification method for unformatted signature data, for the ASN.1 format data that may exist in third-party certificates, verification failures are likely to occur.
[0039] Based on this, the present application provides a digital signature processing method. For the signature data that needs to be verified, first determine the data type; if it is ASN.1 format signature data, it is necessary to first convert it into a digital signature of standard unformatted data and then perform verification; thereby improving the compatibility of the client with the data and increasing the success rate of digital signature verification.
[0040] Before introducing the specific content of the digital signature processing method of the present application, the digital signature will be introduced first.
[0041] A digital signature is a piece of data generated by the information sender that cannot be forged. This data string is also an effective proof of the authenticity and integrity of the information sent by the information sender. It is a kind of ordinary physical signature similar to that written on paper, but is implemented using technologies in the field of public key cryptography and is a method for authenticating digital information. A set of digital signatures usually defines two complementary operations, one for signing and the other for verification.
[0042] The process of issuing and applying digital signatures will be introduced below.
[0043] Taking the example of user B obtaining information from user A, the process of issuing and applying digital signatures is described as follows. During the process of issuing a digital signature, user A first performs a hashing algorithm on the original data to be sent to obtain a data digest of the information. Then, user A uses their own private key to perform an asymmetric encryption algorithm on the obtained data digest to obtain a digital signature.
[0044] Furthermore, the original information, the digital signature, and user A's public key are symmetrically encrypted together to obtain encrypted information. Then, user B's public key is used to perform an asymmetric encryption on the symmetric encryption algorithm used in the previous step to obtain an encryption key that can only be decrypted by user B's private key. This key and the encrypted information are sent to user B together.
[0045] After receiving user A's information, user B first uses their own private key to decrypt the encryption key sent by user A to obtain the symmetric decryption key - the symmetric key. The symmetric key is used to decrypt the encrypted information to obtain the original information, the digital signature, and user A's public key sent by user A. User B uses user A's public key to decrypt the digital signature to obtain a digital digest, and then uses the same method as user A to perform a hashing algorithm on the original text to obtain another digital digest. These two digital digests are compared. If they are the same, the original text is authentic and has not been tampered with.
[0046] Next, two main data formats involved in this article will be introduced. One is the standard format digital signature, and the other is the ASN.1 format data signature.
[0047] Standard format digital signature. The standard format digital signature consists of two parts: r and s. Generally, the standard digital signature format is a formatless data, directly concatenated by 256-bit r and 256-bit s, which is also the most commonly used method at present.
[0048] The ASN.1 (Abstract Syntax Notation One) format is an ISO / ITU-T standard format that describes data in an abstract way. ASN.1 can be roughly divided into four types: simple types (the most primitive, atomic types without any components), structured types (containing other components), tagged types (derived from other types), and other types. For digital signature data, the ASN.1 format has common simple types, where the type and data size are described by the preceding digits, followed by the data, that is, the ASN.1 format data signature involved in the digital signature processing method of this application embodiment. There are also structured types that segment the data, with the first segment describing r and the second segment describing s, etc.
[0049] Please refer toFigure 1 , Figure 1 is the first flowchart of the digital signature processing method provided by the embodiment of the present application; the digital signature processing method includes the following steps:
[0050] Step S100: Determine the type of the target signature data.
[0051] Step S101: If it is determined that the type of the target signature data is ASN.1 format signature data, perform format conversion on the ASN.1 format target signature data to obtain the target signature data in standard format.
[0052] In the above steps S100 - S101, first determine the data type of the target digital signature; the main data types to be determined in the digital signature method provided by the embodiment of the present application are the signature data in standard format and the signature data in ASN.1 format.
[0053] If it is determined that the data type of the target data signature format is ASN.1 format signature data, then perform format conversion on the ASN.1 format target signature data to obtain the target signature data in standard format.
[0054] Step S102: Send the target signature data in standard format to the target server.
[0055] In the above step S102, continuing from the above, if it is determined that the data type of the target data signature format is ASN.1 format signature data, perform format conversion on the ASN.1 format target signature data to obtain the target signature data in standard format; after converting it into the target signature data in standard format, send the target signature data in standard format to the target server, so as to ensure the signature verification of the target signature data by the target server.
[0056] It should be noted that in the embodiment of the present application, the way to perform format conversion on the ASN.1 format target signature data is mainly to reorganize the ASN.1 format target signature data according to a preset format, and obtain the target signature data in standard format after trimming and reorganizing.
[0057] Through Figure 1 it can be seen that after obtaining the target signature data, determine whether its data type is the signature data in standard format or the signature data in ASN.1 format; if it is the signature data in ASN.1 format, convert the ASN.1 format target signature data into the target signature in standard format through data format conversion, and then send the target signature in standard format generated by recombination to the server for signature verification. Using the digital signature processing method provided by the embodiment of the present application can improve the compatibility of the client data format and further increase the probability of successful digital signature verification.
[0058] Please refer to Figure 2 , Figure 2The flowchart of data format conversion provided by the embodiments of the present application; in the embodiments of the present application, the method of converting the ASN.1 format target signature data into the standard format target signature is to reorganize the ASN.1 format target signature according to a preset format; continuing from the above, reorganizing the ASN.1 format target signature according to the preset format includes the following steps:
[0059] Step S200: Obtain the preset data header, preset first data segment, and preset second data segment of the ASN.1 format target signature data according to the data header length, the length of the first data segment, and the length of the second data segment of the standard ASN.1 format signature data.
[0060] In the above step S200, as described in the previous text, the standard ASN.1 format data includes a data header and the actually used data. The standard ASN.1 format signature data is mainly arranged in the way of including data header - first data segment - data header - second data segment, where the first data segment and the second data segment correspond to the r and s segments mentioned above.
[0061] For the ASN.1 format target signature, obtain the preset data header, preset first data segment, and preset second data segment of the ASN.1 format target signature data according to the data header length, the length of the first data segment, and the length of the second data segment of the standard ASN.1 format signature data.
[0062] Step S201: Reorganize the ASN.1 format target signature data according to the preset data header, preset first data segment, preset second data segment, and the ASN.1 format target signature data to obtain the standard format target signature data.
[0063] In the above step S201, after obtaining the preset data header, preset first data segment, and preset second data segment, reorganize the ASN.1 format target signature data according to the ASN.1 format target signature data itself to obtain the standard format target signature data.
[0064] Through Figure 2 It can be seen that when the target signature data is in the ASN.1 format, according to the standard ASN.1 format and the ASN.1 format target signature, perform clipping and reorganization on the ASN.1 format target signature to obtain the standard format target signature data.
[0065] Please refer to Figure 3 , Figure 3 The flowchart of data clipping provided by the embodiments of the present application; in the embodiments of the present application, obtaining the preset data header, preset first data segment, and preset second data segment of the ASN.1 format target signature data according to the data header length, the length of the first data segment, and the length of the second data segment of the standard ASN.1 format signature data includes the following steps:
[0066] Step S300: starting from the first bit of the target signature data in the ASN.1 format, removing the preset data header according to the data header length of the standard ASN.1 format signature data.
[0067] In the above step S300, the data trimming process firstly takes the first bit of the target signature data in ASN.1 format as the starting point and removes the preset data header of the target signature data in ASN.1 format according to the data header length of the standard ASN.1 format signature data.
[0068] It can be understood that the data structure obtained after removing the preset data header of the ASN.1 format target signature data should be the preset first data segment-preset data header-preset second data segment, that is, r segment-data header-s segment.
[0069] Step S301: for the target signature data in the ASN.1 format after removing the preset data header, taking the first bit of the target signature data in the ASN.1 format after removing the preset data header as the starting point, obtaining the preset first data segment according to the length of the first data segment.
[0070] In step S301, for the target signature data in the ASN.1 format after the preset data header is removed, the first bit of the target signature data in the ASN.1 format after the preset data header is removed is used as a starting point, and the preset first data segment is obtained according to the length of the first data segment. It is understandable that for the target signature data in the ASN.1 format after the preset data header is removed, the preset first data segment of the target signature data in the ASN.1 format is obtained according to the length of the first data segment in the standard ASN.1 format.
[0071] Step S302: For the target signature data in the ASN.1 format after removing the preset data header, remove the preset first data segment and the preset data header in sequence.
[0072] Step S303: starting from the first bit of the target signature data in the ASN.1 format after removing the preset first data segment and the preset data header, obtaining the length of the preset second data segment according to the length of the second data segment.
[0073] In the above steps S302 - S303, similarly, for the ASN.1 format target signature data after removing the preset data header, the preset first data segment and the preset data header are sequentially removed. Since the data composition of the standard ASN.1 format data is data header - first data segment - data header - second data segment; therefore, after removing the preset first data segment, theoretically the next should be the data header, and this data header also needs to be removed. Further, starting from the first bit of the ASN.1 format target signature data after removing the preset first data segment and the preset data header, the length of the preset second data segment is obtained according to the length of the second data segment. It can be understood that for the ASN.1 format target signature data after removing the preset data header and the preset first data segment, the preset second data segment of the ASN.1 format target signature data is obtained according to the length of the second data segment in the standard ASN.1 format.
[0074] Through Figure 3 It can be seen that in the digital signature processing method provided in the embodiment of the present application, according to the lengths of the data header, the first data segment, and the second data segment of the standard ASN.1 format signature data, the preset data header, the preset first data segment, and the preset second data segment of the ASN.1 format target signature data can be accurately obtained, which is convenient for subsequent recombination of the target signature data.
[0075] Please refer to Figure 4 , Figure 4 which is the first flowchart of the target signature data recombination provided in the embodiment of the present application; in the embodiment of the present application, according to the preset data header, the preset first data segment, the preset second data segment, and the ASN.1 format target signature data, the ASN.1 format target signature data is recombined to obtain the standard format target signature data, including the following steps:
[0076] Step S400: Obtain the total data length of the ASN.1 format target signature data.
[0077] In the above step S400, first, obtain the target signature whose data format is determined to be ASN.1 format, that is, the total data length of the ASN.1 format target signature data.
[0078] Step S401: Obtain the sum of the lengths of the preset data header, the preset first data segment, and the preset second data segment, and compare it with the total data length of the ASN.1 format target signature data to obtain a length comparison result.
[0079] In the above step S401, further, obtain the sum of the lengths of the preset data header, the preset first data segment, and the preset second data segment; that is, the sum of the lengths of the data segments taken out previously; it should be noted that when summing, there should be as many data headers as there are data segments. Compare the result of the summation with the total length of the ASN.1 format target signature data to obtain a comparison result.
[0080] Step S402: Recombine the ASN.1 format target signature data according to the length comparison result to obtain the standard format target signature data.
[0081] In the above step S402, it can be understood that the data length comparison result can be consistent, too long, or too short; therefore, the digital signature processing method provided in the embodiments of the present application recombines the SN.1 format target signature data according to the length comparison result to obtain the standard format target signature data.
[0082] By Figure 4 It can be seen that according to the preset data header, the preset first data segment, the preset second data segment, and the ASN.1 format target signature data, the ASN.1 format target signature data is recombined to obtain the standard format target signature data. Using the digital signature processing method provided in the embodiments of the present application can recombine the target signature data according to the total length of the preset extracted data segments and the total length of the ASN.1 format target signature data itself to obtain the target signature data in the standard format.
[0083] Please refer to Figure 5 , Figure 5 FIG. 2 is the second flowchart of the target tag name data recombination provided by the embodiments of the present application; in an alternative embodiment of the present embodiment, if the result of the data length comparison is that the sum of the lengths of the preset data header, the preset first data segment, and the preset second data segment is greater than the total data length, recombine the ASN.1 format target signature data according to the length comparison result to obtain the standard format target signature data, including the following steps:
[0084] Step S500: Respectively obtain the data of the target bit data lengths of the preset first data segment and the preset second data segment to obtain a first processed data segment and a second processed data segment.
[0085] In the above step S500, when the sum of the lengths of the preset data header, the preset first data segment, and the preset second data segment is greater than the total data length, respectively obtain the data of the target bit data lengths of the preset first data segment and the preset second data segment, so as to obtain a first processed data segment and a second processed data segment.
[0086] It should be noted that the lengths of the first processed data segment and the second processed data segment are the same as those of the first data segment and the second data segment respectively; that is, if the sum of the lengths of the preset data header, the preset first data segment, and the preset second data segment is greater than the total data length, the first processed data segment and the second processed data segment are taken out respectively according to the lengths of the first data segment and the second data segment. Those skilled in the art can understand that the reason for this situation is that the data header of the ASN.1 format target signature data is too long. When the data header is too long, directly take the last 256 bits from the first data segment and the second data segment of the ASN.1 format target signature data.
[0087] It is particularly noteworthy that the first processed data segment and the second processed data segment are the last 256 bits from the preset first data segment and the preset second data segment.
[0088] Step S501: Recombine the first processed data segment and the second processed data segment to obtain the target signature data in standard format.
[0089] In the above step S501, the last 256 bits of the preset first data segment and the preset second data segment taken out, that is, the first processed data segment and the second processed data segment, are recombined, and the target signature data in standard format is obtained after recombination; it can be understood that the format of the obtained target signature data in standard format should be the first processed data segment - the second data segment.
[0090] Through Figure 5 It can be seen that when the sum of the lengths of the preset data header, the preset first data segment, and the preset second data segment is greater than the total data length, that is, when the data header is too long, directly take the last 256 bits from the first data segment and the second data segment of the ASN.1 format target signature data, and further recombine the taken-out data segments to obtain the target signature data in standard format.
[0091] Please refer to Figure 6 , Figure 6 which is the third flowchart of the target tag name data recombination provided by the embodiment of the present application; in an alternative embodiment of this embodiment, if the result of the data length comparison is that the sum of the lengths of the preset data header, the preset first data segment, and the preset second data segment is less than the total data length, the ASN.1 format target signature data is recombined according to the length comparison result to obtain the target signature data in standard format, including the following steps:
[0092] Step S600: Obtain the length difference between the total data length and the sum of the lengths.
[0093] In the above step S600, when the sum of the lengths of the preset data header, the preset first data segment, and the preset second data segment is greater than the total data length, obtain the difference between the sum of the total data lengths and the sum of the lengths of the preset data header, the preset first data segment, and the preset second data segment.
[0094] Step S601: Pad zeros to the data segment with a length difference.
[0095] In the above step S601, following the context, obtain the difference between the sum of the total data lengths and the sum of the lengths of the preset data header, the preset first data segment, and the preset second data segment. On this basis, using this length difference as a standard, perform a zero-padding operation on the ASN.1 format target signature data.
[0096] Step S602: Recombine the preset first data segment and the preset second data segment after zero-padding to obtain the target signature data in the standard format.
[0097] In the above step S602, recombine the preset first data segment and the preset second data segment after zero-padding to obtain the target signature data in the standard format. It can be understood that the format of the target signature data in the standard format should be: the preset first data segment after zero-padding - the preset second data segment after zero-padding.
[0098] Through Figure 6 It can be seen that when the sum of the lengths of the preset data header, the preset first data segment, and the preset second data segment is greater than the total data length, perform a zero-padding operation on the ASN.1 format target signature data according to the difference between the sum of the total data lengths and the sum of the lengths of the preset data header, the preset first data segment, and the preset second data segment, so as to obtain the target signature data in the standard format.
[0099] In an optional embodiment, when the sum of the lengths of the preset data header, the preset first data segment, and the preset second data segment is equal to the total data length, the reorganization of the ASN.1 format target signature data according to the length comparison result to obtain the target signature data in the standard format further includes: recombining the preset first data segment and the preset second data segment to obtain the target signature data in the standard format. It can be understood that on this basis, the format of the target signature data in the standard format should be: the preset first data segment - the preset second data segment.
[0100] It can be seen that when the sum of the lengths of the preset data header, the preset first data segment, and the preset second data segment is greater than the total data length, recombine the preset first data segment and the preset second data segment to obtain the target signature data in the standard format.
[0101] Please refer to Figure 7 , Figure 7 which is the second flowchart of the digital signature processing method provided by the embodiment of the present application; please refer to it in combination with Figures 8 - 11 , Figure 8 which is the schematic diagram of the standard ASN.1 data format provided by the embodiment of the present application; Figure 9 which is the schematic diagram of the ASN.1 format digital signature data provided by the embodiment of the present application;Figure 10 A schematic diagram of the standard format signature data provided in the embodiment of the present application; Figure 11 Schematic diagram of the reorganized digital signature data provided in an embodiment of the present application.
[0102] Step S700: Obtain target digital signature data in an unknown format.
[0103] Step S701: Determine the data format of the target digital signature data.
[0104] Step S702: If the data format of the target digital signature data is ASN.1 format signature data, the ASN.1 format signature data is disassembled and reassembled.
[0105] Step S703: If the data format of the target digital signature data is standard format signature data, the standard format signature data is sent to the target server.
[0106] In the above steps S701-S703, the client first Figure 8 ) and the normal unformatted digital signature number (such as Figure 10 As shown) judge whether it is as follows Figure 9 The ASN.1 standard format shown is as follows. Figure 10 The unformatted standard signature data format shown is directly sent to the server for verification, and the ASN1 standard separates and reassembles the r and s.
[0107] For disassembling and reassembling the ASN.1 format signature data, for example, since the output data after the third-party certificate signature is a character array, the client first removes the imaginary ASN.1 type header and takes out the first data describing the length of r. Furthermore, the length of r is used to obtain the location for storing the length of s, and the length of r, the length of s, and the length of the imaginary ASN.1 structure header are compared with the entire data length to verify whether it is data that conforms to the ASN.1 structure; if the length is too long, it means that the digital signature data header in the ASN.1 format is long, and the last 256 bits of the r and s data can be directly taken. For shorter r and s, 0-padding operation can be performed, so that we can get a standard unformatted digital signature that we need. The reassembled digital signature data can be found in Figure 11 .
[0108] pass Figure 7 It can be seen that the digital signature processing method provided in the embodiment of the present application first determines the data type of the signature data that needs to be verified; if the signature data is in ASN.1 format, it must first be converted into a digital signature of standard unformatted data and then verified; it can improve the client's compatibility with the data, thereby improving the success rate of digital signature verification.
[0109] Please refer to Figure 12 , Figure 12 which is a schematic diagram of the modules of the digital signature processing system provided by the embodiment of the present application; the digital signature processing system 100 includes: a data type judgment module 110, a data format conversion module 120, and a data sending module 130.
[0110] The data type judgment module 110 is used to judge the type of the target signature data; among them, the type of the target signature includes standard format signature data and ASN.1 format signature data.
[0111] The data format conversion module 120 is used to perform format conversion on the ASN.1 format target signature data to obtain standard format target signature data when the type of the target signature data is ASN.1 format signature data.
[0112] The data sending module 130 is used to send the standard format target signature data to the target server; among them, when performing format conversion on the ASN.1 format target signature data, the data format conversion module is specifically used to reorganize the ASN.1 format target signature data according to a preset format.
[0113] In an optional embodiment, the reorganization of the ASN.1 format target signature data according to a preset format includes: obtaining a preset data header, a preset first data segment, and a preset second data segment of the ASN.1 format target signature data according to the data header length, the length of the first data segment, and the length of the second data segment of the standard ASN.1 format signature data; reorganizing the ASN.1 format target signature data according to the preset data header, the preset first data segment, the preset second data segment, and the ASN.1 format target signature data to obtain standard format target signature data.
[0114] In an alternative embodiment, the data format conversion module 120 of the digital signature processing system includes a data disassembling module 121 and a data segment obtaining module 122. The data format conversion module 120 obtains a preset data header, a preset first data segment, and a preset second data segment of the ASN.1 format target signature data according to the data header length, the length of the first data segment, and the length of the second data segment of the standard ASN.1 format signature data, including: The data disassembling module 121 starts from the first bit of the ASN.1 format target signature data and removes the preset data header according to the data header length of the standard ASN.1 format signature data; for the ASN.1 format target signature data after removing the preset data header, starting from the first bit of the ASN.1 format target signature data after removing the preset data header, the data disassembling module 121 obtains the preset first data segment according to the length of the first data segment; for the ASN.1 format target signature data after removing the preset data header, the preset first data segment and the preset data header are removed in sequence; and the data segment obtaining module 122 starts from the first bit of the ASN.1 format target signature data after removing the preset first data segment and the preset data header and obtains the length of the preset second data segment according to the length of the second data segment.
[0115] In an alternative embodiment, the data format conversion module 120 of the digital signature processing system further includes a data recombination module 123. The data format conversion module 120 recombines the ASN.1 format target signature data according to the preset data header, the preset first data segment, the preset second data segment, and the ASN.1 format target signature data to obtain the standard format target signature data, including: The data segment obtaining module 122 obtains the total data length of the ASN.1 format target signature data; the data segment obtaining module 122 obtains the sum of the lengths of the preset data header, the preset first data segment, and the preset second data segment and compares it with the total data length of the ASN.1 format target signature data to obtain a length comparison result; the data recombination module 123 recombines the ASN.1 format target signature data according to the length comparison result to obtain the standard format target signature data.
[0116] In an alternative embodiment, the length comparison result includes that the length is greater than the total data length; recombining the ASN.1 format target signature data according to the length comparison result to obtain the standard format target signature data includes: The data segment obtaining module 122 respectively obtains the data of the target bit data lengths of the preset first data segment and the preset second data segment to obtain a first processed data segment and a second processed data segment; wherein, the lengths of the first processed data segment and the second processed data segment are respectively the same as the lengths of the first data segment and the second data segment. The data recombination module 123 recombines the first processed data segment and the second processed data segment to obtain the standard format target signature data.
[0117] In an optional embodiment, the length comparison result further includes that the sum of the lengths is less than the total data length; the data recombination module 123 recombines the ASN.1 format target signature data according to the length comparison result to obtain the standard format target signature data, and further includes: the data recombination module 123 obtains the length difference between the total data length and the sum of the lengths; pads zeros to the data segment of the length difference; the data recombination module 123 recombines the preset first data segment and the preset second data segment after padding zeros to obtain the standard format target signature data.
[0118] In an optional embodiment, the length comparison result further includes that the sum of the lengths is equal to the total data length; the data recombination module 123 recombines the ASN.1 format target signature data according to the length comparison result to obtain the standard format target signature data, and further includes: the data recombination module 123 recombines the preset first data segment and the preset second data segment to obtain the standard format target signature data.
[0119] Please refer to Figure 13 , Figure 13 which is the structural schematic diagram of the electronic device provided by the embodiment of the present application. An electronic device 300 provided by the embodiment of the present application includes: a processor 301 and a memory 302. The memory 302 stores machine-readable instructions executable by the processor 301. When the machine-readable instructions are executed by the processor 301, the above method is executed.
[0120] Based on the same inventive concept, the embodiment of the present application further provides a computer-readable storage medium. Computer program instructions are stored in the computer-readable storage medium. When the computer program instructions are read and run by a processor, the steps in any of the above implementation manners are executed.
[0121] The computer-readable storage medium may be a random access memory (RAM), a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or other various media that can store program codes. Among them, the storage medium is used to store a program. After receiving an execution instruction, the processor executes the program. The method executed by the electronic terminal defined by the process disclosed in any embodiment of the present invention can be applied to the processor or implemented by the processor.
[0122] In the embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of the units is only a logical function division, and there can be other division methods in actual implementation. For another example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the couplings or direct couplings or communication connections shown or discussed with each other can be through some communication interfaces, and the indirect couplings or communication connections of the devices or units can be in electrical, mechanical or other forms.
[0123] In addition, the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they can be located in one place, or they can be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0124] Furthermore, in each embodiment of this application, the various functional modules can be integrated together to form an independent part, or each module can exist alone, or two or more modules can be integrated to form an independent part.
[0125] Alternatively, it can be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on the computer, the processes or functions described in the embodiments of the present invention are generated in whole or in part.
[0126] The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center in a wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.) manner.
[0127] In this document, relational terms such as first and second are used solely to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprise," "include," or any other variant thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a series of elements includes not only those elements but also other elements not expressly listed, or elements that are inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the statement "comprising..." does not exclude the presence of additional identical elements in the process, method, article, or apparatus that comprises the said element.
[0128] The above description is only for the embodiments of this application and is not intended to limit the scope of protection of this application. For those skilled in the art, this application may have various modifications and changes. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of this application shall be included within the scope of protection of this application.
Claims
1. A digital signature processing method, characterized in that The method comprises: Determine the type of target signature data; wherein the type of target signature includes standard format signature data and ASN.1 format signature data; If it is determined that the type of the target signature data is the ASN.1 format signature data, performing format conversion on the ASN.1 format target signature data to obtain standard format target signature data; Sending the standard format target signature data to the target server; The method of converting the format of the target signature data in the ASN.1 format includes: reorganizing the target signature data in the ASN.1 format according to a preset format.
2. The method according to claim 1, wherein The ASN.1 format target signature data is reorganized according to a preset format, including: Obtaining a preset data header, a preset first data segment, and a preset second data segment of the target signature data in the ASN.1 format according to the data header length, the length of the first data segment, and the length of the second data segment of the standard ASN.1 format signature data; The ASN.1 format target signature data is reorganized according to the preset data header, the preset first data segment, the preset second data segment and the ASN.1 format target signature data to obtain standard format target signature data.
3. The method according to claim 2, wherein The step of obtaining a preset data header, a preset first data segment, and a preset second data segment of the target signature data in the ASN.1 format according to the data header length, the length of the first data segment, and the length of the second data segment of the standard ASN.1 format signature data includes: Taking the first bit of the target signature data in the ASN.1 format as the starting point, the preset data header is removed according to the data header length of the standard ASN.1 format signature data; For the target signature data in the ASN.1 format after the preset data header is removed, taking the first bit of the target signature data in the ASN.1 format after the preset data header is removed as a starting point, and obtaining the preset first data segment according to the length of the first data segment; For the target signature data in the ASN.1 format after removing the preset data header, sequentially removing the preset first data segment and the preset data header; and Taking the first bit of the ASN.1 format target signature data after removing the preset first data segment and the preset data header as a starting point, the length of the preset second data segment is obtained according to the length of the second data segment.
4. The method according to claim 2, wherein The step of reorganizing the ASN.1 format target signature data according to the preset data header, the preset first data segment, the preset second data segment, and the ASN.1 format target signature data to obtain the standard format target signature data includes: Obtain the total length of the target signature data in the ASN.1 format; Obtaining the sum of the lengths of the preset data header, the preset first data segment, and the preset second data segment, and comparing the sum with the total length of the target signature data in the ASN.1 format to obtain a length comparison result; The ASN.1 format target signature data is reorganized according to the length comparison result to obtain the standard format target signature data.
5. The method according to claim 4, wherein Reorganizing the ASN.1 format target signature data according to the length comparison result to obtain the standard format target signature data includes: If the length comparison result is that the sum of the lengths is greater than the total data length, respectively obtain the data of the target bit data lengths of the preset first data segment and the preset second data segment to obtain a first processed data segment and a second processed data segment; wherein, the lengths of the first processed data segment and the second processed data segment are respectively the same as the lengths of the first data segment and the second data segment; Recombine the first processed data segment and the second processed data segment to obtain the standard format target signature data.
6. The method according to claim 4, wherein Reorganizing the ASN.1 format target signature data according to the length comparison result to obtain the standard format target signature data further includes: If the length comparison result is that the sum of the lengths is less than the total data length, obtain the length difference between the total data length and the sum of the lengths; Pad 0 to the data segment of the length difference; Recombine the preset first data segment and the preset second data segment after padding 0 to obtain the standard format target signature data.
7. The method according to claim 4, characterized in that, Reorganizing the ASN.1 format target signature data according to the length comparison result to obtain the standard format target signature data further includes: If the length comparison result is that the sum of the lengths is equal to the total data length, recombine the preset first data segment and the preset second data segment to obtain the standard format target signature data.
8. A digital signature processing system, characterized in that, The digital signature processing system includes: a data type judgment module, a data format conversion module, and a data sending module; The data type judgment module is used to judge the type of the target signature data; wherein, the type of the target signature includes standard format signature data and ASN.1 format signature data; The data format conversion module is used to perform format conversion on the ASN.1 format target signature data to obtain the standard format target signature data when the type of the target signature data is the ASN.1 format signature data; The data sending module is used to send the standard format target signature data to the target server; Among them, when performing format conversion on the ASN.1 format target signature data, the data format conversion module is specifically used to reorganize the ASN.1 format target signature data according to a preset format.
9. An electronic device, characterized in that, The electronic device includes a memory and a processor. When the processor runs the program instructions stored in the memory, it executes the steps in the method according to any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer program instructions. When the computer program instructions are run by a processor, it executes the steps in the method according to any one of claims 1-7.
Citation Information
Patent Citations
Electronic sign-off file processing method and apparatus
CN106484835A
Digital signature system using mobile terminal
KR101502944B1