You can integrate the Key Management Service (KMS) instance SDK to perform cryptographic operations and obtain secret values using keys. This topic describes how to install the KMS instance SDK (PHP).
Network environment description
Ensure the application's runtime environment has network access to the KMS instance VPC address <KMS_INSTANCE_ID>.cryptoservice.kms.aliyuncs.com.
If the application's runtime environment and the KMS instance are in the same region and VPC, they are connected by default with no additional configuration required.
If the application runtime environment and the KMS instance are located in the same region but within different VPCs, you must associate the VPC of the application with the KMS instance. For instructions, see how to access the KMS instance from multiple VPCs in the same region.
If the application's runtime environment is within a local IDC, refer to this guide for configuring network connectivity to ensure access to the KMS instance without using Domain Names.
Prerequisites
A KMS instance is purchased and enabled. For more information, see Purchase and enable a KMS instance.
A key and a secret are created. For more information, see Software-protected keys, Hardware-protected keys, and Create a secret.
NoteIf your business does not require a secret, you do not need to create one.
Install the SDK
Method 1 (Recommended): Use Composer to manage dependencies
Install the AlibabaCloud DKMS-GCS SDK for PHP as a dependency using one of the methods below:
Run
composer require alibabacloud/dkms-gcs-sdkin your project's root directory.Add the dependency to your
composer.jsonfile.Replace
SDK_VERSIONwith the specific version number. We recommend using the latest version of the SDK. For version details, see the open-source repository."require": { "alibabacloud/dkms-gcs-sdk": "SDK_VERSION" }
Run
composer installin the project's root directory to install the dependency.Include the dependency in your PHP code.
require_once __DIR__ . '/vendor/autoload.php';
Method 2: Download the SDK source code directly
Access the open-source repository to download the SDK's source code and include the
autoload.phpfrom the SDK directory in your PHP code.require_once '/path/to/dkms-gcs-sdk/autoload.php';