Skip to main content
Key Management Service (KMS) lets you create asymmetric keys that use a public and private key pair. The example below focuses on digital signatures and shows how to create your first asymmetric key, get its public key, sign a hash of a test file and verify the resulting signature.

Prerequisites

You can create asymmetric keys in any Nebius AI Cloud interface. To sign hashes, use the Nebius AI Cloud CLI. To verify signatures, use a local cryptographic tool such as OpenSSL.
  1. Make sure that OpenSSL is installed on your local machine. In this guide, you use it to generate a local hash of a file and verify a returned signature with a public key locally.
  2. Install and configure the Nebius AI Cloud CLI.
  3. 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 an asymmetric 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-asymmetric-key.
    • In the Type field, select Asymmetric key.
    • In the Algorithm field, select ECC (P-256) to create a key that you can use for digital signature workflows.
  4. Click Create key.
You need the key ID to get the public key and sign a hash. In the list of asymmetric 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>

Get the public 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. Select Asymmetric keys and click the key you created.
  3. On the Key’s overview tab, next to Public key, click https://mintcdn.com/nebius-ai-cloud/1Ha0sWR6e1mnIaHS/_assets/copy.svg?fit=max&auto=format&n=1Ha0sWR6e1mnIaHS&q=85&s=e7f23591f2e46ebae45634aa995aaa9f.
  4. Create the public_key.pem file with the copied contents.

Sign a hash

  1. Create the hello.txt file:
    echo 'Hello world' > hello.txt
    
  2. Generate a SHA-256 hash of the file and encode it in Base64:
    HASH_B64="$(openssl dgst -sha256 -binary hello.txt | openssl base64 -A)"
    printf '%s\n' "$HASH_B64"
    
    The command returns a Base64-encoded hash value that you need to provide for signing and saves it to the HASH_B64 environment variable.
  3. Send the hash value to KMS to sign it with your asymmetric key:
    nebius kms asymmetric-crypto sign-hash \
      --key-id "$KEY_ID" \
      --hash "$HASH_B64" \
      --format jsonpath='{.signature}' > signature.b64
    
    This command includes the following parameters:
    • --key-id: ID of the asymmetric key that you created.
    • --hash: Base64-encoded hash value generated in the previous step.
    • --format jsonpath='{.signature}': Returns only the signature value.
    This command returns the signature as a Base64-encoded string and writes it to the signature.b64 file.

Verify the signature

Verify the signature to confirm that it was created with the matching private key and that the file was not changed after it was signed.
  1. Decode the saved signature in the signature.b64 file, convert it to binary form and save it to the signature.bin file:
    openssl base64 -d -A -in signature.b64 -out signature.bin
    
    OpenSSL uses the binary form of the signature for verification. Therefore, you need the signature.bin file in the next step.
  2. Verify the signature with the public key:
    openssl dgst \
      -sha256 \
      -verify public_key.pem \
      -signature signature.bin \
      hello.txt
    
    This command includes the following parameters:
    • -sha256: Hash function that matches ecdsa_nist_p256_sha_256.
    • -verify: Uses the public key file to check whether the signature was created with the matching private key.
    • -signature: Specifies the signature file to use for verifying the signature.
    • hello.txt: File that OpenSSL checks against the signature.
    If the signature is valid, OpenSSL returns:
    Verified OK
    

What’s next