CREATE ENCRYPT RULE

Description

The CREATE ENCRYPT RULE syntax is used to create encrypt rules.

Syntax

Grammar Railroad diagram

  1. CreateEncryptRule ::=
  2. 'CREATE' 'ENCRYPT' 'RULE' ifNotExists? encryptDefinition (',' encryptDefinition)*
  3. ifNotExists ::=
  4. 'IF' 'NOT' 'EXISTS'
  5. encryptDefinition ::=
  6. ruleName '(' 'COLUMNS' '(' columnDefinition (',' columnDefinition)* ')' ')'
  7. columnDefinition ::=
  8. '(' 'NAME' '=' columnName ',' 'CIPHER' '=' cipherColumnName (',' 'ASSISTED_QUERY' '=' assistedQueryColumnName)? (',' 'LIKE_QUERY' '=' likeQueryColumnName)? ',' encryptAlgorithmDefinition (',' assistedQueryAlgorithmDefinition)? (',' likeQueryAlgorithmDefinition)? ')'
  9. encryptAlgorithmDefinition ::=
  10. 'ENCRYPT_ALGORITHM' '(' 'TYPE' '(' 'NAME' '=' algorithmType (',' propertiesDefinition)? ')'
  11. assistedQueryAlgorithmDefinition ::=
  12. 'ASSISTED_QUERY_ALGORITHM' '(' 'TYPE' '(' 'NAME' '=' algorithmType (',' propertiesDefinition)? ')'
  13. likeQueryAlgorithmDefinition ::=
  14. 'LIKE_QUERY_ALGORITHM' '(' 'TYPE' '(' 'NAME' '=' algorithmType (',' propertiesDefinition)? ')'
  15. propertiesDefinition ::=
  16. 'PROPERTIES' '(' key '=' value (',' key '=' value)* ')'
  17. ruleName ::=
  18. identifier
  19. columnName ::=
  20. identifier
  21. cipherColumnName ::=
  22. identifier
  23. assistedQueryColumnName ::=
  24. identifier
  25. likeQueryColumnName ::=
  26. identifier
  27. algorithmType ::=
  28. string
  29. key ::=
  30. string
  31. value ::=
  32. literal

Supplement

  • CIPHER specifies the cipher column, ASSISTED_QUERY specifies the assisted query column,LIKE_QUERY specifies the like query column;
  • algorithmType specifies the encryption algorithm type, please refer to Encryption Algorithm;
  • Duplicate ruleName will not be created;
  • ifNotExists clause used for avoid Duplicate encrypt rule error.

Example

Create an encrypt rule

  1. CREATE ENCRYPT RULE t_encrypt (
  2. COLUMNS(
  3. (NAME=user_id,CIPHER=user_cipher,ASSISTED_QUERY=assisted_query_user,LIKE_QUERY=like_query_user,ENCRYPT_ALGORITHM(TYPE(NAME='AES',PROPERTIES('aes-key-value'='123456abc'))),ASSISTED_QUERY_ALGORITHM(TYPE(NAME='MD5')),LIKE_QUERY_ALGORITHM(TYPE(NAME='CHAR_DIGEST_LIKE'))),
  4. (NAME=order_id,CIPHER =order_cipher,ASSISTED_QUERY=assisted_query_order,LIKE_QUERY=like_query_order,ENCRYPT_ALGORITHM(TYPE(NAME='AES',PROPERTIES('aes-key-value'='123456abc'))),ASSISTED_QUERY_ALGORITHM(TYPE(NAME='MD5')),LIKE_QUERY_ALGORITHM(TYPE(NAME='CHAR_DIGEST_LIKE')))
  5. )),
  6. t_encrypt_2 (
  7. COLUMNS(
  8. (NAME=user_id,CIPHER=user_cipher,ASSISTED_QUERY=assisted_query_user,LIKE_QUERY=like_query_user,ENCRYPT_ALGORITHM(TYPE(NAME='AES',PROPERTIES('aes-key-value'='123456abc'))),ASSISTED_QUERY_ALGORITHM(TYPE(NAME='MD5')),LIKE_QUERY_ALGORITHM(TYPE(NAME='CHAR_DIGEST_LIKE'))),
  9. (NAME=order_id, CIPHER=order_cipher,ASSISTED_QUERY=assisted_query_order,LIKE_QUERY=like_query_order,ENCRYPT_ALGORITHM(TYPE(NAME='AES',PROPERTIES('aes-key-value'='123456abc'))),ASSISTED_QUERY_ALGORITHM(TYPE(NAME='MD5')),LIKE_QUERY_ALGORITHM(TYPE(NAME='CHAR_DIGEST_LIKE')))
  10. ));

Create an encrypt rule with ifNotExists clause

  1. CREATE ENCRYPT RULE IF NOT EXISTS t_encrypt (
  2. COLUMNS(
  3. (NAME=user_id,CIPHER=user_cipher,ASSISTED_QUERY=assisted_query_user,LIKE_QUERY=like_query_user,ENCRYPT_ALGORITHM(TYPE(NAME='AES',PROPERTIES('aes-key-value'='123456abc'))),ASSISTED_QUERY_ALGORITHM(TYPE(NAME='MD5')),LIKE_QUERY_ALGORITHM(TYPE(NAME='CHAR_DIGEST_LIKE'))),
  4. (NAME=order_id,CIPHER =order_cipher,ASSISTED_QUERY=assisted_query_order,LIKE_QUERY=like_query_order,ENCRYPT_ALGORITHM(TYPE(NAME='AES',PROPERTIES('aes-key-value'='123456abc'))),ASSISTED_QUERY_ALGORITHM(TYPE(NAME='MD5')),LIKE_QUERY_ALGORITHM(TYPE(NAME='CHAR_DIGEST_LIKE')))
  5. )),
  6. t_encrypt_2 (
  7. COLUMNS(
  8. (NAME=user_id,CIPHER=user_cipher,ASSISTED_QUERY=assisted_query_user,LIKE_QUERY=like_query_user,ENCRYPT_ALGORITHM(TYPE(NAME='AES',PROPERTIES('aes-key-value'='123456abc'))),ASSISTED_QUERY_ALGORITHM(TYPE(NAME='MD5')),LIKE_QUERY_ALGORITHM(TYPE(NAME='CHAR_DIGEST_LIKE'))),
  9. (NAME=order_id,CIPHER=order_cipher,ASSISTED_QUERY=assisted_query_order,LIKE_QUERY=like_query_order,ENCRYPT_ALGORITHM(TYPE(NAME='AES',PROPERTIES('aes-key-value'='123456abc'))),ASSISTED_QUERY_ALGORITHM(TYPE(NAME='MD5')),LIKE_QUERY_ALGORITHM(TYPE(NAME='CHAR_DIGEST_LIKE')))
  10. ));

Reserved words

CREATE, ENCRYPT, RULE, COLUMNS, NAME, CIPHER, ASSISTED_QUERY, LIKE_QUERY, ENCRYPT_ALGORITHM, ASSISTED_QUERY_ALGORITHM, LIKE_QUERY_ALGORITHM, TYPE, TRUE, FALSE