This topic describes some common questions about column encryption.
What is the data type of a column that is inserted into a non-encrypted column by using an INSERT INTO ... SELECT ... statement?
- If the user who executes the
INSERT INTO ... SELECT ...statement has the permission to access the plaintext data, the data is inserted as plaintext. The data is returned as plaintext during queries (unless an encryption rule is applied to the table). - If the user who executes the
INSERT INTO ... SELECT ...statement does not have the permission to access the plaintext data, the statement cannot be executed.
Is a column that is renamed after encryption still protected by the encryption rule?
The encryption rule is applied to the column regardless of the column name. Even if the column name is changed, the column is still protected by the encryption rule.
What is the data type of a column that is returned in a query, such as SELECT CAST(id AS CHAR), name, password FROM test_01;?
If the query includes a projection column that contains encrypted data, the entire projection column is returned as encrypted data.
How to set the value of a non-encrypted column from an encrypted column
When you set the value of a non-encrypted column from an encrypted column, such as in the UPDATE test_01 SET age = id + 2; statement, if the user who executes the statement has the permission to access the plaintext data, the value of the non-encrypted column is processed as plaintext. Otherwise, the statement cannot be executed.
What is the result of a calculation between an encrypted column and a plaintext column?
If you calculate the result of an encrypted column and a plaintext column, such as in the SELECT CONCAT(id, name) FROM test_01; statement, the result is returned as encrypted data.
When querying an encrypted column, should I use plaintext or ciphertext in the WHERE condition?
Filter conditions use plaintext. Whether a protected column is returned as ciphertext in the query result depends on the user's plaintext access permission, but query conditions are still matched against plaintext. For example, if a user does not have plaintext access permission for the rule that protects the phone column, the phone column in the SELECT result is ciphertext, but WHERE phone = '13800000000' can still retrieve the target row.
If a rule is disabled, does a query by a user without plaintext access permission return plaintext or ciphertext for a protected column?
Plaintext. ALTER SENSITIVE RULE ... DISABLE only suspends the rule; it does not delete it. While the rule is disabled, it no longer takes effect, so a query on a protected column returns plaintext even without plaintext access permission. After you execute ALTER SENSITIVE RULE ... ENABLE, the rule takes effect again. Disabling a rule exposes protected columns as plaintext, so evaluate the security impact before you proceed.
Will ALTER SENSITIVE RULE ... DROP COLUMN delete a column from the table?
No. This operation only removes the specified column from the protection scope of the rule. The column and its data remain unchanged in the table. After removal, the column returns plaintext as a regular column, and the encryption behavior of other protected columns in the same rule is not affected.
How does backup and restore affect column encryption rules?
When you perform a tenant-level backup and restore, the column encryption rules are restored. However, during a table-level restore, the restored objects are independent of the source table. Therefore, the column encryption rules and permissions of the source table cannot be inherited. If the source table contains column encryption rules, we recommend that you evaluate whether to add access control to the data restored by using the table-level restore.
How is the IV string generated?
When you use an ENCRYPTION rule, if the encryption algorithm requires an initialization vector (IV) string, the database generates a random IV string during encryption. Each column (projection column, not data column) uses a different random IV string. You cannot explicitly specify a fixed IV string.