Prerequisites
You can retrieve the public key in the web console. To sign hashes, use the Nebius AI Cloud CLI. To verify signatures, use a local cryptographic tool such as OpenSSL.- 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. Alternatively, you can have an access permit with theeditorrole assigned to the required key. To check your access rights, go to the Administration → IAM section in the web console.
How to get the public key
You can retrieve the public key to use it for encryption and signature verification.- Web console
- CLI
-
In the web console, go to
Cryptography → KMS.
-
Select Asymmetric keys and find the required key in the list.
To choose a key that supports what you need, check the Algorithm column:
- Signing and verification: ECC (P-256)
- Encryption: RSA-4096
-
On the Key’s overview tab, next to Public key, click
.
-
Save the public key contents to a local file, for example
public_key.pem.
How to use asymmetric keys for encryption
For asymmetric encryption, the public key can be used to encrypt data and only the holder of the private key can decrypt data.Encrypting data
Encrypt the data locally with your public key by using an external tool such as OpenSSL:-in: Path to the file with the plaintext data to encrypt. The maximum plaintext size is 446 bytes.-inkey: Path to the file containing the public key.
How the maximum plaintext size is calculated
How the maximum plaintext size is calculated
The maximum size of a plaintext message to encrypt can be calculated using the following formula:
Message length = (k - 2) - 2 × hash lengthWhere:k: Length of the encryption key, in bytes.hash length: Length of the hash function, in bytes.
rsa_4096_enc_oaep_sha_256) algorithm:k = 512, because an RSA-4096 key is 4096 bits long, which equals 512 bytes.hash length = 32, because SHA-256 produces a 256-bit hash, which equals 32 bytes.
Message length = (512 - 2) - 2 × 32 = 446 bytesDecrypting data
To decrypt data with an asymmetric KMS key:-
Run the following command:
In the command, specify the following parameters:
-
--key-id: ID of the asymmetric KMS key that was used for encryption. To get it, run:In the output, copy the ID of the key that you used for encryption. -
--ciphertext: Encrypted data returned asciphertextwhen you encrypted the data.
-
-
Decode the
plaintextvalue from Base64. For example, to decodeSGVsbG8gd29ybGQ=:
How to use asymmetric keys for digital signatures
Signing a hash
Use the private key of an asymmetric key pair to sign a hash that you generate yourself. The signature can be verified with the public key.-
Generate a hash of the file or data that you want to sign and encode it in Base64.
In the command:
<hash_function>: OpenSSL hash function to use when generating the hash. The value depends on the algorithm your key uses: set it to-sha256forecdsa_nist_p256_sha_256keys and to-sha384forecdsa_nist_p384_sha_384keys.<path_to_file>: Path to the file for which you want to generate the hash.
-
Run the following command:
In the command, specify the following parameters:
-
--key-id: ID of the asymmetric KMS key to use to sign the hash. To get it, run:In the output, copy the ID of the key that you want to use. -
--hash: The hash value that you generated, encoded in Base64.
-
-
Save the
signaturevalue to a local file, for examplesignature.b64.
Verifying a signature
You can verify a signature by using the public key of the asymmetric key pair and an external tool such as OpenSSL.-
Decode the saved signature from Base64:
KMS returns the signature as a Base64-encoded string, while OpenSSL expects a binary signature file. This command converts the saved Base64 value to a binary file that OpenSSL can use. For example:
-
Verify the signature.
In the command:
<hash_function>: OpenSSL hash function parameter to use when verifying the signature. The value depends on the algorithm your key uses: set it to-sha256forecdsa_nist_p256_sha_256keys and to-sha384forecdsa_nist_p384_sha_384keys.-verify: Path to the public key.-signature: Path to the binary signature file.<path_to_file>: Path to the signed file.