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

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: ~,!,@,#,$,%,^,&,*,:,<,>,¦)

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: '*'