Help Center/ Data Security Center/ User Guide/ Security Management/ Data Masking/ Configuring and Checking Static Masking Algorithms
Updated on 2026-07-27 GMT+08:00

Configuring and Checking Static Masking Algorithms

DSC provides multiple masking algorithms to prevent sensitive data leaks. DSC provides built-in masking rules for hash masking, character masking, value change, rounding, and simulation masking. You can directly use these rules when creating a static data masking task.

To use Encryption or Keyword Replacement when creating a static masking task, you need to configure their parameters first.

  • To use Encryption, you need to configure the master key and data key length for KMS encryption.
  • To use Keyword Replacement, you need to configure keywords and their replacement strings.

Masking Algorithms and Application Scenarios

Table 1 Masking algorithms

Algorithm

Description

Application Scenario

Hash

Use Hash functions to mask sensitive data. DSC supports SHA256 and SHA512.

  • SHA256

    SHA256, a message-digest algorithm, is used by DSC to compute a digest from a string in the database table.

    It takes a block of data and returns a fixed-size bit string (hash value). As the value length may exceed the maximum column width allowed in the original table, you can adjust the column width to adapt to the returned SHA256 hash values.

  • SHA512

    SHA512, a message-digest algorithm, is used by DSC to compute a digest from a string in the database table.

    It takes a block of data and returns a fixed-size bit string (hash value). As the value length may exceed the maximum column width allowed in the original table, you can adjust the column width to adapt to the returned SHA512 hash values.

  • Sensitive data:

    Keys

  • Application scenarios:

    Data storage

Encryption

Use an encryption algorithm and an encryption master key to generate a specified Data Encryption Key (DEK). This DEK is then used to encrypt sensitive data, thereby achieving data masking.

DSC supports the AES256 encryption algorithm.

  • Sensitive data:
    • Personal data
    • Enterprise data
  • Application scenarios:

    Data storage

Character Masking

Use the specified character * or random characters (including numbers, letters, and both number and letters) to cover part of the original content. The following six data masking approaches are supported:

  • Retain first N and last M
  • Retain from X to Y
  • Mask first N and last M
  • Mask from X to Y
  • Mask data ahead of special characters
  • Mask data followed by special characters
NOTE:

DSC has multiple character masking templates.

  • Sensitive data:

    Personal data

  • Application scenarios:
    • Data usage
    • Data sharing

Keyword Replacement

Search for keywords in a specified column and replace them.

For example, the specified characters are "Zhang San eats at home". After replacement, the characters become "Mr. Zhang eats at home". In the example, "Zhang San" is replaced with "Mr. Zhang".

After this algorithm is executed, the value length may exceed the maximum length allowed by the database. In this case, the excess part will be truncated and inserted into the database.

  • Sensitive data:
    • Personal data
    • Enterprise data
    • Device data
  • Application scenarios:
    • Data storage
    • Data sharing

Value Change

Set a specified field to Null or leave it blank for data masking.

  • Masking Using the Null Value

    Set a field of any type to NULL.

    If a field is set to NOT NULL, this algorithm changes the attribute of the field to NULL when copying the column.

  • Masking Using a Custom Value

    Set the target field to a default value.

    Specifically, a character field is left blank, a numeric field is set to 0, a date field is set to 1970, and time field is set to 00:00.

  • Sensitive data:
    • Personal data
    • Enterprise data
    • Device data
  • Application scenarios:
    • Data storage
    • Data sharing

Roundup

Round a date or number.

  • Date rounding

    Round the fields after the year field. For example, 2019-05-12 will be converted to 2019-01-01, and 2019-05-12 08:08:08 will be converted to 2019-01-01 00:00:00.

    Round the fields after the month field. For example, 2019-05-12 will be converted to 2019-05-01, and 2019-05-12 08:08:08 will be converted to 2019-05-01 00:00:00.

    Round fields after the day field. For example, 2019-05-12 will be converted to 2019-05-12, and 2019-05-12 08:08:08 will be converted to 2019-05-12 00:00:00.

    Round the fields after the hour field. For example, 08:08:08 will be converted to 08:00:00, and 2019-05-12 08:08:08 will be converted to 2019-05-12 08:00:00.

    Round the fields after the minute field. For example, 08:08:08 will be converted to 08:08:00, and 2019-05-12 08:08:08 will be converted to 2019-05-12 08:08:00.

    Round the fields after the second field. For example, 08:08:08.123 will be converted to 08:08:08.000, and 1575612731312 will be converted to 1575612731000.

  • Number rounding

    Round a specified number.

  • Sensitive data:

    General sensitive data

  • Application scenarios:
    • Data storage
    • Data usage

