Data Masking Algorithm

Background

Data masking algorithms are by the mask features of Apache ShardingSphere. A variety of algorithms are built-in to make it easy for users to fully leverage the feature.

Parameters

Hash Data Masking Algorithm

MD5 Data Masking Algorithm

Type: MD5

Attributes:

NameDataTypeDescription
saltStringSalt value (optional)

Mask Data Masking Algorithm

Keep First N Last M Data Masking Algorithm

Type: KEEP_FIRST_N_LAST_M

Attributes:

NameDataTypeDescription
first-nintfirst n substring
last-mintlast m substring
replace-charStringreplace char

Keep From X To Y Data Masking Algorithm

Type: KEEP_FROM_X_TO_Y

Attributes:

NameDataTypeDescription
from-xintstart position (from 0)
to-yintend position (from 0)
replace-charStringreplace char

Mask First N Last M Data Masking Algorithm

Type: MASK_FIRST_N_LAST_M

Attributes:

NameDataTypeDescription
first-nintfirst n substring
last-mintlast m substring
replace-charStringreplace char

Mask From X To Y Data Masking Algorithm

Type: MASK_FROM_X_TO_Y

Attributes:

NameDataTypeDescription
from-xintstart position (from 0)
to-yintend position (from 0)
replace-charStringreplace char

Mask Before Special Chars Data Masking Algorithm

Type: MASK_BEFORE_SPECIAL_CHARS

Attributes:

NameDataTypeDescription
special-charsStringSpecial chars (first appearance)
replace-charStringreplace char

Mask After Special Chars Data Masking Algorithm

Type: MASK_AFTER_SPECIAL_CHARS

Attributes:

NameDataTypeDescription
special-charsStringSpecial chars (first appearance)
replace-charStringreplace char

Replace Data Masking Algorithm

Personal Identity Number Random Replace Data Masking Algorithm

Type: PERSONAL_IDENTITY_NUMBER_RANDOM_REPLACE

Attributes:

NameDataTypeDescription
alpha-two-country-area-codeStringalpha two country area code (Optional, default value: CN)

Military Identity Number Random Replace Data Masking Algorithm

类型:MILITARY_IDENTITY_NUMBER_RANDOM_REPLACE

可配置属性:

NameDataTypeDescription
type-codesStringmilitary identity number type codes (separate with comma)

Telephone Random Replace Data Masking Algorithm

Type: TELEPHONE_RANDOM_REPLACE

Attributes:

NameDataTypeDescription
network-numbersStringNetwork numbers (separate with comma, default value: 130,131,132,133,134,135,136,137,138,139,150,151,152,153,155,156,157,158,159,166,170,176,177,178,180,181,182,183,184,185,186,187,188,189,191,198,199)

Landline Number Random Replace Data Masking Algorithm

Type: LANDLINE_NUMBER_RANDOM_REPLACE

Attributes:

NameDataTypeDescription
landline-numbersStringLandline numbers (separate with comma)

Generic table random replace algorithm.

Type: GENERIC_TABLE_RANDOM_REPLACE

Attributes:

NameDataTypeDescription
uppercase-letter-codesStringUppercase letter codes (separate with comma, default value: A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z)
lowercase-letter-codesStringLowercase-letter codes (separate with comma, default value: a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z)
digital-random-codesStringNumbers (separate with comma, default value: 0,1,2,3,4,5,6,7,8,9)
special-codesStringSpecial codes (separate with comma, default value: ~,!,@,#,$,%,^,&,*,:,<,>,¦)

Unified credit code random replace algorithm

Type: UNIFIED_CREDIT_CODE_RANDOM_REPLACE

Attributes:

NameDataTypeDescription
registration-department-codesStringRegistration department code (separate with comma)
category-codesStringCategory code (separate with comma)
administrative-division-codesStringAdministrative division code (separate with comma)

Operating Procedure

  1. Configure maskAlgorithms in a mask rule.
  2. Use relevant algorithm types in maskAlgorithms.

Configuration Examples

  1. rules:
  2. - !MASK
  3. tables:
  4. t_user:
  5. columns:
  6. password:
  7. maskAlgorithm: md5_mask
  8. email:
  9. maskAlgorithm: mask_before_special_chars_mask
  10. telephone:
  11. maskAlgorithm: keep_first_n_last_m_mask
  12. maskAlgorithms:
  13. md5_mask:
  14. type: MD5
  15. mask_before_special_chars_mask:
  16. type: MASK_BEFORE_SPECIAL_CHARS
  17. props:
  18. special-chars: '@'
  19. replace-char: '*'
  20. keep_first_n_last_m_mask:
  21. type: KEEP_FIRST_N_LAST_M
  22. props:
  23. first-n: 3
  24. last-m: 4
  25. replace-char: '*'