Log desensitization method and device, computer device and readable storage medium
By determining the start and end positions of parameter formatting during the log de-identification process and searching and replacing de-identification attributes within that range, the problem of high performance loss in existing technologies is solved, and efficient log de-identification processing is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HANGZHOU PINGPONG INTELLIGENT TECH CO LTD
- Filing Date
- 2026-05-07
- Publication Date
- 2026-06-05
AI Technical Summary
Existing technologies suffer significant performance losses during log de-identification, especially since they search from the beginning of the entire string to be printed each time a de-identified attribute is found, resulting in low efficiency.
By obtaining the list of desensitized attributes of the object to be printed and their relationships, the start and end positions of the formatting for each parameter are determined, and desensitized attributes are searched and replaced within this range, reducing global searches. A StringBuilder object is used to store the desensitized string, avoiding frequent expansion and copying.
It effectively reduces performance loss during log desensitization, prevents accidental and repeated desensitization, and improves processing efficiency.
Smart Images

Figure CN122153969A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to a log desensitization method, apparatus, computer equipment, and readable storage medium. Background Technology
[0002] Data anonymization refers to the transformation of sensitive information using anonymization rules to reliably protect sensitive and private data. For example, in cases involving customer security data and other sensitive information, it is necessary to modify real data for testing purposes, requiring anonymization. Similarly, cross-border financial transactions may involve sensitive information such as user details. If this information is printed in logs, it can easily lead to privacy leaks and security risks as the logs circulate. Therefore, data anonymization is necessary.
[0003] To meet financial and / or security compliance requirements, sensitive data needs to be anonymized when printing logs. Current technologies involve tagging attributes (annotations, configuring anonymized attribute names), obtaining the plaintext and the anonymized string before printing the log, identifying the plaintext from the string to be printed, and replacing it with the anonymized string. This method incurs significant performance overhead. Therefore, a data anonymization method that reduces performance loss is needed. Summary of the Invention
[0004] Therefore, it is necessary to provide a log desensitization method, apparatus, computer equipment, computer-readable storage medium, and computer program product that can reduce performance loss in order to address the above-mentioned technical problems.
[0005] Firstly, this application provides a log desensitization method, including:
[0006] Obtain the list of desensitized attributes of the object to be printed, as well as the relationship between the desensitized attribute name, the plaintext of the desensitized attribute, and the desensitized value of each desensitized attribute in the list;
[0007] The object to be printed is formatted to obtain plaintext string to be printed, and the first start and end positions of each parameter in the object to be printed are determined in the plaintext string to be printed after formatting.
[0008] Iterate through each desensitized attribute in the desensitized attribute list, and for the currently traversed desensitized attribute, determine the second start and end positions of the parameter containing the currently traversed desensitized attribute from the plaintext string to be printed;
[0009] Based on the second start and end positions and the association relationship, if the plaintext of the string to be printed contains a desensitized attribute name and desensitized attribute plaintext that match the currently traversed desensitized attribute, and the position of the currently traversed desensitized attribute satisfies the preset position condition, then the plaintext of the currently traversed desensitized attribute is desensitized until the traversal is completed, and the desensitized string to be printed is obtained.
[0010] In one embodiment, before iterating through the desensitized attributes in the desensitized attribute list, the method further includes:
[0011] Determine the length characteristics of the plaintext string to be printed, and construct a StringBuilder object based on the length characteristics; wherein, the StringBuilder object is used to store the anonymized string to be printed.
[0012] In one embodiment, determining the length characteristic of the plaintext string to be printed and constructing a StringBuilder object based on the length characteristic includes:
[0013] Determine the length of the plaintext string to be printed, as well as the plaintext length and the length after desensitization of each desensitized field in the plaintext string to be printed; each desensitized field includes the plaintext of the desensitized attribute;
[0014] For each of the de-identified fields, a corresponding length difference is determined based on the plaintext length and the de-identified length.
[0015] The total length is determined based on the length differences and the lengths themselves, and a StringBuilder object is constructed using the total length as the capacity.
[0016] In one embodiment, obtaining the list of desensitized attributes of the object to be printed and the association between the desensitized attribute name, the plaintext of the desensitized attribute, and the desensitized value of each desensitized attribute in the list includes:
[0017] Determine the type of the object to be printed, and obtain the list of desensitized attributes of the object to be printed based on the mapping relationship between the cached type and the desensitized attributes.
[0018] For each desensitized attribute in the desensitized attribute list, obtain the corresponding desensitized attribute name, desensitized attribute plaintext, and desensitized value;
[0019] List<String[]> The data format stores the desensitized attributes, the corresponding desensitized attribute names, the plaintext of the desensitized attributes, and the desensitized values to obtain the corresponding association relationships.
[0020] In one embodiment, determining the first start and end positions of each parameter in the plaintext string to be printed after formatting includes:
[0021] For each parameter in the formatted object to be printed, the length of the formatted content before each parameter is determined as the first start position of the parameter, and the first end position is determined based on the first start position and the length of the formatted content of the parameter.
[0022] Based on the first start position and the first end position, determine the first start and end positions of each parameter in the object to be printed after formatting in the plaintext string to be printed.
[0023] In one embodiment, the step of traversing the desensitized attributes in the desensitized attribute list, and determining the second start and end positions of the parameter containing the currently traversed desensitized attribute from the plaintext string to be printed, includes:
[0024] Obtain the end position and current processing position of the plaintext string to be printed; the current processing position is used to indicate the current position of the plaintext string to be printed in the current processing.
[0025] If the current processing position is less than the end position, then the desensitized attributes in the desensitized attribute list are traversed, and for the currently traversed desensitized attribute, the second start and end positions of the parameter of the currently traversed desensitized attribute are determined from the plaintext string to be printed.
[0026] In one embodiment, the method further includes:
[0027] The position of the currently traversed desensitized attribute is determined based on the second start and end positions. If the position is smaller than the current processing position, a preset position is obtained.
[0028] If the string length between the preset position and the end position is greater than or equal to the sum of the lengths of the desensitized attribute name, separator, and desensitized attribute plaintext corresponding to the currently traversed desensitized attribute, then based on the second start and end positions and the association relationship, it is determined whether there is a desensitized attribute name and desensitized attribute plaintext matching the currently traversed desensitized attribute in the plaintext string to be printed.
[0029] In one embodiment, determining whether the plaintext string to be printed contains a desensitized attribute name and plaintext that match the currently traversed desensitized attribute, based on the second start and end positions and the association relationship, includes:
[0030] Based on the second start and end positions, determine the target string at the corresponding position from the plaintext string to be printed;
[0031] If the target string contains a desensitized attribute name that matches the currently traversed desensitized attribute, then obtain the adjacent string concatenated after the separator of the matching desensitized attribute name;
[0032] If the adjacent string, the matched desensitized attribute name, and the currently traversed desensitized attribute satisfy the association relationship and the end of the adjacent string is a separator, then the adjacent string is determined as the plaintext of the desensitized attribute of the traversed desensitized attribute.
[0033] In one embodiment, the position of the currently traversed desensitized attribute satisfies a preset position condition, including:
[0034] If the starting position of the plaintext of the currently traversed desensitized attribute is less than the minimum position of the plaintext of the string to be printed, then the position of the currently traversed desensitized attribute satisfies the preset position condition; the minimum position is used to represent the position of the current first desensitized attribute.
[0035] In one embodiment, the process of plaintext desensitizing the currently traversed desensitized attributes until the traversal is complete, resulting in the desensitized string to be printed, includes:
[0036] The desensitized attributes of the currently traversed desensitized attributes are desensitized from plaintext to obtain the desensitized values;
[0037] Obtain the substring between the current processing position and the starting position of the current traversal of the desensitized attribute plaintext value from the plaintext string to be printed, and append the substring and the desensitized value to the StringBuilder object in sequence;
[0038] The current minimum position is updated based on the starting position of the currently traversed desensitized attributes, and the current processing position is updated by adding the starting position of the plaintext value of the currently traversed desensitized attributes to the length of the plaintext of the desensitized attributes.
[0039] The process involves iterating through the desensitized attributes in the desensitized attribute list, determining the second start and end positions of the parameter containing the currently traversed desensitized attribute from the plaintext string to be printed, and continuing until the traversal is complete, thus obtaining the desensitized string to be printed.
[0040] In one embodiment, the method further includes:
[0041] If the currently traversed desensitization attribute does not exist, then obtain the character substring between the current processing position and the end position of the plaintext to be printed from the plaintext to be printed.
[0042] The character substring is appended to the StringBuilder object.
[0043] Secondly, this application also provides a log desensitization device, comprising:
[0044] The data acquisition module is used to acquire a list of desensitized attributes of the object to be printed, as well as the relationship between the desensitized attribute name, the plaintext of the desensitized attribute, and the desensitized value of each desensitized attribute in the list;
[0045] The formatting module is used to format the object to be printed to obtain the plaintext string to be printed, and to determine the first start and end positions of each parameter in the object to be printed after formatting in the plaintext string to be printed.
[0046] The traversal module is used to traverse the desensitized attributes in the desensitized attribute list, and for the currently traversed desensitized attribute, determine the second start and end positions of the parameter where the currently traversed desensitized attribute is located from the plaintext string to be printed;
[0047] The desensitization module is used to desensitize the plaintext of the desensitized attribute based on the second start and end positions and the association relationship, if the plaintext of the string to be printed contains a desensitized attribute name and desensitized attribute plaintext that match the currently traversed desensitized attribute, and the position of the currently traversed desensitized attribute meets a preset position condition, then desensitize the plaintext of the currently traversed desensitized attribute until the traversal is completed, and obtain the desensitized string to be printed.
[0048] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:
[0049] Obtain the list of desensitized attributes of the object to be printed, as well as the relationship between the desensitized attribute name, the plaintext of the desensitized attribute, and the desensitized value of each desensitized attribute in the list;
[0050] The object to be printed is formatted to obtain plaintext string to be printed, and the first start and end positions of each parameter in the object to be printed are determined in the plaintext string to be printed after formatting.
[0051] Iterate through each desensitized attribute in the desensitized attribute list, and for the currently traversed desensitized attribute, determine the second start and end positions of the parameter containing the currently traversed desensitized attribute from the plaintext string to be printed;
[0052] Based on the second start and end positions and the association relationship, if the plaintext of the string to be printed contains a desensitized attribute name and desensitized attribute plaintext that match the currently traversed desensitized attribute, and the position of the currently traversed desensitized attribute satisfies the preset position condition, then the plaintext of the currently traversed desensitized attribute is desensitized until the traversal is completed, and the desensitized string to be printed is obtained.
[0053] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the following steps:
[0054] Obtain the list of desensitized attributes of the object to be printed, as well as the relationship between the desensitized attribute name, the plaintext of the desensitized attribute, and the desensitized value of each desensitized attribute in the list;
[0055] The object to be printed is formatted to obtain plaintext string to be printed, and the first start and end positions of each parameter in the object to be printed are determined in the plaintext string to be printed after formatting.
[0056] Iterate through each desensitized attribute in the desensitized attribute list, and for the currently traversed desensitized attribute, determine the second start and end positions of the parameter containing the currently traversed desensitized attribute from the plaintext string to be printed;
[0057] Based on the second start and end positions and the association relationship, if the plaintext of the string to be printed contains a desensitized attribute name and desensitized attribute plaintext that match the currently traversed desensitized attribute, and the position of the currently traversed desensitized attribute satisfies the preset position condition, then the plaintext of the currently traversed desensitized attribute is desensitized until the traversal is completed, and the desensitized string to be printed is obtained.
[0058] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, performs the following steps:
[0059] Obtain the list of desensitized attributes of the object to be printed, as well as the relationship between the desensitized attribute name, the plaintext of the desensitized attribute, and the desensitized value of each desensitized attribute in the list;
[0060] The object to be printed is formatted to obtain plaintext string to be printed, and the first start and end positions of each parameter in the object to be printed are determined in the plaintext string to be printed after formatting.
[0061] Iterate through each desensitized attribute in the desensitized attribute list, and for the currently traversed desensitized attribute, determine the second start and end positions of the parameter containing the currently traversed desensitized attribute from the plaintext string to be printed;
[0062] Based on the second start and end positions and the association relationship, if the plaintext of the string to be printed contains a desensitized attribute name and desensitized attribute plaintext that match the currently traversed desensitized attribute, and the position of the currently traversed desensitized attribute satisfies the preset position condition, then the plaintext of the currently traversed desensitized attribute is desensitized until the traversal is completed, and the desensitized string to be printed is obtained.
[0063] The aforementioned log desensitization method, apparatus, computer equipment, computer-readable storage medium, and computer program product, before printing logs, in addition to obtaining the plaintext value of the desensitized attribute of the object to be printed and its desensitized value, also obtain the corresponding desensitized attribute name, thus establishing the association between the three. This processing method can prevent the replacement of other attributes with the same value during desensitization processing, avoiding accidental desensitization and multiple desensitizations. Based on this, by determining the first start and end positions of each parameter in the plaintext string to be printed after formatting, the desensitized attributes in the desensitized attribute list are traversed, and for the currently traversed desensitized attribute... The process begins by determining the second start and end positions of the parameters containing the currently traversed de-identified attribute from the plaintext string to be printed. Based on these second start and end positions and the associated relationships, if the plaintext string to be printed contains a de-identified attribute name and plaintext that match the currently traversed de-identified attribute, and the position of the currently traversed de-identified attribute satisfies the preset position conditions, then the plaintext of the currently traversed de-identified attribute is de-identified. This process continues until all traversals are completed, resulting in the de-identified string to be printed. This method eliminates the need to search from the beginning of the entire string to be printed each time when searching for all de-identified attributes; it only requires searching within the corresponding parameter start and end position range, thus reducing performance overhead. Attached Figure Description
[0064] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0065] Figure 1 This is a flowchart illustrating a log desensitization method in one embodiment;
[0066] Figure 2 This is a flowchart illustrating the method for constructing a StringBuilder object in one embodiment;
[0067] Figure 3 This is a flowchart illustrating step 102 in one embodiment;
[0068] Figure 4 This is a flowchart illustrating a method for finding de-identified attributes in one embodiment;
[0069] Figure 5 This is a flowchart illustrating a method for replacing desensitized attribute values in one embodiment;
[0070] Figure 6 This is a flowchart illustrating the log desensitization method in another embodiment;
[0071] Figure 7 This is a structural block diagram of a log desensitization device in one embodiment;
[0072] Figure 8 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0073] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0074] In specific business scenarios, cross-border financial transactions often involve user information. If this information is logged, it can easily lead to privacy data leaks and security risks as the logs circulate. Current de-identification methods search for all de-identified attributes from the beginning of the entire string to be printed, rather than from the substring corresponding to the parameter values. This results in significant performance overhead. For example: `log.info("user:{},credit:{}",user0bj,credit0bj);` After formatting, the resulting string to be printed is:
[0075] user:{"phone": "12345678900"}, credit: {"expireMonth": "12"};
[0076] For the de-identified attribute "phone", the search starts from the beginning position "user" and continues to the end of the string to be printed; for the de-identified attribute "expireMonth", the search also starts from the beginning position "user" and continues to the end of the string to be printed, resulting in significant performance overhead.
[0077] To address the issue of high performance overhead during the desensitization process, a log desensitization method that can reduce performance loss is proposed.
[0078] In one embodiment, such as Figure 1As shown, a log anonymization method is provided. This embodiment illustrates the method's application to a terminal, but it is understood that the method can also be applied to a server, or to a system including both a terminal and a server, and implemented through interaction between the terminal and the server. In this embodiment, the method includes the following steps:
[0079] Step 102: Obtain the list of desensitized attributes of the object to be printed, as well as the relationship between the desensitized attribute name, the plaintext of the desensitized attribute, and the desensitized value of each desensitized attribute in the list.
[0080] The de-identified value can be the result of applying de-identification rules to the plaintext of the de-identified attribute, such as a partial mask or hashing result. It is used to replace the plaintext content in the logs to prevent the leakage of sensitive information. The association can describe the mapping logic between the de-identified attribute name, the plaintext of the de-identified attribute, and the de-identified value, forming a queryable data structure. This supports quickly finding the correspondence between the plaintext of a specific attribute and its de-identification result, avoiding redundant calculations.
[0081] For example, the application loads the de-identification configuration upon startup and caches it. This configuration declares the attribute names to be de-identified, their corresponding sensitive types, and may also include configurations for restrictions such as logger, package, and class blacklist. The application intercepts log printing to determine the object to be de-identified. It obtains the type of the object to be printed, and based on that type, retrieves the de-identified attributes of the object from the cache, resulting in a list of de-identified attributes for the object to be printed. For example, `log.info("user:{},credit:{}", userObj, creditObj)`. It retrieves the de-identified attribute "phone" for User (the type of userObj object) from the cache, and the de-identified attribute "expireMonth" for Credit (the type of creditObj object). Based on the de-identified attributes in the object to be printed, it uses reflection to obtain the values of the de-identified attributes, and constructs the de-identified values according to the de-identification rules. For example, for the de-identified attribute "phone", the value is 12345678900, and the de-identified value is... The desensitized attribute `expireMonth`, with a value of 12, represents the desensitized value as follows: This allows us to determine the relationships between the desensitized attribute name, the plaintext of the desensitized attribute, and the desensitized value for each desensitized attribute in the desensitized attribute list.
[0082] It is understandable that the relationship between the desensitized attribute name, the plaintext of the desensitized attribute, and the desensitized value of each desensitized attribute can be, but is not limited to, stored in the form of an array.
[0083] Step 104: Format the object to be printed to obtain the plaintext string to be printed, and determine the first start and end positions of each parameter in the object to be printed after formatting in the plaintext string to be printed.
[0084] The formatting of the object to be printed can be achieved using existing methods, which will not be elaborated here. The first start and end positions of the formatted parameters can be the character range occupied by each parameter (field) after formatting in the plaintext string to be printed, represented by start and end indices. This provides parameter-level position indices to narrow down the subsequent de-identification matching range and improve positioning efficiency. It should be noted that each parameter is an object, such as log.info("user:{}, credit:{}", userObj, creditObj); here, userObj and creditObj are parameters of log.info, and they are themselves objects, while phone in userObj is an attribute (also called a field).
[0085] For example, after formatting the object to be printed, log.info("user:{},credit:{}"userObj,credit0bj), construct the plaintext string to be printed and record the start and end positions of each parameter: user:{“phone”:“12345678900”},credit:{“expireMonth”:“12”},where, the first start and end positions of the first parameter user are determined to be: [6,29],and the first start and end positions of the second parameter credit are: [40,60].
[0086] Step 106: Traverse the desensitized attributes in the desensitized attribute list. For the currently traversed desensitized attribute, determine the second start and end positions of the parameter containing the currently traversed desensitized attribute from the plaintext string to be printed.
[0087] It should be noted that there must be at least one object to be printed, meaning the result can be a list of objects to be printed. Therefore, the de-identification process is the same for each object in this list. If an object to be printed contains at least two parameters, each with multiple de-identified attributes, then during iteration, the process proceeds sequentially according to the de-identified attribute list corresponding to each parameter. For example, it first checks the parameter's position (in order), then determines its position within the plaintext string based on its de-identified attribute list, and finally replaces the one that appears first.
[0088] For ease of explanation, this example uses a single object to be printed. Each object has its own list of de-identified attributes. The second start and end positions are determined from the first start and end positions of each parameter in the plaintext string to be printed after formatting. "First" and "second" are used only to distinguish the start and end positions of different objects; they are purely for differentiation.
[0089] Each desensitized attribute in the desensitized attribute list has its own corresponding index. When the desensitized attribute list of the object to be printed is traversed for the first time, each desensitized attribute in the list is traversed, starting from the first desensitized attribute. For the currently traversed desensitized attribute, the second start and end positions of the parameter containing the currently traversed desensitized attribute are determined from the plaintext string to be printed. Furthermore, if the position of the currently traversed desensitized attribute can be determined based on the second start and end positions, then... It should be noted that during the traversal, if the plaintext string to be printed does not contain the currently traversed desensitized attribute, the next desensitized attribute will be determined from the desensitized attribute list.
[0090] Step 108: Based on the second start and end positions and the association relationship, if the plaintext of the string to be printed contains a desensitized attribute name and desensitized attribute plaintext that match the currently traversed desensitized attribute, and the position of the currently traversed desensitized attribute meets the preset position conditions, then the plaintext of the currently traversed desensitized attribute is desensitized until the traversal is completed, and the desensitized string to be printed is obtained.
[0091] The preset position condition can be the smallest position of the desensitized attribute among the remaining un-desensitized plaintext strings in the plaintext to be printed, excluding those already desensitized, during the current desensitization attribute traversal. Confirming whether a desensitized attribute name and plaintext matching the currently traversed desensitized attribute exist in the plaintext to be printed can be based on a pre-determined association relationship. This involves searching within the range corresponding to the second start and end positions to see if a matching desensitized attribute name and plaintext exists within the association relationship. If a match is found, it means that a matching desensitized attribute name and plaintext exist in the plaintext to be printed, indicating the existence of a corresponding currently traversed desensitized attribute. Further, it is determined whether the position of the currently traversed desensitized attribute satisfies the preset position condition. In other words, it is necessary to confirm the desensitized attribute name and value first, then confirm the existence of a corresponding desensitized attribute, and finally determine if it is the first desensitized attribute.
[0092] For example, before iterating through the list of de-identified attributes of the object to be printed, initialization settings are required. These include initializing the length `len` of the plaintext string to be printed, the current processing position of the currently processed character in the plaintext string (`currentPos`: initialized to 0), the position of the first de-identified attribute (i.e., the starting position of the plaintext value of the de-identified attribute, i.e., the minimum position `minPos`, initialized to the maximum integer value `Integer.MAX_VALUE` to ensure the minimum position can be found), and the index of the de-identified attribute to be matched (`matchIndex`: initialized to -1, indicating no match). An integer array `int[] matchPosArr` is constructed: its length is the number of de-identified attributes, indicating the position of the de-identified field; all positions are initially set to -1. A boolean array `boolean[] exhaustArr` is constructed: its length is the number of de-identified attributes; a value of `true` indicates that the search has reached the end and the de-identified field cannot be found. The de-identified fields include the de-identified attribute name and the plaintext value corresponding to each de-identified attribute. The position of the first desensitized attribute can be understood as the starting position of its plaintext value. This is equivalent to sorting the attributes; among multiple desensitized attributes, one will always be the first. For example, if we first set minPos to the maximum integer value, the first desensitized attribute, the plaintext value of "phone," starts at position 28, so we set minPos to 28. The second desensitized attribute, the plaintext value of "email," starts at position 12. Since 12 is smaller than 28, we set minPos to 12, meaning "email" is desensitized first.
[0093] If the current processing position is less than the end position of the plaintext string to be printed, then the list of desensitized attributes of the object to be printed is traversed. For the currently traversed desensitized attribute, if a corresponding desensitized field exists, the second start and end positions of the parameter containing the currently traversed desensitized attribute are determined from the plaintext string to be printed, as well as the position of the currently traversed desensitized attribute. Based on the second start and end positions, further judgments are made on the currently traversed desensitized attribute. First, it is checked whether there is a corresponding desensitized attribute name in the association relationship, and then it is checked whether there is a corresponding desensitized attribute plaintext. If the currently traversed desensitized attribute matches in the plaintext string to be printed... The name and plaintext of the desensitized attribute indicate the existence of the current desensitized attribute and the starting index of the obtained plaintext. If the current position of the desensitized attribute is the minimum position, then the plaintext of the desensitized attribute of the current desensitized attribute is desensitized to obtain the corresponding desensitized value. The substring between the current processing position and the starting index of the plaintext of the desensitized attribute and the desensitized value are added to the constructed storage object in sequence. The current processing position and the minimum position are updated, and the next desensitized attribute that meets the preset position condition is determined. This process continues until the traversal is completed, and the desensitized string to be printed is obtained.
[0094] The above-described log desensitization method, before printing the log, not only obtains the plaintext of the desensitized attributes of the object to be printed and their desensitized values, but also obtains the corresponding desensitized attribute names, thus establishing the relationship between the three. This approach prevents the replacement of other attributes with the same value during desensitization, avoiding accidental or multiple desensitizations. Based on this, by determining the first and last positions of each parameter in the plaintext string to be printed after formatting, the desensitized attributes in the desensitized attribute list are traversed. For the currently traversed desensitized attribute, the current desensitized attribute is determined from the plaintext string to be printed. The algorithm iterates through the second start and end positions of the parameters containing the desensitized attributes. Based on these second start and end positions and the association relationships, if the plaintext of the string to be printed contains a desensitized attribute name and plaintext that match the currently iterated desensitized attribute, and the position of the currently iterated desensitized attribute meets the preset position conditions, then the plaintext of the currently iterated desensitized attribute is desensitized. This process continues until all desensitized attributes are found, resulting in the desensitized string to be printed. This method eliminates the need to search from the beginning of the entire string to be printed each time when searching for all desensitized attributes; it only requires searching within the corresponding parameter start and end position range, thus reducing performance overhead.
[0095] When iterating through the list of de-identified attributes, a new StringBuilder object is created each time to store the string replacing that attribute. Furthermore, the StringBuilder object doesn't specify an initial length (default 16), requiring expansion and copying when appending strings, resulting in significant performance and storage overhead. For example: {"expireMonth":"12","cvv":"379"}; For the de-identified attribute `expireMonth`, a new StringBuilder object is created to store the replaced string: {"expireMonth":" {"cvv":"379"}; For the de-identified attribute cvv, create a new StringBuilder object, based on the de-identified result of the previous attribute (i.e., the StringBuilder object above), and store the replaced string: {"expireMonth":" ","cvv":" "}
[0096] This approach leads to frequent creation and conversion, resulting in high memory and performance overhead, and the issue of multiple replacements. In other words, a parameterless StringBuilder is constructed, with the underlying character array having a default length of 16. When subsequent string appending occurs and storage becomes insufficient, a character array of twice the length is created, and the data from the original array is copied into the new array. Therefore, frequent resizing impacts both storage and performance. Furthermore, current de-identification frameworks are based on regular expression matching, which doesn't consider length. To address this issue, creating only one StringBuilder object to store the string replacing the de-identified attribute during the de-identification process can reduce time-consuming operations such as underlying storage resizing and character array copying. However, in most cases in existing technologies, a de-identified character will only appear once, meaning the StringBuilder doesn't need resizing and its length is just right. Therefore, creating only one StringBuilder object is not readily considered.
[0097] In an exemplary embodiment, before iterating through the desensitized attributes in the desensitized attribute list, the method further includes: determining the length characteristics of the plaintext string to be printed, and constructing a StringBuilder object based on the length characteristics; wherein the StringBuilder object is used to store the desensitized string to be printed.
[0098] The length feature can include the length of the plaintext string to be printed, the plaintext length of each de-identified field in the plaintext string to be printed, and the length after de-identification. The plaintext length can be the plaintext length of the de-identified attribute plaintext, and the length after de-identification can be the string length after de-identifying the de-identified attribute plaintext.
[0099] Furthermore, in an exemplary embodiment, a method for constructing a StringBuilder object is provided, such as... Figure 2 As shown, it includes the following steps:
[0100] Step 202: Determine the length of the plaintext string to be printed, as well as the plaintext length and the length after desensitization of each desensitized field in the plaintext string to be printed; each desensitized field includes the plaintext of the desensitized attribute.
[0101] Step 204: For each de-identified field, determine the corresponding length difference based on the plaintext length and the de-identified length.
[0102] Step 206: Determine the total length based on the length differences and the lengths, and construct a StringBuilder object with the total length as the capacity.
[0103] The length can be the total number of characters in the plaintext string to be printed before any de-identification processing, and can be used as the basic input value for calculating the total length of the de-identified string. The de-identified field can be the specific data item in the plaintext string to be printed that needs to be de-identified. De-identified fields can include one or more of the following: identity-related de-identified fields, financial de-identified fields, communication-related de-identified fields, etc. The plaintext length can be the number of characters in the unprocessed state of the de-identified field, and the de-identified length can be the number of characters in the string representing the de-identified value formed after the de-identification rules are applied. The length difference can be the numerical difference between the de-identified length and the plaintext length of a single de-identified field, and can be positive, negative, or zero.
[0104] For example, construct a StringBuilder object with the following capacity: the length of the string to be anonymized, plus the length difference between all anonymized strings and the plaintext string; the plaintext string to be printed, i.e., the length of the string to be anonymized is len; anonymized field 1, plaintext length p1, anonymized length d1; anonymized field 2, plaintext length p2, anonymized length d2; anonymized field n, plaintext length pn, anonymized length dn; then the length of the StringBuilder object is: len + (d1 - p1) + (d2 - p2) + ... + (dn - pn).
[0105] This approach determines the length of the plaintext string to be printed, as well as the plaintext length and the de-identified length of each de-identified field within the plaintext string. For each de-identified field, a corresponding length difference is determined based on the corresponding plaintext length and de-identified length. The total length is then determined based on each length difference and the total length, and a StringBuilder object is constructed with the total length as its capacity. This avoids frequent creation and conversion, which incurs high memory and performance overhead and the problem of multiple replacements. It also reduces time-consuming operations with poor performance, such as expanding the underlying storage and copying character arrays.
[0106] It's understandable that when iterating through the de-identified attributes and replacing the plaintext value with the de-identified string from the string to be printed, certain scenarios can lead to incorrect or multiple de-identification issues, affecting log retrieval. For example, incorrect de-identification might occur with the string {"clientId":"20251218","expireMonth":"12"}. If only the value 12 of the de-identified attribute `expireMonth` is used for searching and replacing, then the 12 in `clientId` will also be replaced with six asterisks, resulting in the incorrect de-identified string.
[0107] .
[0108] Multiple desensitization methods: For example, in the case of {"clientId":"202512163795","expireMonth":"12","cvv":"379"}, after searching and replacing based on the value 12 of the desensitization attribute expireMonth, the 12 in clientId will also be replaced with 6 asterisks.
[0109] Next, based on the value 379 of the desensitization attribute cvv, a search and replace operation is performed, and the 379 in clientId will also be replaced with 6 asterisks:
[0110] In this way, the value of clientId has undergone two rounds of desensitization.
[0111] To address the issues of excessive or incorrect data masking during the data masking process, in addition to obtaining the plaintext and the masked string, the masked attribute names are also obtained. During the data masking process, the same attribute names and values are found in the string to be printed, and then replaced with the masked string.
[0112] In one exemplary embodiment, such as Figure 3 As shown, step 102 includes steps 302 to 306. Wherein:
[0113] Step 302: Determine the type of the object to be printed, and obtain the list of desensitized attributes of the object to be printed based on the mapping relationship between the cached type and the desensitized attributes.
[0114] Step 304: For each desensitized attribute in the desensitized attribute list, obtain the corresponding desensitized attribute name, the plaintext of the desensitized attribute, and the desensitized value.
[0115] Step 306, using List<String[]> The data format stores the desensitized attributes, along with their corresponding desensitized attribute names, plaintext desensitized attributes, and desensitized values, thus obtaining the corresponding association relationships.
[0116] It should be noted that while Maps are convenient for storing the correspondence between plaintext and desensitized values, this implementation requires precise location (i.e., both attribute name and plaintext value must match) to prevent the replacement of non-desensitized attributes with identical values. Therefore, it is necessary to store the association between plaintext, desensitized value, and attribute name. However, further storing Maps would require constructing nested Maps or creating custom types, which is complex. Furthermore, Maps occupy more space than arrays, require hash calculations, and have lower performance than arrays. Therefore, an array is used to store the association between plaintext, desensitized value, and attribute name.
[0117] For example, by storing a List <List<String[]> >: String[0]: Plaintext of the desensitized attribute value, String[1]: Desensitized value, String[2]: Desensitized attribute name;
[0118] List <List<String[]> list = new ArrayList<>();
[0119] List <string>param1List = new ArrayList<>();
[0120] param1List.add(new String[]{"12345678900", " ", "phone"};
[0121] List <string>param2List = new ArrayList<>();
[0122] param2List.add(new String[]{"12", " ", "expireMonth"});
[0123] list.add(param1List);
[0124] The function `list.add(param2List)` adds two elements to the list: `param1List` for the first parameter `user` and `param2List` for the second parameter `credit`. `param1List` contains one de-identified attribute: `phone`, where the array stores the plaintext and the de-identified value, with the attribute name `phone`. `param2List` contains one de-identified attribute: `expireMonth`, where the array stores the plaintext and the de-identified value, with the attribute name `expireMonth`.
[0125] In the above embodiments, the association between plaintext, desensitized value, and attribute name is stored in an array, which improves performance and reduces memory usage compared to Map. By adding desensitized attribute name to the storage of plaintext and desensitized attribute value, the situation of multiple desensitization and accidental desensitization can be avoided.
[0126] Related technologies suffer from high overhead and poor performance due to the fact that each de-identification process starts searching from the beginning. To address this issue, in an exemplary embodiment, the first start and end positions of each parameter in the plaintext string to be printed are determined after formatting, including:
[0127] For each parameter in the formatted object to be printed, the length of the content preceding each parameter is determined as the first start position of the parameter, and the first end position is determined based on the first start position and the length of the formatted parameter. Based on the first start position and the first end position, the first start and end positions of each parameter in the plaintext string to be printed are determined. The first start position can also be understood as the starting position determined by the length of the formatted content preceding each parameter.
[0128] The length of the content preceding each parameter can be the total length of the string composed of all processed fields, delimiters, and structural symbols before the current parameter during the formatting process. For example, in `user:{"phone":"12345678900"}, credit:{"expireMonth":"12"}`, the first starting position of the first parameter `user` is the length of the content preceding it, i.e., `"user:"` is the first starting position, and the length of `"user:" + "{phone":"12345678900"}"` is the first ending position of the first parameter `user`. Similarly, the first starting position of the second parameter `credit` is the length of `"user:{"phone":"12345678900"}` and `credit:"`, and the corresponding second ending position is the length of `"user:{"phone":"12345678900"}` and `credit:" + "{"expireMonth":"12"}"`. In other words, the starting position does not include the formatted string of the corresponding parameter, while the ending position does.
[0129] In the above embodiments, by determining the start and end positions of each parameter after formatting the object to be printed, and further locating the position of the de-identified attribute in the plaintext string to be printed, the search is only conducted between the start and end positions of the parameter containing the de-identified attribute. This reduces the search range, lowers overhead, and improves performance. It should be noted that in related technologies, the native log4j2 does not support obtaining the start and end positions of each formatted parameter, requiring custom extensions.
[0130] In one embodiment, the desensitized attributes in the desensitized attribute list are traversed, and for the currently traversed desensitized attribute, the second start and end positions of the parameter containing the currently traversed desensitized attribute are determined from the plaintext string to be printed. This includes: obtaining the total length of the plaintext string to be printed, the current processing position, the minimum position, and the end position of the formatted desensitized attribute; the current processing position is used to indicate the current position of the plaintext string to be printed; the minimum position is used to indicate the position of the current first desensitized attribute; if the current processing position is less than the end position, the desensitized attributes in the desensitized attribute list are traversed, and for the currently traversed desensitized attribute, the second start and end positions of the parameter containing the currently traversed desensitized attribute are determined from the plaintext string to be printed.
[0131] The step of determining whether the current processing position is less than the end position after the desensitization attribute formatting can be achieved by comparing the numerical values of the current processing position and the end position to decide whether to continue the desensitization traversal.
[0132] The minimum position can be the earliest sensitive field to be located among all the desensitized attributes to be processed. During the initialization phase, the minimum position can be Integer.MAX_VALUE.
[0133] For example, for each iteration, it is necessary to determine the relationship between the current processing position and the corresponding formatted end position of the de-sensitized attribute. If the current processing position is less than the end position, it means that the de-sensitization is not yet complete and the de-sensitization iteration needs to continue. Therefore, the de-sensitized attributes in the de-sensitized attribute list are iterated, and for the currently iterated de-sensitized attribute, the second start and end positions of the parameter containing the currently iterated de-sensitized attribute are determined from the plaintext string to be printed. If the current processing position is greater than or equal to the end position, the iteration of each de-sensitized attribute is stopped.
[0134] It's important to note that the process of iterating through the desensitized attribute list involves determining the first desensitized attribute in each iteration, desensitizing that first attribute, and then updating the current position. For example, if the current processing position is 0, the starting positions of several desensitized attributes are compared. If a position is smaller than 0, it needs to be located to determine the first desensitized attribute, desensitize it, and update the current processing position (e.g., 25). Similarly, for the current processing position 25, the starting positions of several desensitized attributes are checked. If a position is smaller than 25, it needs to be located to determine the first desensitized attribute, desensitize it, and update the current processing position, and so on.
[0135] In the above embodiments, during the traversal of desensitized attributes, the relationship between the current processing position and the end position of the plaintext string to be printed is determined to decide whether to continue traversing the desensitized attributes in the desensitized attribute list. For the currently traversed desensitized attribute, the second start and end positions of the parameter containing the currently traversed desensitized attribute are determined from the plaintext string to be printed. This ensures that each traversal only focuses on the unprocessed string range, reducing the depth of nested loops and the number of repeated string comparisons, thus reducing the runtime computational burden. In particular, it effectively reduces performance loss and improves log output efficiency in scenarios with long texts or multiple sensitive fields.
[0136] In order to ensure the accuracy of desensitization, in an exemplary embodiment, the following processing steps are also performed:
[0137] The position of the currently traversed desensitized attribute is determined based on the second start and end positions. If the position is less than the current processing position, the preset position is obtained. If the string length between the preset position and the end position is greater than or equal to the sum of the lengths of the desensitized attribute name, separator, and plaintext of the desensitized attribute corresponding to the currently traversed desensitized attribute, then based on the second start and end positions and the association relationship, it is determined whether there is a desensitized attribute name and plaintext that match the currently traversed desensitized attribute in the plaintext string to be printed.
[0138] If the position of the currently traversed de-identified attribute is less than the current processing position, it means that the de-identified attribute is located before the current processing position, i.e., the de-identified attribute has already been processed or is in a processed area. In this case, a specific operation is required to determine whether the currently traversed de-identified attribute actually exists. At this time, a local variable pos needs to be defined to obtain the preset position. The initial value of the preset position variable can be the current processing position. Based on the preset position and the end position, a threshold value judgment is made. If the length between the preset position pos and the end position end is less than the length of the de-identified attribute name + separator + the plaintext value of the currently traversed de-identified attribute, it means that the de-identified field does not exist, i.e., exhaustArr[i] = true. The current de-identified attribute is skipped, and the next (i+1) de-identified attribute is judged. If the length of the string between the preset position and the end position is greater than or equal to the sum of the lengths of the desensitized attribute name, separator, and plaintext of the desensitized attribute corresponding to the currently traversed desensitized attribute, it means that there may be a corresponding desensitized field, and further judgment is needed. That is, based on the second start and end positions and the association relationship, it is determined whether there is a desensitized attribute name and desensitized attribute plaintext that match the currently traversed desensitized attribute in the plaintext of the string to be printed.
[0139] It should be noted that before traversing the list of desensitized attributes, there is a stored relationship between each desensitized attribute in the list and its corresponding desensitized attribute name, plaintext of the desensitized attribute, and desensitized value. Based on this relationship, it is possible to more accurately determine whether a field is a true desensitized field, thus avoiding incorrect desensitization.
[0140] In one exemplary embodiment, such as Figure 4 As shown, a method for finding de-identified attributes is provided, including the following steps:
[0141] Step 402: Determine the target string at the corresponding position from the plaintext string to be printed based on the second start and end positions.
[0142] Step 404: If there is a desensitized attribute name in the target string that matches the currently traversed desensitized attribute, then obtain the adjacent string concatenated after the delimiter of the matching desensitized attribute name.
[0143] Understandingly, retrieving the string adjacent to the desensitized attribute name after the desensitized attribute name means skipping the desensitized attribute name and determining if the immediately following string is the plaintext value of the desensitized attribute. This method, instead of calling the `indexOf` method again to locate the attribute value and then comparing the two positions, reduces the search scope and is compatible with complex desensitizers such as multiple newlines and spaces.
[0144] Step 406: If the adjacent strings, the matched desensitized attribute name, and the currently traversed desensitized attribute satisfy the association relationship and the end of the adjacent strings is a separator, then the adjacent strings are determined as the plaintext of the desensitized attribute of the traversed desensitized attribute.
[0145] The delimiter can be, but is not limited to, _____. Add whitespace characters such as spaces, tabs, and line breaks. For the located desensitized attribute values, check whether the preceding and following characters are separators to prevent partial desensitization.
[0146] For example, starting from a preset position, the position of the desensitized field name (which can also be understood as the desensitized attribute name) corresponding to the currently traversed desensitized attribute is located at the second start and end position. That is, based on the second start and end position, the target string at the corresponding position is determined from the plaintext string to be printed. If there is a desensitized attribute name in the target string that matches the currently traversed desensitized attribute, the adjacent string concatenated after the separator of the matching desensitized attribute name is obtained. It is determined whether the immediately adjacent string is the plaintext value of the currently traversed desensitized attribute. If so, it is further determined whether the end of the string is also a separator. If so, the adjacent string is determined as the plaintext of the desensitized attribute of the traversed desensitized attribute, and the starting position of the plaintext of the desensitized attribute is determined as the position of the corresponding desensitized field. In other words, although the desensitized attribute name and separator come before this, the desensitized attribute name and separator do not need to be replaced; they can be copied directly. Marking the starting position of the plaintext is for the purpose of facilitating desensitization replacement.
[0147] Furthermore, if the starting position of the plaintext of the desensitized attribute being traversed is less than the minimum position, then the position of the desensitized attribute being traversed satisfies the preset position condition, that is, the desensitized attribute being traversed is the desensitized attribute with the most recent position.
[0148] In the above embodiments, for the currently traversed de-identified attributes, the search is only performed at the start and end positions of the corresponding parameters, narrowing the search range. Furthermore, the de-identified attributes are accurately confirmed based on their names and values, avoiding false or excessive de-identification and ensuring the accuracy and reliability of the data.
[0149] In one exemplary embodiment, such as Figure 5 As shown, a method for replacing desensitized attribute values is provided, including the following steps:
[0150] Step 502: Desensitize the plaintext of the desensitized attributes of the currently traversed desensitized attributes to obtain the desensitized values.
[0151] In this case, desensitization can be achieved by directly replacing the plaintext desensitized attribute of the currently traversed desensitized attribute with the stored desensitized value.
[0152] Step 504: Obtain the substring of characters between the current processing position and the starting position of the current traversal of the plaintext value of the desensitized attribute from the plaintext string to be printed, and append the substring and the desensitized value to the StringBuilder object in sequence.
[0153] Step 506: Update the current minimum position based on the starting position of the currently traversed desensitized attributes, and update the current processing position by adding the matching position of the currently traversed desensitized attributes to the length of the plaintext of the desensitized attributes.
[0154] Understandably, the current processing position is updated by adding the starting position of the currently traversed plaintext with the length of the plaintext with the desensitized attribute.
[0155] Step 508: Execute the step of traversing the desensitized attributes in the desensitized attribute list, and for the currently traversed desensitized attribute, determine the second start and end positions of the parameter of the currently traversed desensitized attribute from the plaintext of the string to be printed, until the traversal is completed and the desensitized string to be printed is obtained.
[0156] Understandably, if the currently traversed de-identified attribute is the first de-identified attribute determined in the first traversal, then the substring between the current processing position and the starting position of the de-identified attribute's plaintext is obtained from the plaintext string to be printed. This substring and the de-identified value are then appended sequentially to the StringBuilder object. The current processing position is then updated, and the same processing steps are performed for the first de-identified attribute determined in the second traversal. It should be noted that the substring between the current processing position and the starting position of the de-identified attribute's plaintext is obtained from the plaintext string to be printed, excluding the starting position of the de-identified attribute's plaintext.
[0157] Furthermore, if there is no currently traversed de-identification attribute, then obtain the character substring between the current processing position and the end position of the plaintext to be printed; append the character substring to the StringBuilder object.
[0158] In this embodiment, by determining the first desensitized attribute value, a single StringBuilder object is used to append it from beginning to end, reducing performance-intensive operations such as underlying storage expansion and character array copying.
[0159] In one exemplary embodiment, such as Figure 6 As shown, a log anonymization method is provided. This embodiment illustrates the application of this method to a terminal. In this embodiment, the method includes the following steps:
[0160] Step 602: Obtain the list of desensitized attributes of the object to be printed, as well as the relationship between the desensitized attribute name, the plaintext of the desensitized attribute, and the desensitized value of each desensitized attribute in the list, and organize them into a List.<String[]> The data format stores this association.
[0161] Step 604: Format the object to be printed to obtain the plaintext string to be printed, and determine the first start and end positions of each parameter in the object to be printed after formatting in the plaintext string to be printed.
[0162] Step 606: Determine the length characteristics of the plaintext string to be printed, and construct a StringBuilder object based on the length characteristics.
[0163] Step 608: Traverse each desensitized attribute in the desensitized attribute list. For the currently traversed desensitized attribute, determine the second start and end positions of the parameter containing the currently traversed desensitized attribute from the plaintext string to be printed.
[0164] Step 610: Based on the second start and end positions and the association relationship, if the plaintext of the string to be printed contains a desensitized attribute name and desensitized attribute plaintext that match the currently traversed desensitized attribute, and the position of the currently traversed desensitized attribute meets the preset position conditions, then the plaintext of the currently traversed desensitized attribute is desensitized until the traversal is completed, and the desensitized string to be printed is obtained.
[0165] It should be noted that the specific implementation of this example can be achieved through the methods described above, which will not be elaborated upon here.
[0166] The following is an exemplary embodiment of a specific implementation method for finding identical attribute names and values in a string to be printed, and then replacing them with a desensitized string, including:
[0167] Step 1: Initialization phase: Construct a StringBuilder object with a capacity equal to the length of the string to be anonymized, plus the length difference between all anonymized strings and the plaintext string.
[0168] Construct an integer array `int[] matchPosArr`: its length is the number of de-identified attributes, indicating the position of the de-identified field. The initial position is set to -1. Construct a boolean array `boolean[] exhaustArr`: its length is the number of de-identified attributes. A value of `true` indicates that the search has reached the end and the de-identified field can no longer be found.
[0169] The length of the plaintext string to be printed is determined as len; the current processing position currentPos is initially set to 0;
[0170] The minimum position minPos (i.e., the position of the earliest desensitized attribute): initialized to the maximum value of the integer type (Integer.MAX_VALUE); the index of the desensitized attribute that is hit: matchIndex (the initial value is -1).
[0171] Step 2: Traverse the list of objects to be printed (outer layer: List, each element corresponds to 1 parameter to be printed),
[0172] for(int j = 0; j < list.size(); j++){ / / list is the desensitized attribute list of all objects to be printed;
[0173] List<String[]> list2 = list.get(j); / / list2 is the desensitized attribute list of a certain object to be printed;
[0174] int start = startIndices[j]; / / The start position after formatting the desensitized attribute;
[0175] int end = endIndices[j]; / / The end position after formatting the desensitized attribute;
[0176] while(currentPos < end){ / / When currentPos is less than end, execute;
[0177] for(int i = 0; i < list2.size(); i++){ / / Traverse each desensitized attribute;
[0178] / / Find and determine the earliest desensitized attribute;
[0179] }
[0180] / / Replace the desensitized attribute;
[0181] / / Update the currentPos position;
[0182] }
[0183] };
[0184] Step 3: When currentPos is less than end, iterate through each de-identified attribute. If the de-identified attribute is not found (exhaustArr[i] is true), skip it and continue to judge the next (i+1) de-identified attribute. If the position of the de-identified attribute is behind the current processing position currentPos; define pos, with an initial value of currentPos; perform a threshold judgment: if the length between pos and end is less than the length of the de-identified attribute name + separator + de-identified attribute value, it means that the de-identified field does not exist, exhaustArr[i] = true, skip the current de-identified attribute, and continue to judge the next (i+1) de-identified attribute. It should be noted that the current processing position is a position index and is not closely related to the end index of the de-identified value. For example, user: {"phone":"12345678999"}, initially currentPos = 0, the minimum position is the index of the phone number 1, append currentPos to the StringBuilder to the substring before the phone number 1, and add... Then currentPos is set to the double quotes after the last 9 of the phone number, which is indeed adjacent to the end index of the de-identified value. The minimum position is the starting index of the attribute value corresponding to the de-identified attribute.
[0185] Step 4: Find the masked attribute: Starting from position pos, locate the position of the masked field name using the improved indexOf method: StringUtil.indexOf(str,field,start,end), which adds the end parameter to limit the search range; if not found, set exhaustArr[i] to true, skip the current masked attribute, and continue to check the next (i+1) masked attribute; if found, skip the separators after the field name (these separators have... Add whitespace characters such as spaces, tabs, and newlines, and determine if the immediately adjacent string is the plaintext value of the de-identified attribute; if so, determine if the end of the string is also a delimiter. If so, set matchPos to the starting position of the de-identified attribute value and matchPosArr[i] to matchPos; if matchPosArr[i] is less than minPos, set minPos to matchPosArr[i] and matchIndex to i.
[0186] Step 5: Replace the desensitized attribute values. After iterating through all desensitized attributes, if matchIndex is not -1, the builder appends: the substring to be desensitized: from currentPos to matchPosArr[matchIndex], and the desensitized value; if matchIndex is -1, the builder appends: the substring to be desensitized: from currentPos to end.
[0187] Step 6: Update currentPos so that in the next loop, currentPos is set to: the position of the de-identified attribute matching position, plus the length of the plaintext value of the de-identified attribute, and continue to locate and replace until the end.
[0188] Step 7: Tail string processing; After traversing the list of objects to be printed, if currentPos is less than len, the builder appends: the substring to be de-identified: the substring between currentPos and the string to be de-identified.
[0189] Step 8: Return the anonymized string: Call the builder.toString() method, which is the anonymized string to be printed.
[0190] For example, retrieve the object to be printed: log.info("user:{},credit:{}", userObj, credit0bj); construct the plaintext string to be printed, recording the start and end positions of each parameter: user: {"Phone": "12345678900","email":"test@xxx.com"}, credit{"expireMonth":"12","expireYear":"2028"}, the start and end positions of the first parameter are 6,52; the start and end positions of the second parameter are 63,103;
[0191] The first parameter has two de-identified attributes. A custom `indexOf` is used to locate the attribute that appears first, replacing the one listed earlier. This way, only one `StringBuilder` is needed. Attribute name: `Phone`, attribute value: `12345678900`, after de-identification... Search within the range of position 6-52, first match "Phone", skip the separator, check if the value is 12345678900, and get the starting index of the value, 17; Desensitized attribute name: email, attribute value: test@xxxcom, after desensitization... Search within the range of positions 6-52, first matching "email", skipping the separator, checking if the value is "test@xxxcom", obtaining the starting index of the value (39), creating a new StringBuilder, since the index of "phone" is smaller than that of "email", first replacing the value of "phone": user:{"phone":" The StringBuilder above appends the part between the phone and email values, as well as the anonymized email value: user:{"phone":" ","email": ;
[0192] The second parameter has two desensitized attributes. A custom `indexOf` is used to determine which attribute appears first: the earlier desensitized attribute is replaced first. Desensitized attribute name: `expireMonth`, attribute value: 12. After desensitization... Search within the range of positions 63-103, first match `expireMonth`, then skip the separator, check if the value is 12, and get the starting index of the value: 80; Desensitized attribute name: `expireYear`, attribute value: `2028`, after desensitization... Search within the range of positions 63-103, first matching `expireYear`, then skipping the separator, checking if the value is 2028, obtaining the starting index of the value (98). Since the index of `expireMonth` is smaller than `expireYear`, append the part between the email value and the `expireMonth` value, as well as the anonymized value of `expireMonth`: user:{"phone":" ","email": }, credit{"expireMonth":" ;
[0193] Then append the part between the expireMonth and expireYear values, and the anonymized expireYear value: user:{"phone":" ","email": }, credit{"expireMonth":" ",expireYear:" Finally, append the expireYear value to the end: user:{"phone":" ","email": }, credit{"expireMonth":" ",expireYear:" "}
[0194] For example, in an exemplary embodiment, based on the above log desensitization method, this log desensitization component is introduced into a Spring Boot 2 application, and desensitization configuration is added to the application.yml configuration file; an AppUser class is created, where idCard is the ID card field, with the desensitization annotation @Sensitive, and the type is ID card; to is the list of email addresses to send to, defined as email type in application.yml in step 1; a key-value pair with email as the key is constructed in the map, and the email field is defined as email type in application.yml; a CreditCard class is created, where expireMonth: the month the card expires, defined as confidential type in application.yml in step 1; expireYear: the year the card expires, defined as confidential type in application.yml in step 1; cvv: the card verification code, with the desensitization annotation @Sensitive, and the type is confidential. By obtaining the pair to be printed, the above log desensitization method is executed, and the printing result is obtained:
[0195] user: AppUser(username=john, , , , This ensures that the two 12s in user.setIdCard("330101201912150598") are not replaced with the correct number because they are the same as expireMonth. The 12 in card.setCvv("129") will not be replaced with .
[0196] In the above embodiments, before printing the log, in addition to obtaining the plaintext of the desensitized attributes and their desensitized values of the object to be printed, the corresponding desensitized attribute names are also obtained. The association between these three attributes is then stored in an array, improving performance, reducing memory usage, and preventing the replacement of other attributes with the same value during desensitization processing, thus avoiding accidental and multiple desensitizations. Based on this, by determining the first start and end positions of each parameter in the formatted plaintext string to be printed, the desensitized attributes in the desensitized attribute list are traversed. For the currently traversed desensitized attribute, the desensitized attribute is determined from the plaintext string to be printed. The second start and end positions of the parameter are used; based on the second start and end positions and the association, if the plaintext of the string to be printed contains a desensitized attribute name and desensitized attribute plaintext that match the currently traversed desensitized attribute, and the position of the currently traversed desensitized attribute meets the preset position condition, then the plaintext of the currently traversed desensitized attribute is desensitized until the traversal is completed, and the desensitized string to be printed is obtained. Only one StringBuilder is used to append from the beginning to the end. This method does not require searching from the beginning position of the entire string to be printed every time when searching for all desensitized attributes. It only needs to be searched within the corresponding parameter start and end position range, which reduces performance loss.
[0197] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0198] Based on the same inventive concept, this application also provides a log desensitization device for implementing the log desensitization method described above. The solution provided by this device is similar to the solution described in the above method; therefore, the specific limitations of the one or more log desensitization device embodiments provided below can be found in the limitations of the log desensitization method described above, and will not be repeated here.
[0199] In one exemplary embodiment, such as Figure 7 As shown, a log de-identification device is provided, including: a data acquisition module 702, a formatting module 704, a traversal module 706, and a de-identification module 708, wherein:
[0200] The data acquisition module 702 is used to acquire the list of desensitized attributes of the object to be printed, as well as the relationship between the desensitized attribute name, the plaintext of the desensitized attribute, and the desensitized value of each desensitized attribute in the list;
[0201] The formatting module 704 is used to format the object to be printed, obtain the plaintext string to be printed, and determine the first start and end positions of each parameter in the object to be printed after formatting in the plaintext string to be printed.
[0202] The traversal module 706 is used to traverse the desensitized attributes in the desensitized attribute list. For the currently traversed desensitized attribute, the second start and end positions of the parameter containing the currently traversed desensitized attribute are determined from the plain text of the string to be printed.
[0203] The desensitization module 708 is used to desensitize the plaintext of the desensitized attribute based on the second start and end positions and the association relationship. If the plaintext of the string to be printed contains a desensitized attribute name and desensitized attribute plaintext that match the currently traversed desensitized attribute, and the position of the currently traversed desensitized attribute meets the preset position conditions, then the plaintext of the currently traversed desensitized attribute will be desensitized until the traversal is completed, and the desensitized string to be printed will be obtained.
[0204] The aforementioned log desensitization device, before printing logs, not only obtains the plaintext of the desensitized attributes of the object to be printed and their desensitized values, but also obtains the corresponding desensitized attribute names, thus establishing the relationship between the three. This processing method prevents the replacement of other attributes with the same value during desensitization, avoiding accidental desensitization and multiple desensitizations. Based on this, by determining the first start and end positions of each parameter in the formatted plaintext string to be printed, the device iterates through the desensitized attributes in the desensitized attribute list. For the currently iterated desensitized attribute, it determines the current desensitized attribute from the plaintext string to be printed. The algorithm iterates through the second start and end positions of the parameters containing the desensitized attributes. Based on these second start and end positions and the association relationships, if the plaintext of the string to be printed contains a desensitized attribute name and plaintext that match the currently iterated desensitized attribute, and the position of the currently iterated desensitized attribute meets the preset position conditions, then the plaintext of the currently iterated desensitized attribute is desensitized. This process continues until all desensitized attributes are found, resulting in the desensitized string to be printed. This method eliminates the need to search from the beginning of the entire string to be printed each time when searching for all desensitized attributes; it only requires searching within the corresponding parameter start and end position range, thus reducing performance overhead.
[0205] In an exemplary embodiment, the above-described apparatus further includes a construction module, which is used to determine the length characteristics of the plaintext string to be printed and construct a StringBuilder object based on the length characteristics; wherein the StringBuilder object is used to store the anonymized string to be printed.
[0206] In an exemplary embodiment, the construction module is further configured to determine the length of the plaintext string to be printed, as well as the plaintext length and the length after desensitization of each desensitized field in the plaintext string to be printed; each desensitized field includes the plaintext of the desensitized attribute;
[0207] For each de-identified field, determine the corresponding length difference based on the plaintext length and the de-identified length;
[0208] The total length is determined based on the length differences and the length itself. A StringBuilder object is then constructed with the total length as the capacity.
[0209] In an exemplary embodiment, the data acquisition module 702 is used to determine the type of the object to be printed, and obtain a list of desensitized attributes of the object to be printed from the mapping relationship between the cached type and the desensitized attributes.
[0210] For each desensitized attribute in the desensitized attribute list, obtain the corresponding desensitized attribute name, the plaintext of the desensitized attribute, and the desensitized value;
[0211] List<String[]> The data format stores the desensitized attributes, along with their corresponding desensitized attribute names, plaintext desensitized attributes, and desensitized values, thus obtaining the corresponding association relationships.
[0212] In an exemplary embodiment, the formatting module 704 is configured to, for each parameter in the formatted object to be printed, determine the length of the content preceding each parameter as the first start position of the parameter, and determine the first end position based on the first start position and the length of the formatted parameter.
[0213] Based on the first start position and the first end position, determine the first start and end positions of each parameter in the plaintext string to be printed after formatting.
[0214] In an exemplary embodiment, the traversal module 706 is used to obtain the end position and the current processing position of the plaintext string to be printed; the current processing position is used to indicate the current position of the plaintext string to be printed in the string;
[0215] If the current processing position is less than the end position, then iterate through the desensitized attributes in the desensitized attribute list. For the currently traversed desensitized attribute, determine the second start and end positions of the parameter containing the currently traversed desensitized attribute from the plaintext string to be printed.
[0216] In an exemplary embodiment, the above-mentioned device further includes a desensitization attribute determination module, which is used to determine the position of the currently traversed desensitization attribute based on the second start and end positions, and if the position is less than the current processing position, then a preset position is obtained.
[0217] If the length of the string between the preset position and the end position is greater than or equal to the sum of the lengths of the desensitized attribute name, separator, and plaintext of the desensitized attribute corresponding to the currently traversed desensitized attribute, then based on the second start and end positions and the association relationship, it is determined whether there is a desensitized attribute name and plaintext of the desensitized attribute that match the currently traversed desensitized attribute in the plaintext of the string to be printed.
[0218] In an exemplary embodiment, the desensitization attribute determination module is used to determine the target string at the corresponding position from the plaintext string to be printed based on the second start and end positions;
[0219] If the target string contains a desensitized attribute name that matches the currently traversed desensitized attribute, then obtain the adjacent string concatenated after the delimiter of the matching desensitized attribute name;
[0220] If the adjacent strings, the matched desensitized attribute name, and the currently traversed desensitized attribute satisfy the association relationship, and the end of the adjacent strings is a separator, then the adjacent strings are determined as the plaintext of the desensitized attribute of the traversed desensitized attribute.
[0221] In an exemplary embodiment, the desensitization module 708 is used to determine that the position of the currently traversed desensitized attribute satisfies a preset position condition if the starting position of the plaintext of the desensitized attribute being traversed is less than the minimum position of the plaintext of the string to be printed; the minimum position is used to represent the position of the current first desensitized attribute.
[0222] In an exemplary embodiment, the desensitization module 708 is used to desensitize the plaintext of the desensitized attributes of the currently traversed desensitized attributes to obtain the desensitized value;
[0223] Get the substring between the current processing position and the starting position of the current traversal of the plaintext value of the desensitized attribute from the plaintext string to be printed, and append the substring and the desensitized value to the StringBuilder object in sequence;
[0224] Update the current minimum position based on the starting position of the currently traversed desensitized attributes, and update the current processing position by adding the starting position of the plaintext value of the currently traversed desensitized attributes to the length of the plaintext value of the desensitized attributes;
[0225] The process involves iterating through the desensitized attributes in the desensitized attribute list. For each desensitized attribute being iterated through, the process involves determining the second start and end positions of the parameter containing the current desensitized attribute from the plaintext string to be printed. This process continues until all attributes have been traversed, resulting in the desensitized string to be printed.
[0226] In an exemplary embodiment, the desensitization module 708 is used to obtain a character substring from the plaintext string to be printed between the current processing position and the end position of the plaintext string if no desensitization attribute is currently being traversed.
[0227] Appends a substring of characters to a StringBuilder object.
[0228] Each module in the aforementioned log desensitization device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of a computer device in hardware form or independent of it, or stored in the memory of the computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0229] In one exemplary embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 8 As shown, the computer device includes a processor, memory, input / output interfaces, a communication interface, a display unit, and an input device. The processor, memory, and input / output interfaces are connected via a system bus, and the communication interface, display unit, and input device are also connected to the system bus via the input / output interfaces. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The input / output interfaces are used for exchanging information between the processor and external devices. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, mobile cellular networks, Near Field Communication (NFC), or other technologies. When the computer program is executed by the processor, it implements a log desensitization method. The display unit is used to form a visually visible image and can be a display screen, a projection device, or a virtual reality imaging device. The display screen can be an LCD screen or an e-ink screen. The input device of the computer device can be a touch layer covering the display screen, or buttons, trackballs, or touchpads set on the casing of the computer device, or external keyboards, touchpads, or mice, etc.
[0230] Those skilled in the art will understand that Figure 8 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0231] In one embodiment, a computer device is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above method embodiments.
[0232] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon that, when executed by a processor, implements the steps in the above method embodiments.
[0233] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0234] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.
[0235] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0236] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0237] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.< / string> < / string>
Claims
1. A log anonymization method, characterized in that, The method includes: Obtain the list of desensitized attributes of the object to be printed, as well as the relationship between the desensitized attribute name, the plaintext of the desensitized attribute, and the desensitized value of each desensitized attribute in the list; The object to be printed is formatted to obtain plaintext string to be printed, and the first start and end positions of each parameter in the object to be printed are determined in the plaintext string to be printed after formatting. Iterate through each desensitized attribute in the desensitized attribute list, and for the currently traversed desensitized attribute, determine the second start and end positions of the parameter containing the currently traversed desensitized attribute from the plaintext string to be printed; Based on the second start and end positions and the association relationship, if the plaintext of the string to be printed contains a desensitized attribute name and desensitized attribute plaintext that match the currently traversed desensitized attribute, and the position of the currently traversed desensitized attribute satisfies the preset position condition, then the plaintext of the currently traversed desensitized attribute is desensitized until the traversal is completed, and the desensitized string to be printed is obtained.
2. The method according to claim 1, characterized in that, Before iterating through the desensitized attributes in the desensitized attribute list, the method further includes: Determine the length characteristics of the plaintext string to be printed, and construct a StringBuilder object based on the length characteristics; wherein, the StringBuilder object is used to store the anonymized string to be printed.
3. The method according to claim 2, characterized in that, Determining the length characteristics of the plaintext string to be printed, and constructing a StringBuilder object based on the length characteristics, includes: Determine the length of the plaintext string to be printed, as well as the plaintext length and the length after desensitization of each desensitized field in the plaintext string to be printed; each desensitized field includes the plaintext of the desensitized attribute; For each of the de-identified fields, a corresponding length difference is determined based on the plaintext length and the de-identified length. The total length is determined based on the length differences and the lengths themselves, and a StringBuilder object is constructed using the total length as the capacity.
4. The method according to claim 1, characterized in that, The process of obtaining the list of desensitized attributes of the object to be printed, and the relationship between the desensitized attribute name, the plaintext of the desensitized attribute, and the desensitized value of each desensitized attribute in the list, includes: Determine the type of the object to be printed, and obtain the list of desensitized attributes of the object to be printed based on the mapping relationship between the cached type and the desensitized attributes. For each desensitized attribute in the desensitized attribute list, obtain the corresponding desensitized attribute name, desensitized attribute plaintext, and desensitized value; List<String[]> The data format stores the desensitized attributes, the corresponding desensitized attribute names, the plaintext of the desensitized attributes, and the desensitized values to obtain the corresponding association relationships.
5. The method according to claim 1, characterized in that, Determining the first start and end positions of each parameter in the plaintext string to be printed after formatting includes: For each parameter in the formatted object to be printed, the length of the content before each parameter is determined as the first start position of the parameter, and the first end position is determined based on the first start position and the length of the formatted parameter. Based on the first start position and the first end position, determine the first start and end positions of each parameter in the object to be printed after formatting in the plaintext string to be printed.
6. The method according to claim 1, characterized in that, The step of traversing the desensitized attributes in the desensitized attribute list, and determining the second start and end positions of the parameter containing the currently traversed desensitized attribute from the plaintext string to be printed, includes: Obtain the end position and current processing position of the plaintext string to be printed; the current processing position is used to indicate the current position of the plaintext string to be printed in the current processing. If the current processing position is less than the end position, then the desensitized attributes in the desensitized attribute list are traversed, and for the currently traversed desensitized attribute, the second start and end positions of the parameter of the currently traversed desensitized attribute are determined from the plaintext string to be printed.
7. The method according to claim 6, characterized in that, The method further includes: The position of the currently traversed desensitized attribute is determined based on the second start and end positions. If the position is smaller than the current processing position, a preset position is obtained. If the string length between the preset position and the end position is greater than or equal to the sum of the lengths of the desensitized attribute name, separator, and desensitized attribute plaintext corresponding to the currently traversed desensitized attribute, then based on the second start and end positions and the association relationship, it is determined whether there is a desensitized attribute name and desensitized attribute plaintext matching the currently traversed desensitized attribute in the plaintext string to be printed.
8. The method according to claim 7, characterized in that, The step of determining whether the plaintext string to be printed contains a desensitized attribute name and plaintext that match the currently traversed desensitized attribute, based on the second start and end positions and the association relationship, includes: Based on the second start and end positions, determine the target string at the corresponding position from the plaintext string to be printed; If the target string contains a desensitized attribute name that matches the currently traversed desensitized attribute, then obtain the adjacent string concatenated after the separator of the matching desensitized attribute name; If the adjacent string, the matched desensitized attribute name, and the currently traversed desensitized attribute satisfy the association relationship and the end of the adjacent string is a separator, then the adjacent string is determined as the plaintext of the desensitized attribute of the traversed desensitized attribute.
9. The method according to claim 8, characterized in that, The position of the currently traversed desensitized attribute satisfies preset position conditions, including: If the starting position of the plaintext of the currently traversed desensitized attribute is less than the minimum position of the plaintext of the string to be printed, then the position of the currently traversed desensitized attribute satisfies the preset position condition; the minimum position is used to represent the position of the current first desensitized attribute.
10. The method according to claim 2, characterized in that, The process of plaintext desensitizing the currently traversed desensitized attributes continues until the traversal is complete, resulting in the desensitized string to be printed, including: The desensitized attributes of the currently traversed desensitized attributes are desensitized from plaintext to obtain the desensitized values; Obtain the substring between the current processing position and the starting position of the current traversal of the desensitized attribute plaintext value from the plaintext string to be printed, and append the substring and the desensitized value to the StringBuilder object in sequence; The current minimum position is updated based on the starting position of the currently traversed desensitized attributes, and the current processing position is updated by adding the starting position of the plaintext value of the currently traversed desensitized attributes to the length of the plaintext of the desensitized attributes. The process involves iterating through the desensitized attributes in the desensitized attribute list, determining the second start and end positions of the parameter containing the currently traversed desensitized attribute from the plaintext string to be printed, and continuing until the traversal is complete, thus obtaining the desensitized string to be printed.
11. The method according to claim 2, characterized in that, The method further includes: If the currently traversed desensitization attribute does not exist, then obtain the character substring between the current processing position and the end position of the plaintext to be printed from the plaintext to be printed. The character substring is appended to the StringBuilder object.
12. A log desensitization device, characterized in that, The device includes: The data acquisition module is used to acquire a list of desensitized attributes of the object to be printed, as well as the relationship between the desensitized attribute name, the plaintext of the desensitized attribute, and the desensitized value of each desensitized attribute in the list; The formatting module is used to format the object to be printed to obtain the plaintext string to be printed, and to determine the first start and end positions of each parameter in the object to be printed after formatting in the plaintext string to be printed. The traversal module is used to traverse the desensitized attributes in the desensitized attribute list, and for the currently traversed desensitized attribute, determine the second start and end positions of the parameter where the currently traversed desensitized attribute is located from the plaintext string to be printed; The desensitization module is used to desensitize the plaintext of the desensitized attribute based on the second start and end positions and the association relationship, if the plaintext of the string to be printed contains a desensitized attribute name and desensitized attribute plaintext that match the currently traversed desensitized attribute, and the position of the currently traversed desensitized attribute meets a preset position condition, then desensitize the plaintext of the currently traversed desensitized attribute until the traversal is completed, and obtain the desensitized string to be printed.
13. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 11.
14. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 11.
15. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 11.