- Create a symmetric key if you need to encrypt and decrypt data with the same key material or generate data keys for envelope encryption.
- Create an asymmetric key if you need a public-private key pair.
Prerequisites
- Web console
- CLI
- Terraform
- Go SDK
- Python SDK
- JavaScript SDK
Make sure you are in a group that has at least the
editor role within your tenant or project; for example, the default editors group. You can check this in the Administration → IAM section of the web console.- Install and configure the Nebius AI Cloud CLI.
- Make sure you are in a group that has at least the
editorrole within your tenant or project; for example, the defaulteditorsgroup. You can check this in the Administration → IAM section of the web console.
- Install and configure the Nebius AI Cloud provider for Terraform.
- Make sure you are in a group that has at least the
editorrole within your tenant or project; for example, the defaulteditorsgroup. You can check this in the Administration → IAM section of the web console.
- Install and initialize the Nebius SDK for Go.
- Make sure you are in a group that has at least the
editorrole within your tenant or project; for example, the defaulteditorsgroup. You can check this in the Administration → IAM section of the web console.
- Install and initialize the Nebius SDK for Python.
- Make sure you are in a group that has at least the
editorrole within your tenant or project; for example, the defaulteditorsgroup. You can check this in the Administration → IAM section of the web console.
- Install and initialize the Nebius SDK for JavaScript.
- Make sure you are in a group that has at least the
editorrole within your tenant or project; for example, the defaulteditorsgroup. You can check this in the Administration → IAM section of the web console.
How to create a symmetric key
- Web console
- CLI
- Terraform
- Go SDK
- Python SDK
- JavaScript SDK
-
In the web console, go to
Cryptography → KMS.
-
Click
Create key.
- Specify a unique key name.
- In the Type field, select Symmetric key.
- (Optional) In Rotation period, set how often KMS should automatically rotate the key material. When a key is rotated, KMS generates a new key version and immediately sets it as the default version. You can set the rotation period in days, months or years. The Algorithm value is set automatically to AES-256-GCM.
- (Optional) Add a description.
- Click Create key.
Create a symmetric key:The command contains the following parameters:
nebius kms symmetric-key create \
--name <key_name> \
--description "<key_description>" \
--algorithm aes_256 \
--rotation-period <period>
-
--name: Name of the key. -
--description(optional): Description of the key. -
--algorithm: Key encryption algorithm. You can only specify the algorithm when you create a key. You can’t update it later. The only supported value isaes_256. -
--rotation-period(optional): Period after which KMS automatically rotates the key material. When a key is rotated, KMS generates a new key version and immediately sets it as the default version. Specify the value in theNhNmNsformat, for example,24hor48h30m10s. The minimum value is86400s(one day) and the maximum value is315360000s(3650 days). The default value is7776000s(90 days).
-
Create the following configuration file:
In the configuration, specify:
resource "nebius_kms_v1_symmetric_key" "my_symmetric_key" { name = "<key_name>" description = "<key_description>" parent_id = "<project_ID>" algorithm = "AES_256" rotation_period = "<period>" }-
name: Name of the key. -
description(optional): Description of the key. -
parent_id: Project ID. -
algorithm: Key encryption algorithm. You can only specify the algorithm when you create a key. You can’t update it later. The only supported value isAES_256. -
rotation_period(optional): Period after which KMS automatically rotates the key material. When a key is rotated, KMS generates a new key version and immediately sets it as the default version. Specify the value in theNhNmNsformat, for example,24hor48h30m10s. The minimum value is86400s(one day) and the maximum value is315360000s(3650 days). The default value is7776000s(90 days).
-
-
Check that the configuration is correct:
terraform validate -
Apply the changes:
terraform apply
Create a symmetric key:In the code, specify:
symCreatePeriod, err := time.ParseDuration(
"<period>",
)
if err != nil {
return fmt.Errorf("parse rotation period: %w", err)
}
symCreateService := sdk.Services().KMS().V1().
SymmetricKey()
symCreateOperation, err := symCreateService.Create(
ctx,
&kms.CreateSymmetricKeyRequest{
Metadata: &common.ResourceMetadata{
Name: "<key_name>",
},
Spec: &kms.SymmetricKeySpec{
Description: "<key_description>",
Algorithm: kms.SymmetricAlgorithm_AES_256,
RotationPeriod: durationpb.New(symCreatePeriod),
},
},
)
if err != nil {
return fmt.Errorf("create symmetric key: %w", err)
}
symCreateOperation, err = symCreateOperation.Wait(ctx)
if err != nil {
return fmt.Errorf("wait for operation: %w", err)
}
symCreateResult, err := symCreateService.Get(
ctx,
&kms.GetSymmetricKeyRequest{
Id: symCreateOperation.ResourceID(),
},
)
if err != nil {
return fmt.Errorf("get key: %w", err)
}
fmt.Println(symCreateResult)
-
Metadata.Name: Name of the key. -
Spec.Description(optional): Description of the key. -
Spec.Algorithm: Key encryption algorithm. You can only specify the algorithm when you create a key. You can’t update it later. The only supported value iskms.SymmetricAlgorithm_AES_256. -
Spec.RotationPeriod(optional): Period after which KMS automatically rotates the key material. The code parses the<period>value withtime.ParseDuration. To use the default period, remove thetime.ParseDurationcall and theRotationPeriodline. When a key is rotated, KMS generates a new key version and immediately sets it as the default version. Specify the value in theNhNmNsformat, for example,24hor48h30m10s. The minimum value is86400s(one day) and the maximum value is315360000s(3650 days). The default value is7776000s(90 days).
Create a symmetric key:In the code, specify:
service = kms.SymmetricKeyServiceClient(sdk)
operation = await service.create(
kms.CreateSymmetricKeyRequest(
metadata=ResourceMetadata(name="<key_name>"),
spec=kms.SymmetricKeySpec(
description="<key_description>",
algorithm=kms.SymmetricAlgorithm.AES_256,
rotation_period=timedelta(hours=720),
),
),
)
await operation.wait()
result = await service.get(
kms.GetSymmetricKeyRequest(id=operation.resource_id),
)
print(result)
metadata.name: Name of the key.spec.description(optional): Description of the key.spec.algorithm: Key encryption algorithm. You can only specify the algorithm when you create a key. You can’t update it later. The only supported value iskms.SymmetricAlgorithm.AES_256.spec.rotation_period(optional): Period, as atimedelta, after which KMS automatically rotates the key material. The example sets 720 hours. When a key is rotated, KMS generates a new key version and immediately sets it as the default version. The minimum value is one day and the maximum value is 3650 days. The default value is 90 days.
Create a symmetric key:In the code, specify:
const symCreateService = new kms.SymmetricKeyService(sdk);
dayjs.extend(duration);
const symCreateOperation = await symCreateService.create(
kms.CreateSymmetricKeyRequest.create({
metadata: { name: "<key_name>" },
spec: {
description: "<key_description>",
algorithm: kms.SymmetricAlgorithm.AES_256,
rotationPeriod: dayjs.duration(720, "hours"),
},
}),
).result;
await symCreateOperation.wait();
const symCreateResult = await symCreateService.get(
kms.GetSymmetricKeyRequest.create({
id: symCreateOperation.resourceId(),
}),
).result;
console.log(symCreateResult);
metadata.name: Name of the key.spec.description(optional): Description of the key.spec.algorithm: Key encryption algorithm. You can only specify the algorithm when you create a key. You can’t update it later. The only supported value iskms.SymmetricAlgorithm.AES_256.spec.rotationPeriod(optional): Period, as a Day.js duration, after which KMS automatically rotates the key material. The example sets 720 hours. When a key is rotated, KMS generates a new key version and immediately sets it as the default version. The minimum value is one day and the maximum value is 3650 days. The default value is 90 days.
How to create an asymmetric key
- Web console
- CLI
- Terraform
- Go SDK
- Python SDK
- JavaScript SDK
- In the web console, go to
Cryptography → KMS.
- Click
Create key.
- Specify a unique key name.
- In the Type field, select Asymmetric key.
- In the Algorithm field, select RSA-4096 or ECC (P-256).
- (Optional) Add a description.
- Click Create key.
Create an asymmetric key:The command contains the following parameters:
nebius kms asymmetric-key create \
--name <key_name> \
--description "<key_description>" \
--algorithm <asymmetric_key_algorithm>
-
--name: Name of the key. -
--description(optional): Description of the key. -
--algorithm: Cryptographic algorithm to use with the key. You can only specify the algorithm when you create a key. You can’t update it later. The supported values are:ecdsa_nist_p256_sha_256ecdsa_nist_p384_sha_384rsa_4096_enc_oaep_sha_256
-
Create the following configuration:
In the configuration, specify:
resource "nebius_kms_v1_asymmetric_key" "my_asymmetric_key" { name = "<key_name>" description = "<key_description>" parent_id = "<project_ID>" algorithm = "<asymmetric_key_algorithm>" }-
name: Name of the key. -
description(optional): Description of the key. -
parent_id: Project ID. -
algorithm: Cryptographic algorithm to use with the key. You can only specify the algorithm when you create a key. You can’t update it later. The supported values are:ECDSA_NIST_P256_SHA_256ECDSA_NIST_P384_SHA_384RSA_4096_ENC_OAEP_SHA_256
-
-
Check that the configuration is correct:
terraform validate -
Apply the changes:
terraform apply
Create an asymmetric key:In the code, specify:
asymCreateService := sdk.Services().KMS().V1().
AsymmetricKey()
asymCreateOperation, err := asymCreateService.Create(
ctx,
&kms.CreateAsymmetricKeyRequest{
Metadata: &common.ResourceMetadata{
Name: "<key_name>",
},
Spec: &kms.AsymmetricKeySpec{
Description: "<key_description>",
Algorithm: kms.AsymmetricAlgorithm_ECDSA_NIST_P256_SHA_256,
},
},
)
if err != nil {
return fmt.Errorf("create asymmetric key: %w", err)
}
asymCreateOperation, err = asymCreateOperation.Wait(ctx)
if err != nil {
return fmt.Errorf("wait for operation: %w", err)
}
asymCreateResult, err := asymCreateService.Get(
ctx,
&kms.GetAsymmetricKeyRequest{
Id: asymCreateOperation.ResourceID(),
},
)
if err != nil {
return fmt.Errorf("get key: %w", err)
}
fmt.Println(asymCreateResult)
-
Metadata.Name: Name of the key. -
Spec.Description(optional): Description of the key. -
Spec.Algorithm: Cryptographic algorithm to use with the key. You can only specify the algorithm when you create a key. You can’t update it later. The supported values are:kms.AsymmetricAlgorithm_ECDSA_NIST_P256_SHA_256kms.AsymmetricAlgorithm_ECDSA_NIST_P384_SHA_384kms.AsymmetricAlgorithm_RSA_4096_ENC_OAEP_SHA_256
Create an asymmetric key:In the code, specify:
service = kms.AsymmetricKeyServiceClient(sdk)
operation = await service.create(
kms.CreateAsymmetricKeyRequest(
metadata=ResourceMetadata(name="<key_name>"),
spec=kms.AsymmetricKeySpec(
description="<key_description>",
algorithm=kms.AsymmetricAlgorithm.ECDSA_NIST_P256_SHA_256,
),
),
)
await operation.wait()
result = await service.get(
kms.GetAsymmetricKeyRequest(id=operation.resource_id),
)
print(result)
-
metadata.name: Name of the key. -
spec.description(optional): Description of the key. -
spec.algorithm: Cryptographic algorithm to use with the key. You can only specify the algorithm when you create a key. You can’t update it later. The supported values are:kms.AsymmetricAlgorithm.ECDSA_NIST_P256_SHA_256kms.AsymmetricAlgorithm.ECDSA_NIST_P384_SHA_384kms.AsymmetricAlgorithm.RSA_4096_ENC_OAEP_SHA_256
Create an asymmetric key:In the code, specify:
const asymCreateService = new kms.AsymmetricKeyService(sdk);
const asymCreateOperation = await asymCreateService.create(
kms.CreateAsymmetricKeyRequest.create({
metadata: { name: "<key_name>" },
spec: {
description: "<key_description>",
algorithm: kms.AsymmetricAlgorithm.ECDSA_NIST_P256_SHA_256,
},
}),
).result;
await asymCreateOperation.wait();
const asymCreateResult = await asymCreateService.get(
kms.GetAsymmetricKeyRequest.create({
id: asymCreateOperation.resourceId(),
}),
).result;
console.log(asymCreateResult);
-
metadata.name: Name of the key. -
spec.description(optional): Description of the key. -
spec.algorithm: Cryptographic algorithm to use with the key. You can only specify the algorithm when you create a key. You can’t update it later. The supported values are:kms.AsymmetricAlgorithm.ECDSA_NIST_P256_SHA_256kms.AsymmetricAlgorithm.ECDSA_NIST_P384_SHA_384kms.AsymmetricAlgorithm.RSA_4096_ENC_OAEP_SHA_256