Reference documentation and code samples for the Data Loss Prevention V2 Client class CharacterMaskConfig.
Partially mask a string by replacing a given number of characters with a
fixed character. Masking can start from the beginning or end of the string.
This can be used on data of any type (numbers, longs, and so on) and when
de-identifying structured data we'll attempt to preserve the original data's
type. (This allows you to take a long like 123 and modify it to a string like
**3.
Generated from protobuf messagegoogle.privacy.dlp.v2.CharacterMaskConfig
Namespace
Google \ Cloud \ Dlp \ V2
Methods
__construct
Constructor.
Parameters
Name
Description
data
array
Optional. Data for populating the Message object.
↳ masking_character
string
Character to use to mask the sensitive values—for example,*for an alphabetic string such as a name, or0for a numeric string such as ZIP code or credit card number. This string must have a length of 1. If not supplied, this value defaults to*for strings, and0for digits.
↳ number_to_mask
int
Number of characters to mask. If not set, all matching chars will be masked. Skipped characters do not count towards this tally. Ifnumber_to_maskis negative, this denotes inverse masking. Cloud DLP masks all but a number of characters. For example, suppose you have the following values: -masking_characteris*-number_to_maskis-4-reverse_orderisfalse-CharsToIgnoreincludes-- Input string is1234-5678-9012-3456The resulting de-identified string is****-****-****-3456. Cloud DLP masks all but the last four characters. Ifreverse_orderistrue, all but the first four characters are masked as1234-****-****-****.
↳ reverse_order
bool
Mask characters in reverse order. For example, ifmasking_characteris0,number_to_maskis14, andreverse_orderisfalse, then the input string1234-5678-9012-3456is masked as00000000000000-3456. Ifmasking_characteris*,number_to_maskis3, andreverse_orderistrue, then the string12345is masked as12***.
When masking a string, items in this list will be skipped when replacing characters. For example, if the input string is555-555-5555and you instruct Cloud DLP to skip-and mask 5 characters with*, Cloud DLP returns***-**5-5555.
getMaskingCharacter
Character to use to mask the sensitive values—for example,*for an
alphabetic string such as a name, or0for a numeric string such as ZIP
code or credit card number. This string must have a length of 1. If not
supplied, this value defaults to*for strings, and0for digits.
Returns
Type
Description
string
setMaskingCharacter
Character to use to mask the sensitive values—for example,*for an
alphabetic string such as a name, or0for a numeric string such as ZIP
code or credit card number. This string must have a length of 1. If not
supplied, this value defaults to*for strings, and0for digits.
Parameter
Name
Description
var
string
Returns
Type
Description
$this
getNumberToMask
Number of characters to mask. If not set, all matching chars will be
masked. Skipped characters do not count towards this tally.
Ifnumber_to_maskis negative, this denotes inverse masking. Cloud DLP
masks all but a number of characters.
For example, suppose you have the following values:
masking_characteris*
number_to_maskis-4
reverse_orderisfalse
CharsToIgnoreincludes-
Input string is1234-5678-9012-3456The resulting de-identified string is****-****-****-3456. Cloud DLP masks all but the last four characters.
Ifreverse_orderistrue, all but the first four characters are masked
as1234-****-****-****.
Returns
Type
Description
int
setNumberToMask
Number of characters to mask. If not set, all matching chars will be
masked. Skipped characters do not count towards this tally.
Ifnumber_to_maskis negative, this denotes inverse masking. Cloud DLP
masks all but a number of characters.
For example, suppose you have the following values:
masking_characteris*
number_to_maskis-4
reverse_orderisfalse
CharsToIgnoreincludes-
Input string is1234-5678-9012-3456The resulting de-identified string is****-****-****-3456. Cloud DLP masks all but the last four characters.
Ifreverse_orderistrue, all but the first four characters are masked
as1234-****-****-****.
Parameter
Name
Description
var
int
Returns
Type
Description
$this
getReverseOrder
Mask characters in reverse order. For example, ifmasking_characteris0,number_to_maskis14, andreverse_orderisfalse, then the
input string1234-5678-9012-3456is masked as00000000000000-3456.
Ifmasking_characteris*,number_to_maskis3, andreverse_orderistrue, then the string12345is masked as12***.
Returns
Type
Description
bool
setReverseOrder
Mask characters in reverse order. For example, ifmasking_characteris0,number_to_maskis14, andreverse_orderisfalse, then the
input string1234-5678-9012-3456is masked as00000000000000-3456.
Ifmasking_characteris*,number_to_maskis3, andreverse_orderistrue, then the string12345is masked as12***.
Parameter
Name
Description
var
bool
Returns
Type
Description
$this
getCharactersToIgnore
When masking a string, items in this list will be skipped when replacing
characters. For example, if the input string is555-555-5555and you
instruct Cloud DLP to skip-and mask 5 characters with*, Cloud DLP
returns***-**5-5555.
When masking a string, items in this list will be skipped when replacing
characters. For example, if the input string is555-555-5555and you
instruct Cloud DLP to skip-and mask 5 characters with*, Cloud DLP
returns***-**5-5555.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Data Loss Prevention V2 Client - Class CharacterMaskConfig (2.6.1)\n\nVersion latestkeyboard_arrow_down\n\n- [2.6.1 (latest)](/php/docs/reference/cloud-dlp/latest/V2.CharacterMaskConfig)\n- [2.6.0](/php/docs/reference/cloud-dlp/2.6.0/V2.CharacterMaskConfig)\n- [2.4.1](/php/docs/reference/cloud-dlp/2.4.1/V2.CharacterMaskConfig)\n- [2.3.0](/php/docs/reference/cloud-dlp/2.3.0/V2.CharacterMaskConfig)\n- [2.2.3](/php/docs/reference/cloud-dlp/2.2.3/V2.CharacterMaskConfig)\n- [2.1.0](/php/docs/reference/cloud-dlp/2.1.0/V2.CharacterMaskConfig)\n- [2.0.0](/php/docs/reference/cloud-dlp/2.0.0/V2.CharacterMaskConfig)\n- [1.19.0](/php/docs/reference/cloud-dlp/1.19.0/V2.CharacterMaskConfig)\n- [1.18.0](/php/docs/reference/cloud-dlp/1.18.0/V2.CharacterMaskConfig)\n- [1.17.0](/php/docs/reference/cloud-dlp/1.17.0/V2.CharacterMaskConfig)\n- [1.16.0](/php/docs/reference/cloud-dlp/1.16.0/V2.CharacterMaskConfig)\n- [1.15.1](/php/docs/reference/cloud-dlp/1.15.1/V2.CharacterMaskConfig)\n- [1.14.0](/php/docs/reference/cloud-dlp/1.14.0/V2.CharacterMaskConfig)\n- [1.13.2](/php/docs/reference/cloud-dlp/1.13.2/V2.CharacterMaskConfig)\n- [1.12.0](/php/docs/reference/cloud-dlp/1.12.0/V2.CharacterMaskConfig)\n- [1.11.0](/php/docs/reference/cloud-dlp/1.11.0/V2.CharacterMaskConfig)\n- [1.10.2](/php/docs/reference/cloud-dlp/1.10.2/V2.CharacterMaskConfig)\n- [1.9.0](/php/docs/reference/cloud-dlp/1.9.0/V2.CharacterMaskConfig)\n- [1.8.6](/php/docs/reference/cloud-dlp/1.8.6/V2.CharacterMaskConfig) \nReference documentation and code samples for the Data Loss Prevention V2 Client class CharacterMaskConfig.\n\nPartially mask a string by replacing a given number of characters with a\nfixed character. Masking can start from the beginning or end of the string.\n\nThis can be used on data of any type (numbers, longs, and so on) and when\nde-identifying structured data we'll attempt to preserve the original data's\ntype. (This allows you to take a long like 123 and modify it to a string like\n\\*\\*3.\n\nGenerated from protobuf message `google.privacy.dlp.v2.CharacterMaskConfig`\n\nNamespace\n---------\n\nGoogle \\\\ Cloud \\\\ Dlp \\\\ V2\n\nMethods\n-------\n\n### __construct\n\nConstructor.\n\n### getMaskingCharacter\n\nCharacter to use to mask the sensitive values---for example, `*` for an\nalphabetic string such as a name, or `0` for a numeric string such as ZIP\ncode or credit card number. This string must have a length of 1. If not\nsupplied, this value defaults to `*` for strings, and `0` for digits.\n\n### setMaskingCharacter\n\nCharacter to use to mask the sensitive values---for example, `*` for an\nalphabetic string such as a name, or `0` for a numeric string such as ZIP\ncode or credit card number. This string must have a length of 1. If not\nsupplied, this value defaults to `*` for strings, and `0` for digits.\n\n### getNumberToMask\n\nNumber of characters to mask. If not set, all matching chars will be\nmasked. Skipped characters do not count towards this tally.\n\nIf `number_to_mask` is negative, this denotes inverse masking. Cloud DLP\nmasks all but a number of characters.\nFor example, suppose you have the following values:\n\n- `masking_character` is `*`\n- `number_to_mask` is `-4`\n- `reverse_order` is `false`\n- `CharsToIgnore` includes `-`\n- Input string is `1234-5678-9012-3456` The resulting de-identified string is `****-****-****-3456`. Cloud DLP masks all but the last four characters. If `reverse_order` is `true`, all but the first four characters are masked as `1234-****-****-****`.\n\n### setNumberToMask\n\nNumber of characters to mask. If not set, all matching chars will be\nmasked. Skipped characters do not count towards this tally.\n\nIf `number_to_mask` is negative, this denotes inverse masking. Cloud DLP\nmasks all but a number of characters.\nFor example, suppose you have the following values:\n\n- `masking_character` is `*`\n- `number_to_mask` is `-4`\n- `reverse_order` is `false`\n- `CharsToIgnore` includes `-`\n- Input string is `1234-5678-9012-3456` The resulting de-identified string is `****-****-****-3456`. Cloud DLP masks all but the last four characters. If `reverse_order` is `true`, all but the first four characters are masked as `1234-****-****-****`.\n\n### getReverseOrder\n\nMask characters in reverse order. For example, if `masking_character` is\n`0`, `number_to_mask` is `14`, and `reverse_order` is `false`, then the\ninput string `1234-5678-9012-3456` is masked as `00000000000000-3456`.\n\nIf `masking_character` is `*`, `number_to_mask` is `3`, and `reverse_order`\nis `true`, then the string `12345` is masked as `12***`.\n\n### setReverseOrder\n\nMask characters in reverse order. For example, if `masking_character` is\n`0`, `number_to_mask` is `14`, and `reverse_order` is `false`, then the\ninput string `1234-5678-9012-3456` is masked as `00000000000000-3456`.\n\nIf `masking_character` is `*`, `number_to_mask` is `3`, and `reverse_order`\nis `true`, then the string `12345` is masked as `12***`.\n\n### getCharactersToIgnore\n\nWhen masking a string, items in this list will be skipped when replacing\ncharacters. For example, if the input string is `555-555-5555` and you\ninstruct Cloud DLP to skip `-` and mask 5 characters with `*`, Cloud DLP\nreturns `***-**5-5555`.\n\n### setCharactersToIgnore\n\nWhen masking a string, items in this list will be skipped when replacing\ncharacters. For example, if the input string is `555-555-5555` and you\ninstruct Cloud DLP to skip `-` and mask 5 characters with `*`, Cloud DLP\nreturns `***-**5-5555`."]]