0Pricing
Cryptology Academy · Lesson

Google Tink: Safe High-Level Crypto

Use Tink's keyset-based API to perform common cryptographic operations without cryptographic expertise.

Google Tink: Safe High-Level Crypto is a free Cryptology Academy lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cryptology Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Tink Overview and Motivation

Tink is an open-source cryptographic library developed by Google's cryptography team, designed to provide safe and easy-to-use cryptography. The primary motivation is preventing the common cryptographic misuse patterns that occur even among experienced developers using lower-level libraries. Tink's API is designed so that the correct operation is the path of least resistance, making it difficult to accidentally create insecure configurations.

Keyset-Based Abstraction

Tink organizes keys into keysets rather than exposing individual key objects. Applications work with keyset handles, not raw key bytes. This abstraction prevents accidental key exposure, enables seamless key rotation, and allows keys to be stored in remote Key Management Systems without the application ever seeing the key material directly. The keyset concept is central to Tink's safe design.

AEAD Interface

The AEAD (Authenticated Encryption with Associated Data) interface in Tink provides encrypt and decrypt operations. AeadFactory.getPrimitive(keyset) returns an Aead object; calling aead.encrypt(plaintext, associatedData) returns ciphertext. Tink automatically selects the encryption algorithm based on the keyset (e.g., AES-256-GCM) and generates a random nonce. The interface hides all algorithm details, nonce management, and format encoding.

MAC Interface

Tink's MAC interface provides compute and verify operations for message authentication codes. MacFactory.getPrimitive(keyset) returns a Mac object. mac.computeMac(data) returns the authentication tag; mac.verifyMac(tag, data) verifies it, throwing a security exception if verification fails. The default algorithm is HMAC-SHA256. The interface prevents common mistakes like comparing MACs with regular string equality instead of constant-time comparison.

Digital Signature Interface

Tink provides separate PublicKeySign and PublicKeyVerify interfaces for digital signatures. The sign and verify objects are derived from different keyset handles (private and public respectively), preventing accidental use of a private key for verification or vice versa. Tink's Ed25519 and ECDSA P-256 implementations are the defaults, with deterministic ECDSA available to avoid randomness vulnerabilities.

Hybrid Encryption Interface

Tink's HybridEncrypt and HybridDecrypt interfaces implement ECIES (Elliptic Curve Integrated Encryption Scheme). Hybrid encryption combines asymmetric key exchange with symmetric encryption: the sender generates an ephemeral key, performs ECDH with the recipient's public key, derives a symmetric key, and encrypts with AEAD. This allows encrypting large messages using asymmetric keys without the overhead of pure asymmetric encryption.

Keyset Rotation Process

Key rotation in Tink is safe and backward-compatible. To rotate: generate a new key and add it to the keyset, mark the new key as primary (future encryptions use it), keep old keys in the keyset for decryption of existing ciphertexts. Old ciphertexts continue to decrypt because non-primary keys remain available for decryption. Once all old ciphertexts have been re-encrypted or expired, delete old keys from the keyset.

Keyset Serialization

Tink keysets are serialized as JSON or binary Protocol Buffer format. The JSON format is human-readable and useful for debugging. Binary format is more compact for production. Serialized keysets containing private keys must be encrypted before storage. Tink supports storing encrypted keysets using standard symmetric AEAD encryption, or delegating storage to a KMS.

KMS Integration for Keyset Encryption

Tink integrates with major KMS providers: AWS KMS, Google Cloud KMS, and HashiCorp Vault. Instead of encrypting keysets with a local AEAD key, Tink wraps the keyset encryption key using the KMS. The actual keyset encryption uses a locally generated Data Encryption Key (DEK), and the DEK is encrypted by the KMS Key Encryption Key (KEK). This follows the envelope encryption pattern used by cloud providers.

Streaming AEAD for Large Files

Standard AEAD requires loading the entire message into memory for encryption and decryption. Tink's Streaming AEAD interface encrypts large files in segments, allowing streaming encryption and decryption without buffering the complete plaintext. Each segment is independently authenticated, and the ordering and completeness of segments is verified during decryption. This is essential for encrypting backups, videos, and other large files.

Language Support and Ecosystem

Tink is available for Java, Python, Go, and C++ with idiomatic APIs for each language. Cross-language interoperability is guaranteed: a file encrypted with Tink in Python can be decrypted with Tink in Java. This makes Tink suitable for systems with multiple services in different languages that need to exchange encrypted data. Tink also integrates with protocol buffers for type-safe keyset configuration.

Tink Keyset Rotation

During Tink key rotation, what happens to ciphertexts encrypted with the old (non-primary) key?

Google Tink Recap

Tink recap: keyset-based abstraction prevents raw key exposure, AEAD interface hides nonce management and algorithm selection, MAC interface uses constant-time verification internally, digital signature and hybrid encryption interfaces prevent interface misuse, key rotation is backward-compatible (old keys decrypt until removed), KMS integration follows envelope encryption pattern, streaming AEAD handles large files, and cross-language interoperability is guaranteed.

Frequently asked questions

Is the “Google Tink: Safe High-Level Crypto” lesson free?

Yes — the full text of “Google Tink: Safe High-Level Crypto” is free to read here on the web, and the Cryptology Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cryptology Academy course, upgrade to CoddyKit PRO.

What will I learn in “Google Tink: Safe High-Level Crypto”?

Use Tink's keyset-based API to perform common cryptographic operations without cryptographic expertise. You practise Cryptology Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Cryptology Academy?

No prior experience is required. Cryptology Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Google Tink: Safe High-Level Crypto” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Cryptology Academy lesson?

Yes. Every Cryptology Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. libsodium: A Misuse-Resistant Crypto Library
  2. OpenSSL API: Core Structures and Pitfalls
  3. Google Tink: Safe High-Level Crypto
  4. Auditing and Selecting Cryptographic Dependencies
← Back to Cryptology Academy