瞭解 Tink 的重要概念
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
首次使用 Tink 時,在開始流程之前,請務必先瞭解一些重要概念;我們會在以下各節中說明這些概念。
基本
Tink 使用「原始物件」做為密碼編譯建構區塊,用於管理基礎演算法,讓使用者能安全地執行加密編譯工作。基本定義了加密編譯演算法和金鑰類型的詳細資料。
Tink 支援的基本功能:
- 使用相關資料進行驗證加密 (AEAD):最常用於資料加密的基本功能,適用於大多數加密需求。AEAD 提供純文字的機密性,並允許驗證其完整性和真實性。請參閱使用相關資料進行驗證 (AEAD) 驗證。
- 確定性加密:這個原始物件一律會針對特定明文和金鑰產生相同的密文。這可能會有風險,因為攻擊者只需要找出特定明文輸入內容對應的密文即可進行識別。請參閱確定性 AEAD 部分。
- 數位簽章:非對稱式 (請參閱「非對稱金鑰加密」一節),用於確認已簽署資料的真實性和完整性。請參閱「數位簽章」。
- 混合式加密:結合非對稱式金鑰加密與對稱式金鑰加密的基本功能 (請參閱「非對稱金鑰加密」和「對稱金鑰加密」部分)。混合式加密結合了對稱加密的效率與公開金鑰加密的便利性。為加密訊息,系統會產生新的對稱金鑰,並使用該金鑰加密明文資料,而接收方的公開金鑰則只用於加密對稱金鑰。最終的密文包含對稱密文和加密對稱金鑰。請參閱「混合式加密」。
- 訊息驗證碼 (MAC):用於確認資料的真實性和完整性的對稱式 (請參閱「對稱金鑰加密」一節)。請參閱訊息驗證碼 (MAC)。
- 串流 AEAD:提供已驗證串流資料加密的原始版本;如果要加密的資料太大,而無法在單一步驟中處理,此屬性就非常實用。請參閱串流 AEAD。
如需相容性資訊,請參閱「依語言區分的支援基元」。
詳情請參閱原始設計。
金鑰類型
金鑰類型會實作特定基元。大部分基元都有多種關鍵類型,您可以根據安全性、執行階段和空間需求選擇。舉例來說,AES128_GCM 是一種 AEAD,快速又有效,能滿足大多數需求。詳情請參閱不同語言支援的金鑰類型。
金鑰組與金鑰組控點
Tink 使用金鑰組來管理金鑰。金鑰組基本上是一組有助於輪替金鑰的金鑰。金鑰組值得注意的屬性如下:
- 金鑰組中的每個金鑰都有專屬 ID,在金鑰組中不得重複。這個 ID 通常會新增為每個所產生密文、簽章或標記的前置字串,以表示使用的金鑰 (詳情請參閱 Tink 的標記密文說明)。
- 金鑰組中一次只能有一個金鑰為「主要」。金鑰組中的主鍵是目前「使用中」的索引鍵。
- 金鑰組中的所有金鑰都必須採用相同原始 (例如 AEAD) 的實作,但金鑰類型可以不同 (例如 AES-GCM 和 XCHACHA20-POLY1305 金鑰)。
每個 Tink 實作都會提供用於建立或編輯金鑰組的 API。不過,我們建議使用 CLI 工具的 Tinkey。
使用者是透過金鑰組控制代碼透過金鑰組運作。金鑰組控制代碼會限制實際機密金鑰內容的曝光率。它也會提取一組金鑰組,可讓使用者取得可「包裝」整個金鑰組的基本功能。舉例來說,您可以取得具有 N
金鑰的金鑰組 AEAD 原始物件,然後使用取得的原始金鑰加密和解密,然後使用金鑰組中的主金鑰。
詳情請參閱「金鑰組設計」。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-25 (世界標準時間)。
[null,null,["上次更新時間: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)."]]