English | 简体中文
Alibaba Cloud KMS SDK for PHP Supports PHP developers using Alibaba Cloud Key Management Service (KMS).
Your system will need to meet the Prerequisites, including having PHP >= 5.5. We highly recommend having it compiled with the cURL extension and cURL 7.16.2+.
If Composer is already installed globally on your system, run the following in the base directory of your project to install Alibaba Cloud KMS SDK for PHP as a dependency:
composer require alibabacloud/kms
Some users may not be able to install due to network problems, you can try to switch the Composer mirror.
Please see the Installation for more detailed information about installing through Composer and other means.
Before you begin, you need to sign up for an Alibaba Cloud account and retrieve your Credentials.
Please pass in your accessKeyId
, accessKeySecret
, endpoint
, View the list of KMS endpoints.
<?php
use AlibabaCloud\Kms\V20160120\Kms;
$client = new Kms('accessKeyId', 'accessKeySecret', 'kms.cn-hangzhou.aliyuncs.com');
Please refer to Guzzle Request Options.
<?php
$options = [];
Cancels the deletion of a CMK. When this operation is successful, the CMK is set to the Enabled state. API Reference
<?php
use GuzzleHttp\Exception\GuzzleException;
try {
$result = $client->cancelKeyDeletion(
[
'KeyId' => 'key_id',
],
$options
);
} catch (GuzzleException $e) {
echo $e->getMessage();
}
Creates a display name for a CMK. API Reference
<?php
use GuzzleHttp\Exception\GuzzleException;
try {
$result = $client->createAlias(
[
'AliasName' => 'alias/1234',
'KeyId' => 'key_id',
]
);
} catch (GuzzleException $e) {
echo $e->getMessage();
}
Creates a customer master key (CMK). API Reference
<?php
use GuzzleHttp\Exception\GuzzleException;
try {
$result = $client->createKey(
[
'Origin' => 'Aliyun_KMS',
'Description' => 'test key',
'KeyUsage' => 'ENCRYPT/DECRYPT',
],
$options
);
} catch (GuzzleException $e) {
echo $e->getMessage();
}
Decrypts ciphertext. Ciphertext is plaintext that has been previously encrypted by using any of the following operations. API Reference
<?php
use GuzzleHttp\Exception\GuzzleException;
try {
$result = $client->decrypt(
[
'CiphertextBlob' => 'CiphertextBlob',
'EncryptionContext' => json_encode(['k' => 'v']),
],
$options
);
} catch (GuzzleException $e) {
echo $e->getMessage();
}
Deletes the specified alias. API Reference
<?php
use GuzzleHttp\Exception\GuzzleException;
try {
$result = $client->deleteAlias(
[
'AliasName' => 'alias/12345',
],
$options
);
} catch (GuzzleException $e) {
echo $e->getMessage();
}
Deletes the imported key material. API Reference
<?php
use GuzzleHttp\Exception\GuzzleException;
try {
$result = $client->deleteKeyMaterial(
[
'KeyId' => 'id',
],
$options
);
} catch (GuzzleException $e) {
echo $e->getMessage();
}
Returns detailed information about the specified CMK. API Reference
<?php
use GuzzleHttp\Exception\GuzzleException;
try {
$result = $client->describeKey(
[
'KeyId' => 'id',
],
$options
);
} catch (GuzzleException $e) {
echo $e->getMessage();
}
Returns available regions for the specified account. API Reference
<?php
use GuzzleHttp\Exception\GuzzleException;
try {
$result = $client->describeRegions();
} catch (GuzzleException $e) {
echo $e->getMessage();
}
Sets the state of a CMK to disabled, thereby preventing its use for cryptographic operations. The ciphertext encrypted using the CMK cannot be decrypted until the CMK is enabled again. API Reference
<?php
use GuzzleHttp\Exception\GuzzleException;
try {
$result = $client->disableKey(
[
'KeyId' => 'id',
],
$options
);
} catch (GuzzleException $e) {
echo $e->getMessage();
}
Sets the state of the specified CMK to Enabled, thereby permitting its use for cryptographic operations. API Reference
<?php
use GuzzleHttp\Exception\GuzzleException;
try {
$result = $client->enableKey(
[
'KeyId' => 'id',
],
$options
);
} catch (GuzzleException $e) {
echo $e->getMessage();
}
Encrypts plaintext into ciphertext by using a CMK. API Reference
<?php
use GuzzleHttp\Exception\GuzzleException;
try {
$result = $client->encrypt(
[
'KeyId' => 'id',
'Plaintext' => 'text',
'EncryptionContext' => json_encode(['k' => 'v']),
],
$options
);
} catch (GuzzleException $e) {
echo $e->getMessage();
}
Returns a data encryption key that you can use in your application to encrypt data locally. API Reference
<?php
use GuzzleHttp\Exception\GuzzleException;
try {
$result = $client->generateDataKey(
[
'KeyId' => 'id',
],
$options
);
} catch (GuzzleException $e) {
echo $e->getMessage();
}
Returns the items you need in order to import key material into KMS from your existing key management infrastructure. The returned items are used in the subsequent ImportKeyMaterial request. API Reference
<?php
use GuzzleHttp\Exception\GuzzleException;
try {
$result = $client->getParametersForImport(
[
'KeyId' => 'external_key_id',
'WrappingAlgorithm' => 'RSAES_OAEP_SHA_256',
'WrappingKeySpec' => 'RSA_2048',
],
$options
);
} catch (GuzzleException $e) {
echo $e->getMessage();
}
Imports key material to an existing KMS CMK that was created without key material. API Reference
<?php
use GuzzleHttp\Exception\GuzzleException;
try {
$result = $client->importKeyMaterial(
[
'KeyId' => 'external_key_id',
'EncryptedKeyMaterial' => base64_encode('test'),
'ImportToken' => 'import_token',
'KeyMaterialExpireUnix' => time() + 3600,
],
$options
);
} catch (GuzzleException $e) {
echo $e->getMessage();
}
Gets a list of all aliases in the caller’s account and region. API Reference
<?php
use GuzzleHttp\Exception\GuzzleException;
try {
$result = $client->listAliases(
[
'PageNumber' => 1,
'PageSize' => 100,
],
$options
);
} catch (GuzzleException $e) {
echo $e->getMessage();
}
Lists all aliases associated with the CMK. API Reference
<?php
use GuzzleHttp\Exception\GuzzleException;
try {
$result = $client->listAliasesByKeyId(
[
'KeyId' => 'key_id',
'PageNumber' => 1,
'PageSize' => 100,
],
$options
);
} catch (GuzzleException $e) {
echo $e->getMessage();
}
Returns a list of all CMKs in the caller’s account and region. API Reference
<?php
use GuzzleHttp\Exception\GuzzleException;
try {
$result = $client->listKeys(
[
'PageNumber' => 1,
'PageSize' => 100,
],
$options
);
} catch (GuzzleException $e) {
echo $e->getMessage();
}
Schedules the deletion of a CMK. API Reference
<?php
use GuzzleHttp\Exception\GuzzleException;
try {
$result = $client->scheduleKeyDeletion(
[
'KeyId' => 'key_id',
'PendingWindowInDays' => 7,
],
$options
);
} catch (GuzzleException $e) {
echo $e->getMessage();
}
Associates an existing alias with a different CMK. API Reference
<?php
use GuzzleHttp\Exception\GuzzleException;
try {
$result = $client->updateAlias(
[
'KeyId' => 'key_id',
'AliasName' => 'alias/12345',
],
$options
);
} catch (GuzzleException $e) {
echo $e->getMessage();
}
Opening an Issue, Issues not conforming to the guidelines may be closed immediately.
Detailed changes for each release are documented in the release notes.
Please make sure to read the Contributing Guide before making a pull request.
Copyright 1999-2019 Alibaba Group Holding Ltd.