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
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
    • Yandex Cloud Partner program
  • Blog
  • Pricing
  • Documentation
© 2025 Direct Cursus Technology L.L.C.
Tutorials
    • All tutorials
    • Differentiation of access permissions for user groups
    • Creating an L7 load balancer with a Smart Web Security security profile through an Application Load Balancer Ingress controller
    • Centralized online publication and app protection against DDoS attacks
    • Delivering logs from a VM instance to Cloud Logging
    • Writing load balancer logs to PostgreSQL
    • Secure storage of GitLab CI passwords as Yandex Lockbox secrets
    • Service account with an OS Login profile for VM management via Ansible
    • Transferring logs from Container Optimized Image to Cloud Logging
    • Adding an HTML page to work with SmartCaptcha
    • Creating an L7 load balancer with a security profile
    • Alert settings in Monitoring
    • Exporting audit logs to MaxPatrol SIEM
    • Exporting audit logs to SIEM Splunk systems
    • Uploading audit logs to ArcSight SIEM
      • 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
    • Server-side encryption for an Object Storage bucket
    • Encrypting secrets in Hashicorp Terraform
    • Managing KMS keys with Hashicorp Terraform
    • Auto Unseal in Hashicorp Vault

In this article:

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

Encrypting data using Google Tink

Written by
Yandex Cloud
Updated at January 23, 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
Server-side encryption for an Object Storage bucket
© 2025 Direct Cursus Technology L.L.C.