Data protection method and device, electronic equipment and storage medium
The data protection method uses Protobuf's reflection capability to identify and desensitize sensitive fields across multiple programming languages, addressing high development costs and facilitating business upgrades by keeping business logic codes intact.
Patent Information
- Application Number
- CN202310650825.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-02
- Publication Date
- 2024-12-03
AI Technical Summary
Existing data protection methods in programming languages other than Java require invasive changes to business logic codes, leading to high development costs and hindering business upgrades.
A data protection method utilizing the reflection capability of Protobuf to identify and desensitize sensitive fields in message objects through a Proto description file, independent of business logic codes, supporting multiple programming languages and reducing development costs.
Enables cross-language data protection with reduced development costs and supports continuous business upgrades by using Protobuf's reflection capability to identify and desensitize sensitive fields without modifying business logic codes.
Smart Images

Figure CN119066694A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a data protection method, device, electronic device and storage medium. Background Art
[0002] Data protection refers to the deformation of certain sensitive information through desensitization rules to achieve reliable protection of sensitive privacy data. In application scenarios such as data transmission and storage, data involving user security or some commercially sensitive data needs to be desensitized to protect data security.
[0003] In the related technologies, only programs written in the Java programming language can protect sensitive data through its reflection capabilities during operation; while for programs written in other programming languages such as C++, developers are required to forcibly invade business logic codes to protect data, resulting in additional development costs and being unfavorable for business changes and upgrades. Summary of the invention
[0004] In order to solve the problems of language limitation and high development cost in the data protection solutions in the prior art, the present application provides a data protection method, device, electronic device and storage medium:
[0005] According to a first aspect of the present application, a data protection method is provided, comprising:
[0006] During the program running process, the description information of each message field in the message object and the field value of each message field are obtained through the reflection interface; the description information of each message field is defined in the Proto description file of the program;
[0007] Get the extended field in the Proto description file; the extended field is used to mark the message field to be protected; the extended field is a custom message type, and the custom message type includes at least one desensitizing field; the desensitizing field represents the desensitizing method implemented on the message field to be protected;
[0008] Determine the message field of the description information carrying the extension field in the message object as the target message field;
[0009] The field value of the target message field in the message object is desensitized based on the desensitized field to obtain a processed message object.
[0010] According to a second aspect of the present application, a data protection device is provided, including:
[0011] The first acquisition module is used to obtain the description information of each message field and the field value of each message field in the message object through the reflection interface during the program running process; the description information of each message field is defined in the Proto description file of the program;
[0012] The second acquisition module is used to obtain the extended field in the Proto description file; the extended field is used to mark the message field to be protected; the extended field is a custom message type, and the custom message type includes at least one desensitizing field; the desensitizing field represents the desensitization method implemented on the message field to be protected;
[0013] A determination module, used to determine the message field carrying the extended field in the description information in the message object as the target message field;
[0014] The desensitizing module is used to perform desensitization processing on the field value of the target message field in the message object based on the desensitizing field to obtain the processed message object.
[0015] According to a third aspect of the present application, an electronic device is provided, comprising a processor and a memory, wherein at least one instruction or at least one program is stored in the memory, and the at least one instruction or at least one program is loaded and executed by the processor to implement the data protection method of the first aspect.
[0016] According to the fourth aspect of the present application, a computer-readable storage medium is provided, in which at least one instruction or at least one program is stored, and the at least one instruction or at least one program is loaded and executed by a processor to implement the data protection method of the first aspect.
[0017] According to a fifth aspect of the present application, a computer program is provided, which implements the data protection method of the first aspect when executed by a processor.
[0018] The data protection method, device, electronic device and storage medium provided by the present application have the following technical effects:
[0019] The data protection method of the present application utilizes the reflection capability of protobuf. When the program is running, the description information of each message field in the message object is obtained through the reflection interface, the target message field that needs to be desensitized in the message object is identified and desensitized, and finally the processed message object is output, thereby realizing data protection. On the one hand, the cross-language feature of protobuf enables the data protection method of the embodiment of the present application to support multiple programming languages and be suitable for different language platforms. On the other hand, the Proto description file is independent of the business logic code file of the program, and is simple to modify, which can significantly reduce development costs and is conducive to the continuous upgrading of the business. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions and advantages in the embodiments of the present application or the prior art, the drawings required for use in the embodiments or the prior art descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0021] Figure 1 is a schematic diagram of an application environment provided by an embodiment of the present application;
[0022] Figure 2 It is a flowchart of a data protection method provided in an embodiment of the present application;
[0023] Figure 3 It is a flowchart of extending the original Proto description file of a program provided by an embodiment of the present application;
[0024] Figure 4 This is a schematic diagram of a process for creating a Proto extension file provided in an embodiment of the present application;
[0025] Figure 5 It is a flow chart of desensitizing the field value of the target message field in the message object based on the desensitized field provided by an embodiment of the present application;
[0026] Figure 6 This is a schematic diagram of a desensitization process provided in an embodiment of the present application;
[0027] Figure 7 This is a schematic diagram of a character encoding conversion process provided by an embodiment of the present application;
[0028] Figure 8 It is a block diagram of a data protection device provided in an embodiment of the present application;
[0029] Fig. 9 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0030] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0031] It should be noted that the terms "including" and "having" and any variations thereof in the specification and claims of this application and the above-mentioned drawings are intended to cover non-exclusive inclusions. For example, a process, method, system, product or server that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0032] Before further describing the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are explained. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations.
[0033] Protobuf (Protocol Buffers): It is a cross-language and cross-platform serialized data structure method developed by Google. It is a flexible and efficient protocol for serializing data.
[0034] Proto description file: Message protocol prototype definition file, in which the message format required in the program is defined using a descriptive language.
[0035] See also Figure 1 , Figure 1 It is a schematic diagram of an application environment of a data protection method provided in an embodiment of the present application. The application environment may include a server 01 and a client 02. The server 01 and the client 02 perform data transmission based on the Protobuf protocol, and the server 01 also performs data storage based on the Protobuf protocol.
[0036] The server 01 can provide background services for the client 02. The server 01 can desensitize the data related to user security or commercially sensitive data in the background service through the data protection method of the embodiment of the present application, so as to avoid the exposure of these data causing user security problems or affecting enterprise operations.
[0037] In one possible application scenario, the server 01 may store the data sent by the client 02 during the background service process. When the server 01 subsequently calls the data to implement other applications, the server 01 desensitizes the data using the data protection method of the embodiment of the present application, and then uses the desensitized data to implement other applications. Alternatively, in another possible application scenario, when providing background services to the client 02, the server 01 desensitizes the sensitive data that needs to be sent to the client 02, and sends the desensitized data to the client 02, thereby ensuring data security without affecting the implementation of the background service.
[0038] The server 01 may be an independent physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The server may include a network communication unit, a processor, a memory, and the like.
[0039] The client 02 may be a physical device such as a smart phone, a computer (such as a desktop computer, a tablet computer, a laptop computer), an augmented reality (AR) / virtual reality (VR) device, a digital assistant, an intelligent voice interaction device (such as an intelligent speaker), an intelligent wearable device, an intelligent home appliance, a vehicle-mounted terminal, etc., or may be software running in a physical device, such as a computer program. The operating system corresponding to the client may be an Android system (Android system), an iOS system (a mobile operating system developed by Apple), a Linux system (an operating system), a Microsoft Windows system (Microsoft Windows operating system), etc.
[0040] It should be noted that for the account data involved in the embodiments of the present application, when the embodiments of the present application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of relevant countries and regions.
[0041] The following describes a specific embodiment of a data protection method of the present application. Figure 2 It is a flowchart of a data protection method provided by an embodiment of the present application. The present application provides method operation steps as described in the embodiment or flowchart, but may include more or fewer operation steps based on conventional or non-creative labor. The order of steps listed in the embodiment is only one way of executing the steps among many orders, and does not represent the only order of execution. When the actual system or product is executed, it can be executed in the order of the method shown in the embodiment or the drawings or in parallel (for example, in a parallel processor or multi-threaded processing environment). Specifically, Figure 2 As shown, the method may include:
[0042] S201: During program execution, the description information of each message field and the field value of each message field in the message object are obtained through the reflection interface; the description information of each message field is defined in the Proto description file of the program.
[0043] Among them, the program may refer to the relevant program run by the server when providing background services to the front-end client for implementing the background service. The background services include but are not limited to data query services, data processing services, etc., and the process of providing background services usually involves interaction with the front-end client; or, the program may also refer to the relevant program run by the server when implementing services unrelated to the front-end based on stored data. Here, services unrelated to the front-end refer to services that do not involve interaction with the front-end client. For example, the services of the server to organize or analyze stored log data, service data, etc. do not involve interaction with the front-end client.
[0044] It should be noted that the program in the embodiment of the present application can be a program developed based on any programming language such as C, C++, Java, etc.
[0045] In some possible application scenarios, when the server provides background services such as account information query service, account transaction information query service, and account balance information query service, it will involve the sending of sensitive data such as account information, account transaction information, and account balance. In addition, when the server processes and analyzes stored log data in the background, it may also involve outputting sensitive data such as account information, account transaction information, and account balance to data analysis tools. For businesses such as the above that involve the use of sensitive data, the server needs to desensitize these sensitive data during the operation of related programs to protect the data from being fully exposed, thereby improving data security.
[0046] In an embodiment of the present application, the server performs data transmission and storage based on the Protobuf protocol. Therefore, the server can utilize the reflection mechanism of Protobuf to obtain any Message message object defined in the Proto description file and the description information of each message field in the Message through a specified interface when the program is running. The description information of each message field includes at least: field type, data type, field name and field number.
[0047] Field types include: basic type, nested type and array type. A nested type refers to a message nested in another message, and the field type of the nested message is a nested type; an array type is a repeated type, which means that the corresponding field can be repeated any number of times, including 0 times, and the order of repeated data will be saved in the protocol buffer; except for the above nested types and array types, the remaining field types are basic types, which can include but are not limited to required types, optional types, etc.
[0048] The data types are consistent with various programming language data types, such as int32, string, float, etc.
[0049] The field names are basically the same as variable names in languages such as C, C++, and Java, such as pwd, nick, and so on.
[0050] The field number is a unique identifier for the field identity. It is used to identify the field in the compiled binary message format, that is, the field number will be used in serialization and deserialization. The range is [1,536870911], where 19000 to 19999 are reserved numbers.
[0051] In the embodiment of the present application, the Proto description file of the program marks which message fields belong to the message fields to be protected, the message fields to be protected are sensitive fields, and the corresponding field values are sensitive data; specifically, ordinary message fields and message fields to be protected are distinguished by description information; for the message fields to be protected, in addition to the above-mentioned field type, data type, field name and field number, the description information also includes sensitive identification information, which indicates that the field value corresponding to the message field needs to be desensitized;
[0052] In Proto, a message type is defined by specifying the keyword message. Therefore, for example, in a Proto description file corresponding to a program that uses account data, the following Message object named "UserData" is defined:
[0053] Example 1:
[0054] message UserData{
[0055] optional string pwd=1[(xm_sensitive)={clear=true}];
[0056] optional string nick=2[(xm_sensitive)={mask=true}];
[0057] }
[0058] Among them, "[(xm_sensitive)={clear=true}]" and "[(xm_sensitive)={mask=true}]" are sensitive identification information, indicating that the password data corresponding to the message field "pwd" and the nickname data corresponding to "nick" need to be desensitized; the meaning of each field in the sensitive identification information in the example here will be explained in detail below and will not be repeated here.
[0059] In an embodiment of the present application, the Proto description file is reflected through the proto reflect library, and the reflect library provides a reflection interface ListFields(). The server calls the reflection interface when the program is running, and can dynamically read and write the description information of each message object defined in the Proto description file and each message field in the message object.
[0060] S203: Obtain an extension field in the Proto description file; the extension field is used to mark the message field to be protected; the extension field is a custom message type, and the custom message type includes at least one desensitizing field; the desensitizing field represents the desensitizing method implemented on the message field to be protected.
[0061] In an embodiment of the present application, sensitive identification information is added to the description information of the message field to be protected in the Proto description file in advance. In this way, after the description information of each message field is obtained through the reflection interface when the program is running, it can be determined whether to perform desensitization on the corresponding field value by identifying whether the description information carries the sensitive identification information.
[0062] Among them, the sensitive identification information may include an extended proto field, that is, the program development end needs to expand the original Proto description file of the program in advance, and add relevant descriptions of the extended field to the message field to be protected to complete the addition of sensitive identification information. Here, the data type of the extended field can be a custom message type, and at least one desensitizing field can be defined in the custom message type. The desensitizing field is used to characterize the desensitizing method implemented on the message field to be protected. It should be noted that in some application scenarios, the program development end can be the server.
[0063] Therefore, in order to implement the above S203, the original Proto description file of the program needs to be expanded in advance; thus, in some possible embodiments, the data protection method of the embodiment of the present application may also include the following: Figure 3 The following steps are shown:
[0064] S301: Acquire the original Proto description file of the program; the original Proto description file includes the original description information of each message field.
[0065] In this step, the server can obtain the original Proto description file of the program to expand the original Proto description file and complete the marking of sensitive fields; wherein the original Proto description file contains all Message message objects involved in the program and the original description information of each message field in each message object, where the original description information is the above-mentioned field type, data type, field name and field number.
[0066] S303: Create a Proto extension file; the Proto extension file includes definition information of the custom message type and definition information of the extension field.
[0067] Among them, the definition information of the custom message type includes the structural information of the custom message object, that is, which fields are contained in the custom message object and the description information of each field. For details, please refer to the example above; the extended field is used to mark the message field to be protected in the original Proto description file; if you want to use the extended field for marking, you need to define the extended field first.
[0068] Therefore, in this step, a Proto extension file is first created. In the Proto extension file, a custom message type can be created according to at least one data masking method, that is, different masking fields are defined in the structural information of the custom message type to represent different data masking methods; then, the data type of the extension field is defined as the custom message type.
[0069] In a specific embodiment, the above step S303 may specifically include the following: Figure 4 The following steps are shown:
[0070] S401: Construct a custom message type through message keywords, and define a first desensitized field and a second desensitized field in the custom message type.
[0071] In this step, a custom message type is constructed by using the keyword message. Based on different data sensitivities, a first desensitizing field and a second desensitizing field can be defined in the custom message type, wherein the first desensitizing field represents a desensitizing method for completely masking the data, and the second desensitizing field represents a desensitizing method for partially masking the data; for example, a partial masking desensitizing method can be selected for nickname data and mobile phone data, and a full masking desensitizing method can be selected for password data.
[0072] S403: construct an extended field through an extended keyword, and define the data type of the extended field as a custom message type.
[0073] In this step, the extended field is defined by using the keyword extend, and the data type of the extended field is set to the above-mentioned custom message type.
[0074] Based on the above description, the following is a specific example of a Proto extension file in an embodiment of the present application. The Proto extension file can be named pboption.proto. It can be understood that this example is used to more clearly understand the method of creating a Proto extension file in an embodiment of the present application, and does not constitute any limitation on the present application.
[0075] Example 2:
[0076] import"google / protobuf / descriptor.proto";
[0077] message MaskOptions{
[0078] optional bool clear = 1;
[0079] optional bool mask = 2;
[0080] }
[0081] extend google.protobuf.FieldOptions{
[0082] optional MaskOptions xm_sensitive=50005;
[0083] }
[0084] In this example 2, first, the descriptor.proto file dedicated to the extended protobuf is introduced; secondly, the message type named "MaskOptions" is defined through the message keyword, in which the first desensitizing field "clear" and the second desensitizing field "mask" are defined to represent the two data desensitizing methods of full masking and partial masking respectively; in actual applications, other desensitizing methods can be added by extending the message type, such as encrypted desensitizing methods; finally, the extend keyword is used to extend the protobuf field options, define an extended field named "xm_sensitive" with a field number of "50005", and set its data type to "MaskOptions".
[0085] S305: Introduce the Proto extension file into the original Proto description file.
[0086] In this step, the Proto extension file is introduced into the original Proto description file through the standard extension statement; for example, the Proto extension file of Example 2 above is introduced into the original Proto description file (Example 1) through "import "pboption.proto";".
[0087] It should be noted that the Proto extension file can be generally applied to programs corresponding to different businesses on the server, and the Proto extension file can be introduced into the original Proto description files corresponding to different programs.
[0088] S307: Add the extended field to the original description information of the message field to be protected to obtain an extended Proto description file.
[0089] In this step, the message field to be protected in the original Proto description file can be identified manually or by automatic scanning using relevant tools, and then new description information is added based on the original description information of the message field to be protected, that is, the relevant description of the extended field is added to the message field to be protected; after the addition is completed, save it to obtain the extended Proto description file; the message field to be protected is marked in the extended Proto description file.
[0090] The description of the extension field added in this step is the sensitive identification information shown in Example 1 above. Referring to Example 1, the description of adding the extension field "xm_sensitive" to the message field "pwd" to be protected is "[(xm_sensitive) = {clear = true}]", which means that the password data is desensitized by the first desensitizing field "clear" and the full masking data corresponding to the first desensitizing field "clear" is adopted; the description of adding the extension field "xm_sensitive" to the message field "nick" to be protected is "[(xm_sensitive) = {mask = true}]", which means that the nickname data is desensitized by the second desensitizing field "mask" and the partial masking data corresponding to the second desensitizing field "mask" is adopted.
[0091] S309: Compile and publish the extended Proto description file.
[0092] In this step, the extended Proto description file is recompiled, specifically based on the programming language used by the program; the compiled Proto description file is then redeployed online, that is, published to the server running the program.
[0093] In the above embodiment, the program development end, i.e., the server end, creates a Proto extension file, and then marks the message fields to be protected in the original Proto description file based on the extension fields defined in the Proto extension file, thereby paving the way for data protection during subsequent program execution. Since the Proto description file is independent of the business logic code file of the program, the above embodiment only needs to modify the Proto description file of the program without modifying the business logic code file of the program. The modification is simple and can significantly reduce development costs. Proto supports backward compatibility, and the extended Proto description file can also be used for old versions of the program to implement data protection without the need to redevelop the old version of the program, which is also conducive to the continuous upgrading of the business.
[0094] S205: Determine the message field in the message object that contains the extended field as the target message field.
[0095] S207: Desensitizing the field value of the target message field in the message object based on the desensitized field to obtain a processed message object.
[0096] In an embodiment of the present application, the description information of the message field to be protected carries sensitive identification information, namely, an extension field and a corresponding desensitized field. Therefore, when the program is running, the server can traverse each message field in the message object based on the extension field for each message object, identify the message field carrying the extension field in the description information and determine it as the target message field, and then desensitize the field value of the target message field based on the carried desensitized field, and finally obtain the processed message object.
[0097] In actual applications, the above steps S205 to S207 can be implemented by calling the field desensitization function DesensitizeField(). The code implementation inside the specific function can be written according to actual needs, and this application does not limit this.
[0098] The following introduces a possible implementation example of desensitizing the field value of the target message field in the message object based on the desensitized field. In actual applications, the code logic of the field desensitization function can be determined based on the desensitization process of the implementation example, and the corresponding code can be implemented based on the logic.
[0099] In some possible embodiments, when the data type of the target message field is a string data type, the field value of the target message field is a string. When identifying the desensitization field carried by the target message field, such as the "mask" field in Example 1 above, which indicates the implementation of a partially masked desensitization method, the above S207 may include the following: Figure 5 The following steps are shown:
[0100] S501: Determine whether the length of the character string is greater than the preset character length. If the length of the character string is greater than the preset character length, execute step S503; otherwise, execute step S505.
[0101] Among them, the preset character length can be determined according to the data meaning actually represented by the target message field and the normal number of characters in the character string; such as the target message field "nick" in Example 1 above, its actual data meaning represented is a nickname, and the normal number of characters in a nickname string is between 2 and 20 characters, so the exemplary preset character length can be 4.
[0102] In this step, the length of the character string corresponding to the target message field is compared with the preset character length, and then subsequent steps are performed according to the comparison result.
[0103] S503: Using special symbols to replace each character in the character string that exceeds a preset character length to obtain a processed character string.
[0104] In this step, if it is determined that the length of the string is greater than the preset character length, special symbols can be used to replace each character in the string that exceeds the preset character length to obtain a processed string, thereby achieving a partially masked desensitization method.
[0105] For example, assuming that the field value corresponding to the target message field "nick" is the string "abcd1234", the length of which is 8 characters. Since it is greater than the preset character length (assuming it is 4), the characters "1", "2", "3", and "4" that exceed the preset character length can be masked with the special symbol "*", and the processed string is "abcd****". It should be noted that, depending on the order of traversal, the characters that exceed the preset character length can also be "a", "b", "c", and "d", so the string obtained after masking with the special symbol "*" can also be "****1234".
[0106] S505: Use special symbols to replace the first preset number of characters in the character string to obtain a processed character string.
[0107] In this step, if it is determined that the length of the string is less than or equal to the preset character length, since the string itself is short, a special symbol can be used to replace the first preset number of characters in the string to obtain a processed string, thereby realizing a partially masked desensitization method. The first preset number of characters can be any value less than the preset character length; for example, the first preset number of characters can be 1, that is, the first character in the string can be masked with a special symbol.
[0108] For example, assuming that the field value corresponding to the target message field "nick" is the string "abcd", and the length of the string is 4 characters, which is equal to the preset character length (4), the special symbol "*" can be used to mask the first character, and the processed string is "*bcd". It should be noted that, depending on the order of traversal, the string obtained after masking can also be "abc*".
[0109] In the above embodiment, a possible desensitization method is provided for the target message field whose data type is string type, that is, data protection is achieved by desensitizing the data by partially masking the string data. The partial masking desensitization method can not only avoid data security issues caused by full exposure, but also provide some valid information for user confirmation.
[0110] In a further possible embodiment, before the above S207, the data protection method of the embodiment of the present application may also include the following steps: Figure 6 The following steps are shown:
[0111] S601: Perform a character encoding format check on the character string to obtain a check result; the check result indicates that the character string conforms to the variable-length character encoding format or indicates that the character string does not conform to the variable-length character encoding format.
[0112] Among them, the variable-length character encoding format refers to UTF8 variable-length encoding. Since each character in the string is stored in the form of binary bytes, some characters are stored in 1 byte (such as 8 zeros such as 00000000 represent one byte), some characters are stored in 2 bytes, some are stored in 3 bytes, and some are stored in 4 bytes. UTF8 variable-length encoding is as follows:
[0113] One byte: 0*******
[0114] Two bytes: 110*****, 10******
[0115] Three bytes: 1110****, 10******, 10******
[0116] Four bytes: 11110***, 10******, 10******, 10******
[0117] If it starts with 0, then the character is a 1-byte code, and you can get its one-byte data and look it up in the one-byte table; if it starts with 110, then the character is a 2-byte code, and you can get its two-byte data and look it up in the two-byte table; and so on.
[0118] In order to adapt to the storage methods of different characters, the string uniformly adopts UTF8 variable-length encoding. However, UTF8 variable-length encoding is not conducive to the desensitization of the field. Therefore, it is necessary to convert it to a fixed-length character encoding format, namely UTF32 fixed-length encoding, and then perform desensitization. After the desensitization is completed, it is converted to UTF8 variable-length encoding to obtain the final desensitized string.
[0119] In this step, in order to ensure the smooth execution of the subsequent conversion, the character encoding format of the string is first checked for legality, that is, mainly to determine whether the string conforms to the UTF8 variable-length encoding method.
[0120] Specifically, during the verification process, the character encoding format corresponding to the string can be compared with the four variable-length encoding formats based on one to four bytes mentioned above. If the formats are consistent, it can be determined that the string conforms to the UTF8 variable-length encoding.
[0121] S603: When the verification result indicates that the character string conforms to the variable-length character encoding format, the character string is converted based on the fixed-length character encoding format to obtain a character string conforming to the fixed-length character format.
[0122] In this step, when the verification result indicates that the character string conforms to the UTF8 variable-length encoding, the character string is converted into the UTF32 fixed-length encoding format, and then the above steps S501 to S505 are executed to desensitize the character string.
[0123] In a further embodiment, if the string is converted to UTF32 fixed-length encoding, then after S207, the following steps need to be performed: the processed string is converted based on a variable-length character encoding format to obtain a string that conforms to a variable-length character format. That is, after the desensitization of the string is completed, it is finally necessary to convert it to UTF8 variable-length encoding.
[0124] In the above embodiment, if Figure 7 As shown, for variable-length UTF8-encoded strings, they are first converted into fixed-length UTF32 codes to facilitate the implementation of field desensitization function-related programming languages; at the same time, the character encoding format of the string is checked before the conversion to ensure that the string is stored based on the standard UTF8 encoding method, which can ensure the order of format conversion execution, thereby improving the success rate of desensitizing the string and achieving data protection.
[0125] In other embodiments, if the desensitizing field carried by the target message field is identified, such as the "clear" field in the above example, indicating the implementation of a complete masking desensitization method, the existing ClearField() method can be directly called to clear all characters in the string; or, special symbols can be used to replace all characters in the string.
[0126] It should be noted that the specific desensitization method mainly implemented for string data in the above embodiment can also be applied to other data types; for example, when the data type of the target message field is a float data type, the ClearField() method can also be directly called to clear all numbers.
[0127] In actual applications, when implementing the field desensitization function DesensitizeField(message,field), you can use the existing desensitization function to desensitize the target message field of a specific data type. For example, encapsulate the desensitization method of the string above, and then provide the DesensitizeStr() function interface to the outside world, so that the interface can be directly called in the field desensitization function of different logics to desensitize the string.
[0128] In addition, in actual applications, by adding the key code snippet of Example 3 below to the business logic code file of the program, the above S201 to S207 can be automatically implemented when the program is running.
[0129] Example 3:
[0130] void DesensitizeMessage(Message*message){
[0131] const Reflection*refl=message->GetReflection();
[0132] const Descriptor*desc=message->GetDescriptor();
[0133] std::vector<const FieldDescriptor*> fields;
[0134] refl->ListFields(*message,&fields);
[0135] for(auto field:fields){
[0136] DesensitizeField(message,field);
[0137] }
[0138] }
[0139] Among them, DesensitizeMessage() can desensitize each message object and return it; by obtaining each message field in each message object, the field desensitization function DesensitizeField() is called one by one to achieve field desensitization. The field desensitization function DesensitizeField() does not process ordinary message fields. In addition, if the message object belongs to a nested message type, DesensitizeMessage() is recursively called in DesensitizeField().
[0140] In summary, a data protection method provided in an embodiment of the present application utilizes the reflection capability of protobuf. When the program is running, the description information of each message field in the message object is obtained through the reflection interface, the target message field that needs to be desensitized in the message object is identified and desensitized, and finally the processed message object is output, thereby achieving data protection; on the one hand, the cross-language feature of protobuf enables the data protection method of the embodiment of the present application to support multiple programming languages and is suitable for different language platforms; on the other hand, the Proto description file is independent of the business logic code file of the program, and is simple to modify, which can significantly reduce development costs and is conducive to the continuous upgrading of the business.
[0141] The present application also provides a data protection device, such as Figure 8 As shown, the data protection device 80 includes:
[0142] The first acquisition module 801 is used to obtain the description information of each message field and the field value of each message field in the message object through the reflection interface during the program running process; the description information of each message field is defined in the Proto description file of the program;
[0143] The second acquisition module 802 is used to obtain the extended field in the Proto description file; the extended field is used to mark the message field to be protected; the extended field is a custom message type, and the custom message type includes at least one desensitized field; the desensitized field represents the desensitization method implemented on the message field to be protected;
[0144] A determination module 803, configured to determine a message field in a message object that contains an extended field for description information as a target message field;
[0145] The desensitizing module 804 is used to perform desensitization processing on the field value of the target message field in the message object based on the desensitizing field to obtain a processed message object.
[0146] In some possible embodiments, the device also includes an extension module for obtaining an original Proto description file of the program; the original Proto description file includes original description information of each message field; creating a Proto extension file; the Proto extension file includes definition information of a custom message type and definition information of an extension field; introducing the Proto extension file into the original Proto description file; adding the extension field to the original description information of the message field to be protected to obtain an extended Proto description file; and compiling and publishing the extended Proto description file.
[0147] In some possible embodiments, at least one desensitizing field includes a first desensitizing field and a second desensitizing field; the first desensitizing field represents a desensitizing method of masking all data, and the second desensitizing field represents a desensitizing method of masking part of the data;
[0148] The extension module is also used to construct a custom message type through message keywords, define a first desensitized field and a second desensitized field in the custom message type; construct an extension field through extension keywords, and define the data type of the extension field as a custom message type.
[0149] In some possible embodiments, the field value of the target message field is a string; the desensitization field represents a desensitization method of partially masking the string;
[0150] The desensitization module 804 is further used to replace each character in the string that exceeds the preset character length with a special symbol when the length of the string is greater than the preset character length, to obtain a processed string;
[0151] Or; when the length of the string is less than or equal to the preset character length, a special symbol is used to replace the first preset number of characters in the string to obtain a processed string.
[0152] In some possible embodiments, the desensitizing module 804 is also used to perform character encoding format verification on the string to obtain a verification result; the verification result indicates that the string conforms to a variable-length character encoding format or indicates that the string does not conform to a variable-length character encoding format; when the verification result indicates that the string conforms to a variable-length character encoding format, the string is converted based on a fixed-length character encoding format to obtain a string that conforms to a fixed-length character format.
[0153] In some possible embodiments, the desensitization module 804 is further used to convert the processed character string based on a variable-length character encoding format to obtain a character string that conforms to the variable-length character format.
[0154] It should be noted that the device and method embodiments in the device embodiment are based on the same inventive concept.
[0155] An embodiment of the present application provides an electronic device, which includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or the at least one program is loaded and executed by the processor to implement the data protection method provided in the above method embodiment.
[0156] Further, Fig. 9 A hardware structure diagram of an electronic device for implementing the data protection method provided in the embodiment of the present application is shown. The electronic device may participate in forming or include the data protection device provided in the embodiment of the present application. Fig. 9 As shown, the electronic device 100 may include one or more (1002a, 1002b, ..., 1002n are used to illustrate) processors 1002 (the processor 1002 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 1004 for storing data, and a transmission device 1006 for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the I / O interface), a network interface, a power supply and / or a camera. It can be understood by those skilled in the art that Fig. 9 The structure shown is only for illustration and does not limit the structure of the above electronic device. Fig. 9 More or fewer components as shown, or with Fig. 9 Different configurations shown.
[0157] It should be noted that the one or more processors 1002 and / or other data processing circuits described above may generally be referred to herein as "data processing circuits". The data processing circuits may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. In addition, the data processing circuit may be a single independent processing module, or may be incorporated in whole or in part into any of the other components in the electronic device 100 (or mobile device). As described in the embodiments of the present application, the data processing circuit acts as a processor control (e.g., selection of a variable resistor terminal path connected to an interface).
[0158] The memory 1004 can be used to store software programs and modules of application software, such as program instructions / data storage devices corresponding to the data protection method described in the embodiments of the present application. The processor 1002 executes various functional applications and data processing by running the software programs and modules stored in the memory 1004, that is, to implement the above-mentioned data protection method. The memory 1004 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 1004 may further include a memory remotely arranged relative to the processor 1002, and these remote memories may be connected to the electronic device 100 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0159] The transmission device 1006 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the electronic device 100. In one example, the transmission device 1006 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one embodiment, the transmission device 1006 can be a radio frequency (Radio Frequency, RF) module, which is used to communicate with the Internet wirelessly.
[0160] The display may be, for example, a touch screen liquid crystal display (LCD) that enables a user to interact with a user interface of the electronic device 100 (or mobile device).
[0161] An embodiment of the present application also provides a computer-readable storage medium, which can be set in an electronic device to store at least one instruction or at least one program related to a data protection method in a method embodiment. The at least one instruction or the at least one program is loaded and executed by the processor to implement the data protection method provided by the above method embodiment.
[0162] Optionally, in this embodiment, the storage medium may be located in at least one of the multiple network servers of the computer network. Optionally, in this embodiment, the storage medium may include, but is not limited to, various media that can store program codes, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk, or an optical disk.
[0163] An embodiment of the present application further provides a computer program, which, when executed by a processor, implements the data protection method provided by the above method embodiment.
[0164] It should be noted that the above-mentioned sequence of the embodiments of the present application is for description only and does not represent the advantages and disadvantages of the embodiments. The above-mentioned specific embodiments of the present application are described. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0165] Each embodiment in this application is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device and electronic device embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0166] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.
[0167] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the protection scope of the present application.
Claims
1. A data protection method, characterized in that: include: During the program running process, the description information of each message field in the message object and the field value of each message field are obtained through the reflection interface; the description information of each message field is defined in the Proto description file of the program; Obtain an extended field in the Proto description file; the extended field is used to mark the message field to be protected; the extended field is a custom message type, and the custom message type includes at least one desensitizing field; the desensitizing field represents the desensitizing method implemented on the message field to be protected; Determine a message field in the message object that contains the extended field as a target message field; The field value of the target message field in the message object is desensitized based on the desensitized field to obtain a processed message object.
2. The data protection method according to claim 1, characterized in that: The method further comprises: Obtaining an original Proto description file of the program; the original Proto description file includes original description information of each message field; Creating a Proto extension file; the Proto extension file includes definition information of the custom message type and definition information of the extension field; Introduce the Proto extension file into the original Proto description file; Add the extended field to the original description information of the message field to be protected to obtain an extended Proto description file; The extended Proto description file is compiled and published.
3. The data protection method according to claim 2, characterized in that: The at least one desensitized field includes a first desensitized field and a second desensitized field; The first desensitization field represents a desensitization method of completely masking the data, and the second desensitization field represents a desensitization method of partially masking the data; The creation of the Proto extension file includes: Construct the custom message type by using message keywords, and define the first desensitized field and the second desensitized field in the custom message type; The extended field is constructed by using an extended keyword, and the data type of the extended field is defined as the custom message type.
4. The data protection method according to claim 1, characterized in that: The field value of the target message field is a character string; the desensitization field represents a desensitization method of partially masking the character string; The desensitizing the field value of the target message field in the message object based on the desensitizing field to obtain the processed message object includes: When the length of the character string is greater than the preset character length, a special symbol is used to replace each character in the character string that exceeds the preset character length to obtain a processed character string; Or; when the length of the character string is less than or equal to the preset character length, the special symbol is used to replace the first preset number of characters in the character string to obtain a processed character string.
5. The data protection method according to claim 4, characterized in that: Before desensitizing the field value of the target message field in the message object based on the desensitized field to obtain the processed message object, the method further includes: Performing a character encoding format check on the character string to obtain a check result; the check result indicates that the character string conforms to a variable-length character encoding format or indicates that the character string does not conform to the variable-length character encoding format; When the verification result indicates that the character string conforms to the variable-length character encoding format, the character string is converted based on the fixed-length character encoding format to obtain a character string conforming to the fixed-length character format.
6. The data protection method according to claim 5, characterized in that: After performing desensitization processing on the field value of the target message field in the message object based on the desensitized field to obtain the processed message object, the method further includes: The processed character string is converted based on the variable-length character encoding format to obtain a character string that conforms to the variable-length character format.
7. A data protection device, characterized in that: include: A first acquisition module is used to acquire the description information of each message field in the message object and the field value of each message field through the reflection interface during the program running process; the description information of each message field is defined in the Proto description file of the program; The second acquisition module is used to obtain the extended field in the Proto description file; the extended field is used to mark the message field to be protected; the extended field is a custom message type, and the custom message type includes at least one desensitizing field; the desensitizing field represents the desensitization method implemented on the message field to be protected; A determination module, configured to determine a message field in the message object that contains the extended field as a target message field; The desensitizing module is used to perform desensitization processing on the field value of the target message field in the message object based on the desensitizing field to obtain a processed message object.
8. An electronic device, characterized in that: It comprises a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or the at least one program is loaded and executed by the processor to implement the data protection method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores at least one instruction or at least one program, and the at least one instruction or the at least one program is loaded and executed by a processor to implement the data protection method according to any one of claims 1 to 6.
10. A computer program, characterized in that When the computer program is executed by a processor, the data protection method according to any one of claims 1 to 6 is implemented.
