PHP code example of alibabacloud / dkms-gcs-sdk

1. Go to this page and download the library: Download alibabacloud/dkms-gcs-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alibabacloud / dkms-gcs-sdk example snippets






libabaCloud\Dkms\Gcs\OpenApi\Util\Models\RuntimeOptions;
use AlibabaCloud\Dkms\Gcs\Sdk\Client as AlibabaCloudDkmsGcsSdkClient;
use AlibabaCloud\Dkms\Gcs\OpenApi\Models\Config as AlibabaCloudDkmsGcsOpenApiConfig;
use AlibabaCloud\Dkms\Gcs\Sdk\Models\AdvanceEncryptRequest;
use AlibabaCloud\Tea\Utils\Utils as AlibabaCloudTeaUtils;

// 1.Create DKMS SDK client config
$config = new AlibabaCloudDkmsGcsOpenApiConfig();
$config->protocol = 'https';
$config->clientKeyContent = '<your client key content>';
$config->password = '<your client key password>';
$config->endpoint = '<your dkms instance service address>';

// 2.Create DKMS SDK client instance
$client = new AlibabaCloudDkmsGcsSdkClient($config);

// 3.Create and set up parameters RuntimeOptions instance
$runtimeOptions = new RuntimeOptions();
// set CA certificate
//$runtimeOptions->verify = 'path/to/caCert.pem';
// or, ignore certificate
$runtimeOptions->ignoreSSL = true;

// 4.Create an API request and set parameters
$encryptRequest = new AdvanceEncryptRequest();
$encryptRequest->keyId = '<your cmk id>';
$encryptRequest->plaintext = AlibabaCloudTeaUtils::toBytes('encrypt plaintext');

// 5.Initiate the request and handle the response or exceptions
try {
    $encryptResponse = $client->advanceEncryptWithOptions($encryptRequest, $runtimeOptions);
    var_dump($encryptResponse->toMap());
} catch (Exception $error) {
    if ($error instanceof \AlibabaCloud\Tea\Exception\TeaError) {
        var_dump($error->getErrorInfo());
    }
    var_dump($error->getMessage());
    var_dump($error->getTraceAsString());
}