Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

CREATE CLIENT MASTER KEY

Updated on 2023-10-23 GMT+08:00

Function

CREATE CLIENT MASTER KEY creates a CMK object that can be used to encrypt a CEK object.

Precautions

This syntax is specific to a fully-encrypted database.

When using gsql to connect to a database server, you need to use the -C parameter to enable the fully-encrypted database.

In the CMK object created using this syntax, only the method for reading keys from independent key management tools, services, or components is stored. The key itself is not stored.

Syntax

CREATE CLIENT MASTER KEY client_master_key_name WITH (KEY_STORE = key_store_name, KEY_PATH = "key_path_value", ALGORITHM = algorithm_type)

Parameter Description

  • client_master_key_name

    Specifies the key name. In the same namespace, the value of this parameter must be unique.

    Value range: a string. It must comply with the identifier naming convention.

  • KEY_STORE
    Specifies the tool or service that independently manages keys. Currently, only the key management tool gs_ktool provided by GaussDB and the online key management service huawei_kms provided by Huawei Cloud are supported. Value range: gs_ktool and huawei_kms
    NOTICE:

    Because only the client interacts with the KEY_STORE, the types supported by the KEY_STORE parameter in this syntax vary according to the client. When gsql is used to execute this syntax, KEY_STORE supports only gs_ktool. When JDBC is used to execute this syntax, KEY_STORE supports only huawei_kms.

  • KEY_PATH
    Specifies a key in the key management tool or service. The KEY_STORE and KEY_PATH parameters can be used to uniquely identify a key entity. When KEY_STORE is set to gs_ktool, the value of KEY_PATH is gs_ktool or KEY_ID. When KEY_STORE is set to huawei_kms, the value is a 36-byte key ID.
    NOTE:

    The CMK object created by this syntax stores the KEY_STORE and KEY_PATH information. When the key entity needs to be read, GaussDB can automatically read the specified key entity from the specified KEY_STORE based on the information stored in the CMK object. Therefore, in this syntax, the KEY_PATH parameter should point to an existing key entity.

  • ALGORITHM

    Specifies the encryption algorithm used by the key entity. When KEY_STORE is set to gs_ktool, the value of ALGORITHM can be AES_256_CBC or SM4. When KEY_STORE is set to huawei_kms, the value of ALGORITHM is AES_256.

Example (Using gsql to Connect to the Database Server)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
-- (1) Use the key management tool gs_ktool to create a key. The tool returns the ID of the newly generated key.
[cmd] gs_ktool -g

-- (2) Use a privileged account to create a common user named alice.
openGauss=# CREATE USER alice PASSWORD '********';
-- (3) Use the account of common user alice to connect to the encrypted database and execute the syntax.
gsql -p 57101 postgres -U alice -r -C
gsql((GaussDB Kernel VxxxRxxxCxx build f521c606) compiled at 2021-09-16 14:55:22 commit 2935 last mr 6385 release)
Non-SSL connection (SSL connection is recommended when requiring high-security)
Type "help" for help.

openGauss=>

-- Create a CMK object.
openGauss=> CREATE CLIENT MASTER KEY alice_cmk WITH ( KEY_STORE = gs_ktool , KEY_PATH = "gs_ktool/1" , ALGORITHM = AES_256_CBC);

Example (Using JDBC to Connect to the Database Server)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* 
 * (1) Log in to the Huawei Cloud official website (https://www.huaweicloud.com), choose Console > Service List > Data Encryption Workshop > Key Management Service, and create a key.
 *     KMS is a key management service provided by Huawei Cloud. You can also use APIs to manage keys. For details, see the following public document of Huawei Cloud:
 *    (https://support.huaweicloud.com/dew_faq/dew_01_0053.html)
 */

/* 
 * (2) Establish a connection to the database server and execute the syntax. In the URL, set enable_ce to 1.
 *      Note: The code in this section is used as an example. Consider using the minimum code to implement the most basic functions.
 */
import java.sql.*;

public class CrtCmkTest {
    public static void main(String[] args) {
        String driver = "org.postgresql.Driver";
        try {
            Class.forName(driver);
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }

        /* Information used to establish a connection to the database server */
        String dbUrl = "jdbc:postgresql://localhost:19900/postgres?enable_ce=1";
        String dbUser = "alice";
        String dbPassword = "********";

       /* 
        * Used to access the identity authentication information of Huawei Cloud KMS and KMS project information
        * Note: All parameters in this part can be found on the Console > My Credential page of the Huawei Cloud official website.
        */
        String iamUser = "alice_for_kms";
        String iamPassword = "********";
        String kmsDomain = "hw00000000";
        String kmsProjectName = "cn-east-3";
        String kmsProjectId = "00000000000000000000000000000000";

        /* SQL statement for creating a CMK object */
        String sql = "CREATE CLIENT MASTER KEY alice_cmk WITH ( " + 
         "KEY_STORE = huawei_kms, KEY_PATH = \"00000000-0000-0000-0000-000000000000\" , ALGORITHM = AES_256);";

        try {
            Connection conn = DriverManager.getConnection(dbUrl, dbUser, dbPassword);
            conn.setClientInfo("iamUser", iamUser);
            conn.setClientInfo("iamPassword", iamPassword);
            conn.setClientInfo("kmsDomain", kmsDomain);
            conn.setClientInfo("kmsProjectName", kmsProjectName);
            conn.setClientInfo("kmsProjectId", kmsProjectId );
            Statement stmt = conn.createStatement();
            System.out.println("results: " + stmt.executeUpdate(sql));
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback