-- 创建CMK主秘钥
CREATE CLIENT MASTER KEY cmk12 WITH (
KEY_STORE = localkms,
KEY_PATH = "localkms-1" ,
ALGORITHM = SM2);
CREATE CLIENT MASTER KEY cmk2 WITH (
KEY_STORE = localkms, KEY_PATH = "localkms-1" , ALGORITHM = SM2);
-- 创建CEK数据秘钥
CREATE COLUMN ENCRYPTION KEY cek1 WITH VALUES (
CLIENT_MASTER_KEY = cmk1, ALGORITHM = SM4_SM3);
CREATE COLUMN ENCRYPTION KEY cek2 WITH VALUES (
CLIENT_MASTER_KEY = cmk2, ALGORITHM = SM4_SM3);
DROP CLIENT MASTER KEY cmk1 CASCADE;
-- 创建加密表,col1未加密,col2使用cek1加密,col3和col4使用cek2加密
CREATE TABLE IF NOT EXISTS tbl1 ( col1 INT, col2 INT ENCRYPTED WITH ( COLUMNS_ENCRYPTION_KEY = cek1, ENCRYPTION_TYPE =DETERMINISTIC), col3 TEXT ENCRYPTED WITH ( COLUMNS_ENCRYPTION_KEY = cek2, ENCRYPTION_TYPE = DETERMINISTIC), col4 VARCHAR(20) ENCRYPTED WITH ( COLUMNS_ENCRYPTION_KEY = cek2, ENCRYPTION_TYPE = DETERMINISTIC) );