generateDataKey
KMSClient.generateDataKey
生成一个对称数据密钥,用于 AWS Key Management Service 之外的使用。
参数
名称 | 类型 | 描述 |
---|---|---|
id | string | 密钥的标识符。可以是密钥 ID 或密钥的 Amazon Resource Name (ARN)。 |
size | number | 数据密钥的长度。例如,使用值 64 生成 512 位数据密钥(64 字节即 512 位)。对于 256 位(32 字节)数据密钥,请使用值 32。 |
返回值
类型 | 描述 |
---|---|
Promise< KMSDataKey> | 一个 Promise,成功时返回 KMSDataKey 对象。 |
示例
import exec from 'k6/execution';
import {
AWSConfig,
KMSClient,
} from 'https://jslib.k6.io/aws/0.13.0/kms.js';
const awsConfig = new AWSConfig({
region: __ENV.AWS_REGION,
accessKeyId: __ENV.AWS_ACCESS_KEY_ID,
secretAccessKey: __ENV.AWS_SECRET_ACCESS_KEY,
});
const kms = new KMSClient(awsConfig);
const testKeyId = 'e67f95-4c047567-4-a0b7-62f7ce8ec8f48';
export default async function () {
// List the KMS keys the AWS authentication configuration
// gives us access to.
const keys = await kms.listKeys();
// If our test key does not exist, abort the execution.
if (keys.filter((b) => b.keyId === testKeyId).length == 0) {
exec.test.abort();
}
// Generate a data key from the KMS key.
const key = await kms.generateDataKey(testKeyId, 32);
}
一个 k6 脚本,用于从 AWS Key Management Service 密钥生成数据密钥