CREATE ENCRYPT RULE

描述

CREATE ENCRYPT RULE 语法用于创建数据加密规则

语法定义

语法 铁路图

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

补充说明

  • PLAIN 指定明文数据列,CIPHER 指定密文数据列,ASSISTED_QUERY_COLUMN 指定辅助查询列,LIKE_QUERY_COLUMN 指定模糊查询列;
  • encryptAlgorithmType 指定加密算法类型,请参考 加密算法
  • 重复的 ruleName 将无法被创建;
  • ifNotExists 子句用于避免出现 Duplicate encrypt rule 错误。

示例

创建数据加密规则

  1. CREATE ENCRYPT RULE t_encrypt (
  2. COLUMNS(
  3. (NAME=user_id,PLAIN=user_plain,CIPHER=user_cipher,ENCRYPT_ALGORITHM(TYPE(NAME='AES',PROPERTIES('aes-key-value'='123456abc')))),
  4. (NAME=order_id, CIPHER =order_cipher,ENCRYPT_ALGORITHM(TYPE(NAME='MD5')))
  5. ),QUERY_WITH_CIPHER_COLUMN=true),
  6. t_encrypt_2 (
  7. COLUMNS(
  8. (NAME=user_id,PLAIN=user_plain,CIPHER=user_cipher,ENCRYPT_ALGORITHM(TYPE(NAME='AES',PROPERTIES('aes-key-value'='123456abc')))),
  9. (NAME=order_id, CIPHER=order_cipher,ENCRYPT_ALGORITHM(TYPE(NAME='MD5')))
  10. ), QUERY_WITH_CIPHER_COLUMN=FALSE);

使用 ifNotExists 子句创建数据加密规则

  1. CREATE ENCRYPT RULE IF NOT EXISTS t_encrypt (
  2. COLUMNS(
  3. (NAME=user_id,PLAIN=user_plain,CIPHER=user_cipher,ENCRYPT_ALGORITHM(TYPE(NAME='AES',PROPERTIES('aes-key-value'='123456abc')))),
  4. (NAME=order_id, CIPHER =order_cipher,ENCRYPT_ALGORITHM(TYPE(NAME='MD5')))
  5. ),QUERY_WITH_CIPHER_COLUMN=true),
  6. t_encrypt_2 (
  7. COLUMNS(
  8. (NAME=user_id,PLAIN=user_plain,CIPHER=user_cipher,ENCRYPT_ALGORITHM(TYPE(NAME='AES',PROPERTIES('aes-key-value'='123456abc')))),
  9. (NAME=order_id, CIPHER=order_cipher,ENCRYPT_ALGORITHM(TYPE(NAME='MD5')))
  10. ), QUERY_WITH_CIPHER_COLUMN=FALSE);

保留字

CREATEENCRYPTRULECOLUMNSNAMECIPHERPLAINENCRYPT_ALGORITHMQUERY_WITH_CIPHER_COLUMNTYPETRUEFALSE

相关链接