Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Blog
  • Pricing
  • Documentation
Yandex project
© 2025 Yandex.Cloud LLC
Security in Yandex Cloud
  • Key security principles
  • Division of responsibility
  • Compliance
  • Security measures on the Yandex Cloud side
  • Security tools available to cloud service users
    • All tutorials
      • Which encryption method should I choose?
      • Encrypting data using the Yandex Cloud CLI and API
      • Encrypting data using the Yandex Cloud SDK
      • Encrypting data using the AWS Encryption SDK
      • Encrypting data using Google Tink
      • Managing Key Management Service keys with Terraform
      • Encrypting secrets in Terraform
      • Auto Unseal in Hashicorp Vault
      • Secure password transmission to an initialization script
      • Secure storage of GitLab CI passwords as Yandex Lockbox secrets
      • Getting Yandex Lockbox secret value on the GitHub side
      • Getting Yandex Lockbox secret value on the GitLab side
  • User support policy during vulnerability scanning
  • Security bulletins
  • Public IP address ranges

In this article:

  • Adding dependencies
  • Encryption and decryption
  1. Tutorials
  2. Data encryption and key management
  3. Encrypting data using Google Tink

Encrypting data using Google Tink

Written by
Yandex Cloud
Updated at March 31, 2025
  • Adding dependencies
  • Encryption and decryption

Tink is Google's cryptographic library, an alternative to AWS Encryption. The library helps you focus on encrypting and decrypting data without the need to choose the correct encryption algorithm and parameters.

It supports Java and Go Tink client versions, which provide encryption and decryption of data using Yandex Key Management Service keys. Data is encrypted using envelope encryption (the size of plaintext is not limited).

Adding dependenciesAdding dependencies

Before you start, you need to add dependencies.

Java
Go

Add dependencies using Apache Maven:

<dependency>
    <groupId>com.yandex.cloud</groupId>
    <artifactId>kms-provider-tink</artifactId>
    <version>2.6</version>
</dependency>

Run the following command:

go get github.com/yandex-cloud/kms-clients-go/yckmstink

Encryption and decryptionEncryption and decryption

The code uses the following variables:

  • endpoint: api.cloud.yandex.net:443.
  • credentialProvider or credentials: Determines the authentication method. For more information, see Authentication in theYandex Cloud SDK.
  • keyId: ID of the KMS key.
  • plaintext: Unencrypted text.
  • ciphertext: Ciphertext.
  • aad: AAD context.
Java
Go

Create an AEAD object and use the encrypt and decrypt methods for data encryption and decryption:

AeadConfig.register();
KmsClients.add(new YcKmsClient(credentialProvider).withEndpoint(endpoint));

String keyUri = "yc-kms://" + keyId;
Aead kmsAead = KmsClients.get(keyUri).getAead(keyUri);
Aead aead = new KmsEnvelopeAead(AeadKeyTemplates.AES256_GCM, kmsAead);

...

byte[] ciphertext = aead.encrypt(plaintext, aad);

...

byte[] plaintext = aead.decrypt(ciphertext, aad);

Create an AEAD object and use the encrypt and decrypt methods for data encryption and decryption:

sdk, err := ycsdk.Build(context, ycsdk.Config{
  Endpoint:    endpoint,
  Credentials: credentials,
})
if err != nil {...}

kmsAead := yckmstink.NewYCAEAD(keyId, sdk)
aead := aead.NewKMSEnvelopeAEAD(*aead.AES256GCMKeyTemplate(), kmsAead)

...

ciphertext, err := aead.Encrypt(plaintext, aad)
if err != nil {...}

...

plaintext, err := aead.Decrypt(ciphertext, aad)
if err != nil {...}

See alsoSee also

  • Google Tink.
  • Java client for Tink.
  • Examples of using the Java client for Tink.
  • Go client for Tink.
  • Examples of using the Go client for Tink.

Was the article helpful?

Previous
Encrypting data using the AWS Encryption SDK
Next
Managing Key Management Service keys with Terraform
Yandex project
© 2025 Yandex.Cloud LLC