Getting started with Key Management Service
In this guide, you create your first key and encrypt and decrypt text using the KMS.
Getting started
To get started with Key Management Service:
- Log in to the management console
. If you do not have an account yet, go to the management console and follow the guide. - On the Billing
page, make sure you have a billing account linked and it has theACTIVE
orTRIAL_ACTIVE
status. If you do not yet have a billing account, create one. - Make sure that you have the
owner
oreditor
role for the cloud. - If you do not have the Yandex Cloud (CLI) command line interface yet, install and initialize it.
Create a symmetric encryption key
Create a symmetric encryption key:
- In the management console
, select the folder where you want to create a key. - Select Key Management Service.
- In the left-hand panel, select
Symmetric keys. - Click Create key and set the key parameters:
- In the Name field, enter
my-first-key
. - In the Encryption algorithm field, set
AES-256
. - In the Rotation period, days field, leave
No rotation
. - Click Create.
- In the Name field, enter
- Click the line with the key name and make sure the Versions section contains the first key version.
Encrypt text using the key
Come up with a secret text, for example: The launch is scheduled for Marchember 42.
. The text size must not exceed 32 KB. To encrypt large volumes of data, use envelope encryption.
Encrypt the text:
-
Save the secret text to the
plaintext.txt
file. -
Copy the ID of the previously created key from the management console.
- In the management console
, go to the folder where the key was created. - Select Key Management Service.
- In the window that opens, copy the key from the ID field.
- In the management console
-
Encrypt the text:
yc kms symmetric-crypto encrypt \ --id <key_ID> \ --plaintext-file plaintext.txt \ --ciphertext-file ciphertext
The result is a binary file named ciphertext
containing ciphertext.
Decrypt the text
Decrypt the ciphertext
binary file from the previous step.
Decrypt the text:
yc kms symmetric-crypto decrypt \
--id <key_ID> \
--ciphertext-file ciphertext \
--plaintext-file decrypted.txt
As a result, the ciphertext
file is decrypted and the following decrypted text is written to the decrypted.txt
file: The launch is scheduled for Marchember 42.
.