Yandex Cloud
  • Services
  • Solutions
  • Why Yandex Cloud
  • Blog
  • Pricing
  • Documentation
  • Contact us
Get started
Language / Region
Yandex project
© 2023 Yandex.Cloud LLC
Yandex Key Management Service
  • Getting started
  • Step-by-step instructions
    • All instructions
    • Key
    • Key version
    • Data encryption
  • Concepts
    • Overview
    • Key
    • Key version
    • Encryption
    • Envelope encryption
    • Key consistency
    • Hardware Security Module (HSM)
    • Quotas and limits
  • Practical guidelines
    • All tutorials
    • Data encryption
      • Which encryption method should I choose?
      • Encrypting data using the CLI and API Yandex Cloud
      • Encrypting data using the Yandex Cloud SDK
      • Encrypting data using the AWS Encryption SDK
      • Encrypting data using Google Tink
    • Encrypting secrets in Managed Service for Kubernetes
    • KMS key management with Hashicorp Terraform
    • Encrypting secrets in Hashicorp Terraform
    • Auto Unseal in Hashicorp Vault
  • Access management
  • Pricing policy
  • API reference
    • Authentication in the API
    • gRPC
      • Overview
      • SymmetricCryptoService
      • SymmetricKeyService
      • OperationService
    • REST
      • Overview
      • SymmetricCrypto
        • Overview
        • decrypt
        • encrypt
        • generateDataKey
        • reEncrypt
      • SymmetricKey
        • Overview
        • cancelVersionDestruction
        • create
        • delete
        • get
        • list
        • listAccessBindings
        • listOperations
        • listVersions
        • rotate
        • scheduleVersionDestruction
        • setAccessBindings
        • setPrimaryVersion
        • update
        • updateAccessBindings
  • Questions and answers
  1. Practical guidelines
  2. Data encryption
  3. Encrypting data using the AWS Encryption SDK

Encrypting data using the AWS Encryption SDK

Written by
Yandex Cloud
  • Adding dependencies
  • Encryption and decryption

AWS Encryption SDK is a library that simplifies the process of encrypting and decrypting data. Use it if you want to securely encrypt data without going into the details of encryption algorithms.

The Yandex Cloud provider for the AWS Encryption SDK lets you use the AWS Encryption SDK to encrypt and decrypt data with Yandex Cloud KMS keys. Data is encrypted using envelope encryption (the size of plaintext is not limited). The provider is only supported for Java.

Adding dependencies

Before you start, you need to add dependencies.

Java

Add dependencies using Apache Maven:

<dependency>
    <groupId>com.yandex.cloud</groupId>
    <artifactId>kms-provider-awscrypto</artifactId>
    <version>2.1</version>
</dependency>

Encryption and decryption

Create a Yandex Cloud provider for the AWS Encryption SDK and use the methods of the AwsCrypto class to encrypt and decrypt data.

Java
YcKmsMasterKeyProvider provider = new YcKmsMasterKeyProvider()
    .withEndpoint(endpoint)
    .withCredentials(credentialProvider)
    .withKeyId(keyId);
AwsCrypto awsCrypto = AwsCrypto.standard();

...

byte[] ciphertext = awsCrypto.encryptData(provider, plaintext, aad).getResult();

...

byte[] plaintext = awsCrypto.decryptData(provider, ciphertext).getResult();

Where:

  • endpoint – api.cloud.yandex.net:443.
  • credentials: Determines the authentication method (for more information, see Authentication in the Yandex Cloud SDK).
  • keyId: ID of the key in KMS.
  • plaintext: Unencrypted text.
  • ciphertext: Encrypted text.
  • aad: AAD context.

See also

  • AWS Encryption SDK.
  • The Yandex Cloud provider for the AWS Encryption SDK.
    • Examples of using Yandex Cloud KMS Providers for the AWS Encryption SDK.

Was the article helpful?

Language / Region
Yandex project
© 2023 Yandex.Cloud LLC
In this article:
  • Adding dependencies
  • Encryption and decryption