Simulation Masking

After identifying sensitive data, DSC replaces it with simulated data. Sensitive values are replaced by simulated data, which strictly follows the format, business rules, and distribution of the original data. This ensures personal privacy and data security while retaining the business logic and data relationships, making it suitable for R&D, testing, and analytics.

  • Sensitive data:
    • Personal data
    • Enterprise data
    • Device data
  • Application scenarios:
    • Data usage
    • Data sharing

Configuring and Viewing Masking Rules

You can configure masking rules for specified data types to implement static masking of sensitive data. This section describes the data types supported by each masking algorithm and how to add and test masking algorithms.

This method is used to replace a field of the string type with a hash value. In a relational database, if the field length is less than the hash length, the length of the field in the destination database is set to be the same as the hash value length to ensure that the hash value is completely written to the destination database. By default, two hash algorithms, SHA256 and SHA512, are configured for DSC.

Hash algorithms are built-in and do not need to be configured. If you want to test the masking effect, perform the following steps:

  1. Log in to the DSC console.
  2. Click in the upper left corner and select a region or project.
  3. In the navigation pane on the left, choose Security Management > Data Masking. Click the Masking Rule tab page.

    Figure 1 Hash masking

  4. In the column of the selected SHA256 or SHA512 algorithm, click Edit and Test.
  5. On the Edit and Test page, set Masking Algorithm to Hash, enter Raw Data, and click Test. The masked data is displayed in the Masking Result text box.

    Figure 2 Hash method

This method masks data using encryption algorithms and a master key.

  1. Log in to the DSC console.
  2. Click in the upper left corner and select a region or project.
  3. In the navigation pane on the left, choose Security Management > Data Masking. Click the Masking Rule tab page.
  4. Click the Encryption tab.

    • Master Key Algorithm: Select an encryption algorithm from the drop-down list box. Currently, only AES256 is available.
      Table 2 Master key algorithms

      Key Type

      Algorithm Type

      Key Specifications

      Description

      Usage

      Symmetric key

      AES

      AES_256

      AES symmetric key

      Encrypts and decrypts a small amount of data or data keys.

    • For KMS encryption, you can select a KMS key from the drop-down list or enter a key ID.
      • Select from Keys: Select an existing master key from the drop-down list. If no master key is available, click Create KMS Key to create one. For details about how to create a KMS key, see Creating a Key.
      • Enter a KMS key ID: Enter the ID of the KMS key in the current region.
    • Select the Data Key Length from the drop-down list box. The options are 128, 192, and 256.

  5. After the configuration is complete, click Generate Encryption Configuration.

    If you want to delete a configured encryption configuration, click Delete in the Operation column.

    Click to enable the rotation policy. After rotation, the current encryption configuration is updated to improve security.

This method uses the specified character * or a random character to cover part of the content.

There are six masking methods available, including retaining first N and last M, retaining from X to Y, masking first N and last M, masking from X to Y, masking data ahead of special characters, and masking data followed by special characters.

  1. Log in to the DSC console.
  2. Click in the upper left corner and select a region or project.
  3. In the navigation pane on the left, choose Security Management > Data Masking. Click the Masking Rule tab page.
  4. Click the Character Masking tab.
  5. Click Add to configure a character masking rule.

    Figure 3 Adding a character masking rule

  6. Configure the parameters by referring to Table 3. Enter the raw data and click Test. The masking result will be displayed in the Masking Result text box.

    Table 3 Character masking parameters

    Parameter

    Description

    Name

    Enter a character masking rule name. The name can contain only letters, digits, underscores (_), and hyphens (-), and cannot exceed 255 characters.

    Rule

    The following rules are available:

    • Retain first N and last M
    • Retain from X to Y
    • Mask first N and last M
    • Mask from X to Y
    • Mask data ahead of special characters
    • Mask data followed by special characters

    Rule Variable

    Enter the value of the corresponding rule. For example, if you select Retain from x to y, set x to 3, and set y to 6, meaning the third to sixth characters are retained.

    Masking Method

    The optional masking methods are as follows:

    • Fixed characters: Replace specified characters with fixed characters.
    • Random characters: Replace specified characters with random characters.

    Masked with

    This parameter is displayed when Masking Method is set to Fixed Characters. You need to enter the specified characters used to mask data.

    Random Character Type

    This parameter is displayed when Masking Method is set to Random characters. The options are as follows:

    • Random letters
    • Random digits
    • Combination of random digits and letters

  7. Verify the testing result and click Save.

    • Multiple character masking rules have been preset in DSC. Built-in masking rules cannot be deleted. To delete a custom masking rule, click Delete in the Operation column of the target rule.
    • All rules can be edited. To edit a rule, locate the row containing the rule and click Edit in the Operation column.

