了解 Tink 中的关键概念
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
首次使用 Tink 时,在开始学习之前您应该了解一些关键概念;以下各部分将对这些概念加以说明。
原语
Tink 使用基元作为加密构建块来管理底层算法,以便用户可以安全地执行加密任务。基元定义了加密算法和密钥类型的详细信息。
Tink 支持的原语:
- 带关联数据的身份验证加密 (AEAD):最常见的数据加密基元;适合大多数加密需求。AEAD 提供明文机密性,并允许验证其完整性和真实性。请参阅使用关联数据的身份验证加密 (AEAD)。
- 确定性加密:始终为给定明文和密钥生成相同密文的基元。这可能会有风险,因为攻击者只需要知道哪个密文与给定的明文输入相对应即可识别。请参阅确定性 AEAD。
- 数字签名:用于确认签名数据的真实性和完整性的非对称(请参阅非对称密钥加密)基元。请参阅数字签名。
- 混合加密:结合了非对称密钥加密和对称密钥加密的基元(请参阅非对称密钥加密和对称密钥加密)。混合加密将对称加密的效率与公钥加密的便利性结合在一起。为了加密消息,系统会生成一个新的对称密钥并将其用于加密明文数据,而接收方的公钥仅用于加密该对称密钥。最终密文由对称密文和加密的对称密钥组成。请参阅混合加密。
- 消息身份验证代码 (MAC):用于确认数据的真实性和完整性的对称(请参阅对称密钥加密)基元。请参阅邮件身份验证代码 (MAC)。
- 流式 AEAD:为流式数据提供经过身份验证的加密的基元;在要加密的数据太大而无法一步进行处理时,此类型很有用。请参阅流式 AEAD。
如需了解兼容性信息,请参阅按语言支持的基元。
如需了解详情,请参阅基元设计。
密钥类型
键类型会实现特定的基元。大多数基元都有多种键类型可供选择,具体取决于您对安全性、运行时和空间的要求。例如,AES128_GCM 是一种 AEAD,可以快速有效地满足大多数需求。如需了解详情,请参阅按语言支持的密钥类型。
密钥集和密钥集句柄
Tink 使用密钥集管理密钥。密钥集实质上是一组有助于密钥轮替的密钥。密钥集的值得注意的属性包括:
- 密钥集中的每个密钥均有一个唯一 ID,该 ID 在一个密钥集中具有唯一性。此 ID 通常作为前缀添加到每个生成的密文、签名或标记中,以指示使用了哪个密钥(如需了解详情,请参阅 Tink 如何标记密文)。
- 一个密钥集中一次只能有一个密钥为主密钥。密钥集中的主键就是当前“正在使用”的键。
- 密钥集中的所有密钥必须是相同基元(例如 AEAD)的实现,但可以具有不同的密钥类型(例如 AES-GCM 和 XCHACHA20-POLY1305 密钥)。
每个 Tink 实现都提供了用于创建或修改密钥集的 API。不过,我们建议您使用 Tinkey 我们的 CLI 工具。
用户使用密钥集句柄对密钥集执行操作。密钥集句柄可限制实际敏感密钥材料的公开。它还会对密钥集进行抽象化处理,以便用户获取用于“封装”整个密钥集的基元。例如,您可以使用 N
密钥获取密钥集的 AEAD 基元;使用获取的基元进行加密和解密时,会使用密钥集中的主密钥。
如需了解详情,请参阅密钥集设计。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-25。
[null,null,["最后更新时间 (UTC):2025-07-25。"],[[["\u003cp\u003eTink utilizes primitives as fundamental cryptographic building blocks for secure data operations, covering encryption, signatures, and message authentication.\u003c/p\u003e\n"],["\u003cp\u003eKeysets in Tink efficiently manage multiple keys for a single purpose, enabling features like key rotation and supporting various key types within a set.\u003c/p\u003e\n"],["\u003cp\u003eKeyset handles provide a secure abstraction layer, allowing users to interact with keys and perform cryptographic operations without directly exposing sensitive key material.\u003c/p\u003e\n"],["\u003cp\u003eTink offers a diverse selection of primitives and key types, accommodating varying security, performance, and storage requirements, with options like AEAD, digital signatures, and hybrid encryption.\u003c/p\u003e\n"]]],["Tink employs cryptographic building blocks called *primitives*, which define algorithms and key types. These include AEAD, Deterministic encryption, Digital signature, Hybrid encryption, MAC, and Streaming AEAD. *Key types* implement primitives, offering choices based on security and performance. *Keysets*, a set of keys with unique IDs, manage key rotation. *Keyset handles* abstract keysets, providing access to a primitive that operates over the entire keyset, including encryption/decryption with the primary key.\n"],null,["# Understand Key Concepts in Tink\n\nWhen you start working with Tink for the first time, there are some key concepts\nyou should understand before you begin your journey; these are described in the\nfollowing sections.\n\nPrimitives\n----------\n\nTink uses *primitives* as cryptographic building blocks that manage an\nunderlying algorithm so users can perform cryptographic tasks safely. A\nprimitive defines the details of a cryptographic algorithm and the key type.\n\nPrimitives supported by Tink:\n\n- **Authenticated Encryption with Associated Data (AEAD)** : The most common primitive for data encryption; suitable for most encryption needs. AEAD provides plaintext confidentiality, and allows verification of its integrity and authenticity. See [Authenticated Encryption with Associated Data\n (AEAD)](/tink/aead).\n- **Deterministic encryption:** A primitive that always produces the same ciphertext for a given plaintext and key. This can be risky, because an attacker only needs to find out which ciphertext corresponds to a given plaintext input to identify it. See [Deterministic\n AEAD](/tink/deterministic-aead).\n- **Digital signature** : An asymmetric (see *Asymmetric key encryption* ) primitive for confirming the authenticity and integrity of signed data. See [Digital signature](/tink/digital-signature).\n- **Hybrid encryption** : A primitive that combines asymmetric key encryption and symmetric key encryption (see *Asymmetric key encryption* and *Symmetric\n key encryption* ). Hybrid encryption combines the efficiency of symmetric encryption with the convenience of public-key encryption. To encrypt a message, a fresh symmetric key is generated and used to encrypt the plaintext data, while the recipient's public key is used to encrypt the symmetric key only. The final ciphertext consists of the symmetric ciphertext and the encrypted symmetric key. See [Hybrid\n encryption](/tink/hybrid).\n- **Message Authentication Code (MAC)** : A symmetric (see *Symmetric key\n encryption* ) primitive for confirming the authenticity and integrity of data. See [Message Authentication Code (MAC)](/tink/mac).\n- **Streaming AEAD** : A primitive providing authenticated encryption for streaming data; useful when the data to be encrypted is too large to be processed in a single step. See [Streaming AEAD](/tink/streaming-aead).\n\nSee [Supported primitives by language](/tink/primitives-by-language) for\ncompatibility information.\n\nFor more info, see [primitive design](/tink/design/primitives_and_interfaces).\n\nKey types\n---------\n\nA *key type* implements a specific primitive. Most primitives have several key\ntypes to choose from depending on your requirements for security, runtime, and\nspace. For example, AES128_GCM is an [AEAD](/tink/aead) that is fast and\neffective for most needs. See more at [Supported key types by\nlanguage](/tink/supported-key-types).\n\nKeysets \\& keyset handles\n-------------------------\n\nTink uses *keysets* for managing keys. A keyset is essentially a set of keys\nthat facilitate key rotation. Noteworthy properties of a keyset are:\n\n- Each key in a keyset has a unique ID, which is unique within a keyset. This ID is usually added as a prefix to each produced ciphertext, signature or tag to indicate which key was used (see how Tink [tags\n ciphertexts](/tink/design/keysets#tagging_ciphertexts) for more info).\n- Only one key at a time in a keyset is *primary*. A primary key in a keyset is the key \"in use\" at the moment.\n- All the keys in a keyset *must* be implementations of the same primitive (such as AEAD), but can have different key types (for example, an AES-GCM and XCHACHA20-POLY1305 key).\n\nEach Tink implementation provides APIs to create or edit keysets. However, we\nrecommend using [Tinkey](/tink/tinkey-overview) our CLI tool.\n\nUsers operate over a keyset using *keyset handles* . A keyset handle limits the\nexposure of the actual sensitive key material. It also abstracts a keyset\nallowing users to obtain a primitive that \"wraps\" the entire keyset. For\nexample, you can get an AEAD primitive of a keyset with `N` keys; encryption and\ndecryption with the obtained primitive then uses the primary key in the keyset.\n\nFor more info, see [keyset design](/tink/design/keysets)."]]