Registry / auth-security / tink
library1.16.1pypypi✓ verified 25d ago

Tink is a multi-language, cross-platform library that provides cryptographic APIs designed to be secure, easy to use, and hard to misuse. It is developed by cryptographers and security engineers at Google and offers primitives for common cryptographic tasks like AEAD, Streaming AEAD, Deterministic AEAD, MAC, Hybrid Encryption, Digital Signatures, and JWT. The library is actively maintained with frequent releases, currently at version 1.14.1.

pip install tink
INSTALL
IMPORT
SIG · TINK
T
tink
auth-securitypythonv1.16.1
Install
4.6s avg
Import
131ms
Disk
89MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.16.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.915 runs
build_error
glibc
py 3.103.915 runs
installs and imports cleanly · install 4.6s · import 0.131s · 89MB
89MB installed
● package 89MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

tink_config
from tink import tink_config
aead
from tink import aead
KeysetHandle
import tink
JsonKeysetReader
from tink.json_proto_keyset_format import parse
GcpKmsClient
from tink.integration import gcpkms
secret_key_access
from tink import secret_key_access
Required when parsing cleartext keysets, as a security token.

This quickstart demonstrates basic Authenticated Encryption with Associated Data (AEAD) using Tink. It covers initializing Tink, generating a new keyset, encrypting and decrypting data, and a warning-laden example of parsing a cleartext keyset. This example is simplified and does not involve KMS for brevity, but the same primitive concept applies.

import tink from tink import aead from tink import tink_config from tink import secret_key_access from tink.json_proto_keyset_format import parse def main(): # 1. Initialize Tink with all standard primitives. tink_config.register() # 2. Create a new AEAD keyset handle from a key template. # WARNING: Using cleartext keysets directly in code is a security risk. # For production, use secure key management, e.g., KMS or encrypted keysets. key_template = aead.aead_key_templates.AES256_GCM keyset_handle = tink.new_keyset_handle(key_template) # 3. Obtain the AEAD primitive from the keyset handle. aead_primitive = keyset_handle.primitive(aead.Aead) # 4. Define plaintext and associated data. plaintext = b'This is some secret data.' associated_data = b'associated_data_for_encryption' # 5. Encrypt the data. ciphertext = aead_primitive.encrypt(plaintext, associated_data) print(f'Encrypted data: {ciphertext.hex()}') # 6. Decrypt the data. try: decrypted_data = aead_primitive.decrypt(ciphertext, associated_data) print(f'Decrypted data: {decrypted_data.decode()}') assert decrypted_data == plaintext print('Encryption and decryption successful!') except tink.TinkError as e: print(f'Decryption failed: {e}') # Example of loading a cleartext keyset (for demonstration only, not recommended for production) cleartext_keyset_json = '{\"primaryKeyId\":1919301694,\"key\":[{\"keyData\":{\"typeUrl\":\"type.googleapis.com/google.crypto.tink.AesGcmKey\",\"value\":\"EhDKd0x8s2g+tXf1nJjDqD8u\",\"keyMaterialType\":\"SYMMETRIC\"},\"status\":\"ENABLED\",\"keyId\":1919301694,\"outputPrefixType\":\"TINK\"}]}' try: loaded_keyset_handle = parse(cleartext_keyset_json, secret_key_access.TOKEN) print("Successfully loaded cleartext keyset (for demonstration).") except tink.TinkError as e: print(f"Failed to load cleartext keyset: {e}") if __name__ == '__main__': main()
Debug
Known issues
breakingDeserializing `KeysetHandle` objects using `pickle` is explicitly disallowed and will raise a `tink.TinkError`. This change was introduced in v1.14.0 to prevent unintentional key leakage.
fix
To serialize `KeysetHandle` objects, use `tink.proto_keyset_format` or `tink.json_proto_keyset_format` instead.
affects: >=1.14.0
breakingWhen a `GcpKmsClient` is instantiated with a `CryptoKeyVersion`, performing decryption will now raise an error, mirroring Google Cloud KMS service behavior which only allows specifying the version for encrypt operations.
fix
Ensure `GcpKmsClient` is instantiated without a `CryptoKeyVersion` when decryption operations are intended, or manage key versions appropriately for encryption-only contexts.
affects: >=1.13.0
gotchaTink requires explicit registration of primitives or all standard implementations via `tink.tink_config.register()` (for all) or `primitive.register()` (e.g., `aead.register()`). Failing to do so will result in `tink.TinkError` messages like 'No wrapper registered' or 'No manager for type T has been registered' when attempting to obtain a primitive.
fix
Call `tink_config.register()` once at the start of your application, or register only the specific primitives you need (e.g., `aead.register()`).
affects: All versions
gotchaDirectly using cleartext keysets (e.g., hardcoding them in your source code or loading them unencrypted from disk) is a significant security risk as it exposes sensitive key material.
fix
For production environments, always protect your cryptographic keys using secure key management solutions like Cloud KMS, AWS KMS, HashiCorp Vault, or by encrypting keysets using a master key.
affects: All versions
gotchaWhen using AEAD (Authenticated Encryption with Associated Data), the 'associated data' parameter is authenticated but *not* encrypted. It protects against tampering with the associated data but does not hide its contents.
fix
Be aware that associated data remains visible in cleartext. Do not include sensitive information in the associated data if it needs to remain confidential.
affects: All versions
gotcha`GcpKmsClient` can be used as a context manager (i.e., in a `with` statement) since v1.13.0, which ensures proper resource cleanup.
fix
Consider using `with gcpkms.GcpKmsClient(...) as client:` to manage `GcpKmsClient` instances for robust resource handling.
affects: >=1.13.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'tink'
The Tink library has not been installed in the current Python environment.
fix
Install the Tink library using pip: `pip install tink`
tink.python.cc.tink_error.TinkError: Tink has not been initialized or the requested primitive type is not supported.
Tink's cryptographic primitives are not initialized or registered before attempting to use them, or an unsupported primitive type is requested.
fix
Call `tink.tink_config.register()` or the specific primitive's `register()` method (e.g., `tink.aead.register()`) at the start of your application.
tink.python.cc.tink_error.TinkError: invalid key
The provided key material (keyset) is either malformed, corrupted, or incompatible with the cryptographic operation being attempted.
fix
Ensure the keyset is properly generated and loaded using `tink.keyset_handle` methods, and that it corresponds to the intended primitive (e.g., AEAD for AEAD operations).
tink.jwt._jwt_error.JwtInvalidError: invalid JWT signature
The signature of the provided JSON Web Token (JWT) does not match the expected signature, indicating tampering or that the wrong public key is used for verification.
fix
Verify that the JWT was signed with the correct private key and that the public key used for verification corresponds to that private key and is correctly loaded into the `JwtPublicKeyVerify` primitive.
Upgrade
Version history
1.16.1latest on PyPI · released Aug 13, 2026
Audit
Dependencies
protobufrequiredUsed for serializing key material and configuration. Version 6.33.5 was specified in Tink Python v1.14.0.
google-cloud-kmsoptionalRequired for the 'gcpkms' extra to interact with Google Cloud KMS.
boto3optionalRequired for the 'awskms' extra to interact with AWS KMS.
Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
1
Resources
tink — pip install tink · libregistry