This method masks data by replacing matched keywords with custom strings. For example, if the original characters are abcdefgbcdefgkjkoij, the keyword is bcde, and the replacement string is 12, the masking result is a12fg12fgkjkoij.

  1. Log in to the DSC console.
  2. Click in the upper left corner and select a region or project.
  3. In the navigation pane on the left, choose Security Management > Data Masking. Click the Masking Rule tab page.
  4. Click the Keyword Replacement tab.
  5. Click Add in the upper left corner. The Add Keyword page is displayed.
  6. Set the keyword and the replacement string.

    Then, the keywords matched in raw characters will be replaced with the replacement string.

    Figure 4 Adding a keyword

  7. Enter the raw data and click Test. The masking result will be displayed in the Masking Result text box.
  8. Verify the testing result and click Save.

    • In the Operation column of the keyword replacement rule list, click Edit and Test to modify a masking rule.
    • In the Operation column of the keyword replacement rule list, click Delete to delete a masking rule.

The following algorithms have been built in:
  • Masking Using the Null Value: Set fields of any type to NULL. For a field whose attribute is set to NOT NULL, the algorithm changes the attribute to NULL during copy.
  • Masking Using the Empty Value: Set the specified field to an empty value. Specifically, a character field is left blank, a numeric field is set to 0, a date field is set to 1970, and time field is set to 00:00.

It is a built-in masking rule of DSC and does not need to be configured. To view the masking rule, perform the following steps:

  1. Log in to the DSC console.
  2. Click in the upper left corner and select a region or project.
  3. In the navigation pane on the left, choose Security Management > Data Masking. Click the Masking Rule tab page.
  4. Click the Value Change tab.
  1. Log in to the DSC console.
  2. Click in the upper left corner and select a region or project.
  3. In the navigation pane on the left, choose Security Management > Data Masking. Click the Masking Rule tab page.
  4. Click Round.

    There are two built-in data masking algorithms available:

    • Date Roundup: Used for time-related fields such as timestamp, time, date, and datetime in RDS.
    • Number Roundup: Used for value types fields such as double, float, int, and long. After data masking, the original field type does not change.

  5. Click Edit and Test. On the Edit and Test page, select Roundup for Masking Algorithm and set the Roundup result.

    Masking Result: Rounds a given value downwards to a multiple value closest to the raw data. For example, if the given value is 5 and the raw data is 14, the multiple of 5 that is closest to 14 is 10. That is, the masking result is 10.

    Figure 5 Number roundup

  6. Enter the raw data and click Test. The masking result will be displayed in the Masking Result text box.
  7. Verify the testing result and click Save.

Once sensitive data is identified, it is replaced with simulated data. At present, this function applies to only OBS masking tasks and database masking tasks.

Simulated masking is a built-in rule of DSC and does not need to be configured. To check supported data types, perform the following steps:

  1. Log in to the DSC console.
  2. Click in the upper left corner and select a region or project.
  3. In the navigation pane on the left, choose Security Management > Data Masking. Click the Masking Rule tab page.
  4. Click the Simulation Masking tab.

    Table 4 Supported simulation masking types

    No.

    Sensitive Data Rule

    Simulation Masking Type

    1

    ID card No. (Chinese mainland)

    ID card number

    2

    Birthday

    Random date (specified range)

    3

    Date

    Random date (specified range)

    4

    Mobile number (Chinese mainland)

    Mobile number

    5

    Email address

    Email address

    6

    Postal code (Chinese mainland)

    Postal code

    7

    Address (Chinese mainland)

    Address

    8

    Exact address (China)

    Address

    9

    International mobile equipment identity (IMEI)

    IMEI

    10

    IPv4 address

    IPv4 address

    11

    IPv6 address

    IPv6 address

    12

    Bank account number

    Bank account number

    13

    Person name (Simplified Chinese)

    Person name

    14

    Car license plate number (Chinese mainland)

    Car license plate number

    15

    Passport No. (Chinese mainland)

    Passport No.