Skip to main content
Key Management Service (KMS) lets you create symmetric keys that use the same key material for encryption and decryption. The example below shows how to create your first symmetric key, encrypt sample data and decrypt it.

Prerequisites

You can create symmetric keys in any Nebius AI Cloud interface, but to encrypt and decrypt data, use the Nebius AI Cloud CLI.
  1. Install and configure the Nebius AI Cloud CLI.
  2. 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.

Steps

Create a symmetric key

  1. In the web console, go to https://mintcdn.com/nebius-ai-cloud/BhI64Dlym_yJl7Yy/_assets/sidebar/cryptography.svg?fit=max&auto=format&n=BhI64Dlym_yJl7Yy&q=85&s=e2af8c31917650f2951761ab265dd9b9 CryptographyKMS.
  2. Click https://mintcdn.com/nebius-ai-cloud/1Ha0sWR6e1mnIaHS/_assets/plus.svg?fit=max&auto=format&n=1Ha0sWR6e1mnIaHS&q=85&s=7c9efc69d65fc58db0eb73702fd81aa1 Create key.
  3. On the key creation page:
    • In the Name field, enter my-symmetric-key.
    • In the Type field, preserve Symmetric key.
  4. Click Create key.
This creates a symmetric key with the AES_256_GCM algorithm and the default rotation period of three months.You need the key ID to encrypt and decrypt data. In the list of symmetric keys, click https://mintcdn.com/nebius-ai-cloud/1Ha0sWR6e1mnIaHS/_assets/copy.svg?fit=max&auto=format&n=1Ha0sWR6e1mnIaHS&q=85&s=e7f23591f2e46ebae45634aa995aaa9f next to the key ID of the key you created, then save the copied value to the KEY_ID environment variable:
export KEY_ID=<key_ID>

Encrypt data

  1. Encode the text Hello world in Base64:
    printf '%s' 'Hello world' | base64 -w 0
    
    The output looks like the following:
    SGVsbG8gd29ybGQ=
    
  2. Encrypt the text Hello world:
    nebius kms symmetric-crypto encrypt \
      --key-id "$KEY_ID" \
      --plaintext SGVsbG8gd29ybGQ=
    
    This command includes the following parameters:
    • --key-id: ID of the symmetric key that you created.
    • --plaintext: Base64-encoded value of your text.
    The command returns the ciphertext value that you need for decrypting the data later:
    key_id: kmssymkey-e00***
    ciphertext: AhIClM3o***
    

Decrypt data

  1. To decrypt the data, use the same symmetric key and the returned ciphertext:
    nebius kms symmetric-crypto decrypt \
      --key-id "$KEY_ID" \
      --ciphertext <ciphertext>
    
    This command includes the following parameters:
    • --key-id: ID of the symmetric key that you created.
    • --ciphertext: Ciphertext returned when you encrypted the plaintext.
    The output contains the Base64-encoded plaintext:
    key_id: kmssymkey-e00***
    plaintext: SGVsbG8gd29ybGQ=
    
  2. Decode the plaintext value from Base64:
    printf '%s' 'SGVsbG8gd29ybGQ=' | base64 -d
    
    The output is:
    Hello world
    

What’s next