什麼是 Tink?
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Tink 是由密碼學家編寫的開放原始碼密碼學程式庫,
擔任 Google 資安工程師Tink 的安全簡易 API 降低了常見的情況
以使用者為中心的設計、仔細執行和審查程式碼
並進行大量測試詳情請參閱本頁的「目標」一節,
更多的分析見解。
Tink 幫助沒有密碼編譯背景的使用者安全地實作
加密編譯任務Tink 已在 Google 的數百項產品中部署
和系統
為什麼要使用 Tink?
使用 Tink 最重要的理由如下:
簡單易用
密碼學很難抓對。有了 Tink,你可以
加密或簽署資料:
內建安全保證,只需加入幾行程式碼即可。Tink 也可以
協助您使用外部金鑰管理系統輪替金鑰或安全金鑰
(KMS)。
安全無虞
Tink 為 BoringSSL 等知名程式庫加上安全防護措施
以及 Java Cryptography Architecture 在介面中示範
讓稽核人員和工具能快速找出缺口。Tink 也會將 API
因此您可以加以監控
相容
Tink 密文與現有的密碼編譯程式庫相容。町克
也支援在 Python 中加密或儲存金鑰
Amazon KMS、Google Cloud KMS、Android KeyStore 和 iOS 鑰匙圈。
誰正在使用 Tink?
Tink 廣受許多公司使用,包括 Google、Square 和 Citadel。
以及數百個 Google Cloud 客戶和 Google Pay 合作夥伴Tink 也
支援 Jetpack Security 程式庫,可保護許多熱門 Android 應用程式
例如 Slack、Adidas、AirBnb 和 Nextdoor。
Tink 目標
與其他加密編譯程式庫相比,Tink 的主要目標為何?
Tink 使用哪些主要機制來達成這些目標?
簡單來說,Tink 有兩個目標:
- 提升密碼編譯靈活性:使用者應能變更金鑰,
簡化演算法
- 啟用安全性審查:Tink 的用途是讓使用者撰寫
安全性可在本機審查,方法是提供能清楚說明
安全保證
Tink 用來達成這些目標的主要機制如下:
- Tink 提供基本和介面做為重要的抽象層。這些
抽象化機制可讓使用者編寫未指定確切程式碼
,而是指定預期的安全概念。
- Tink 採用「金鑰組」的概念,也就是
與特定基元相關聯這會導致使用者編寫程式碼
這項功能適用於多個鍵
- 在 Tink 中,鍵不僅是基礎金鑰內容指定,
加密編譯演算法和所有參數也就是說
Tink 金鑰一律會從所有可能類型中選取不重複的加密函式
函式可以存在,且沒有空間可解讀。
下列各節將詳細說明這些概念。
加密編譯的靈活性
考慮 Google 軟體工程團隊。
我們探討了在軟體工程領域學到的教訓
副標題:「隨著時間的推移而學習到的課程」。在這個例子中,作者會前往
大量時間去暗示改變世界的意味。這個
也影響了大部分的 Tink 設計。以密碼編譯技術來說
做好萬全準備金鑰會外洩,演算法也會損毀。
對許多使用者而言,更換金鑰和演算法至關重要。
非常謹慎
安全性審查和本地資產
Tink 推廣介面的使用,例如 AEAD 介面
讓使用者加密資料。還包括其他安全保證、AEAD
可保證相同字串的多種加密會產生不同的
密文。
為了瞭解該怎麼運用,假設工程師想要儲存一些
加入使用者 Cookie 中的 ID他們可能會提供以下類別:
class IdEncrypter {
public static IdEncrypter createFromAead(Aead aead);
public String encrypt(long id) throws GeneralSecurityException;
public long decrypt(String encrypted) throws GeneralSecurityException;
};
傳遞 Aead
可取得下列屬性:
- 程式碼表示,
IdEncrypter
可以執行工作,這需要
具有 Aead
提供的安全性屬性加密配置。
此外,
DeterministicAead
敬上
則不足以因應此情況,因為 IdEncrypter
規定
不同的 ID另一方面,將 當做參數
AES GCM 加密工具 (Aead
的特定例項) 會過度
嚴格:任何 Aead 都足以讓 IdEncrypter
完成工作,但沒有得到
則只需要使用一個特定演算法即可
- 安全性審查可以考慮這點。安全性審查人員
不必執行整個程式碼存放區
某個人建立的
Aead
子類別並不安全,
IdEncrypter
。Tink 會提供安全性屬性
Aead 物件具有 且審查者可以確認這些物件是否足夠。
特別是第二點需要格外小心。使用者通常會要求新增
「並未完全」Aead
。上一個要點說明
這不安全:如果有 Aead
的任何實作可用的,而
未提供必要的安全保證,IdEncrypter
可能會不安全,
執行安全性審查的工程師需要檢查額外的程式碼
檢查物件是否已正確例項化
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-25 (世界標準時間)。
[null,null,["上次更新時間:2025-07-25 (世界標準時間)。"],[[["\u003cp\u003eTink is an open-source cryptography library designed for easy and secure implementation of common cryptographic tasks, even for users without a cryptography background.\u003c/p\u003e\n"],["\u003cp\u003eTink prioritizes security by adding protections on top of existing libraries like BoringSSL, using distinct APIs for potentially risky operations, and ensuring ciphertext compatibility with other libraries.\u003c/p\u003e\n"],["\u003cp\u003eTink promotes cryptographic agility by enabling easy key and algorithm changes, and it supports integration with external key management systems like Amazon KMS and Google Cloud KMS.\u003c/p\u003e\n"],["\u003cp\u003eDesigned with security reviews in mind, Tink utilizes interfaces with clear security guarantees and the concept of keysets for enhanced security and code clarity.\u003c/p\u003e\n"],["\u003cp\u003eGoogle, Square, and Citadel are among the many companies that utilize Tink, further demonstrating its reliability and widespread adoption within various applications and systems.\u003c/p\u003e\n"]]],["Tink, a Google-developed open-source cryptography library, simplifies secure cryptographic implementation for users, even without cryptography expertise. It's designed for simplicity, security, and compatibility, supporting key rotation and external Key Management Systems (KMS). Tink prioritizes cryptographic agility, enabling easy key and algorithm changes, and facilitates security reviews by providing clear interfaces and security guarantees. It uses primitives, keysets, and comprehensive key specifications to achieve these goals, ensuring secure, verifiable, and adaptable cryptographic operations.\n"],null,["# What is Tink?\n\nTink is an open-source cryptography library written by cryptographers and\nsecurity engineers at Google. Tink's secure and simple APIs reduce common\npitfalls through user-centered design, careful implementation and code reviews,\nand extensive testing. See the [Goals](#tink_goals) section on this page for\nmore insight into which objectives Tink was designed to fulfil.\n\nTink helps users without a cryptography background safely implement common\ncryptographic tasks. At Google, Tink has been deployed in hundreds of products\nand systems.\n\nWhy should I use Tink?\n----------------------\n\nThe most important reasons to use Tink are:\n\n- **It's simple to use**\n\n Cryptography is difficult to get right. With Tink, you can\n [encrypt](/tink/encrypt-data) or [sign data](/tink/digitally-sign-data) with\n built-in security guarantees using just a few lines of code. Tink can also\n help you rotate keys or secure keys using external Key Management Systems\n (KMSs).\n- **It's secure**\n\n Tink adds security protections on top of well known libraries like BoringSSL\n and Java Cryptography Architecture and shows them right in the interfaces,\n so auditors and tools can quickly find gaps. Tink also separates APIs that\n are potentially dangerous, so you can monitor them.\n- **It's compatible**\n\n Tink ciphertexts are compatible with existing cryptography libraries. Tink\n also supports [encrypting or storing keys](/tink/client-side-encryption) in\n Amazon KMS, Google Cloud KMS, Android Keystore, and iOS Keychain.\n\nWho's using Tink?\n-----------------\n\nTink is widely used by many companies, including Google, Square, and Citadel, as\nwell as hundreds of Google Cloud customers and Google Pay partners. Tink also\npowers the Jetpack Security library, which secures many popular Android apps\nlike Slack, Adidas, AirBnb, and Nextdoor.\n\nTink Goals\n----------\n\nWhat are the main goals of Tink compared to other cryptographic libraries, and\nwhat are the main mechanisms which Tink uses to achieve these goals?\n\nIn short, Tink has two goals:\n\n1. *Promote cryptographic agility*: Users should be able to change keys and algorithms in a simple way.\n2. *Enable security reviews*: Tink aims to allow users to write code whose security can be reviewed locally, by providing interfaces which give clear security guarantees.\n\nThe main mechanisms Tink uses to achieve these goals are as follows:\n\n1. Tink provides primitives and interfaces as important abstractions. These abstractions allow users to write code which does not specify the exact algorithm to be used, but instead specifies the expected security notion.\n2. Tink uses the notion of a \"keyset\", which is a set of keys that are associated with a particular primitive. This results in users writing code which works with multiple keys.\n3. In Tink, keys are not only specified by the underlying key material, but also the cryptographic algorithm, as well as all parameters. This means that a Tink key always selects a unique cryptographic function from all possible functions which can exist, and leaves no room for interpretation.\n\nThe following sections explain these concepts in more detail.\n\n### Cryptographic agility\n\nConsider [Software Engineering at Google](https://abseil.io/resources/swe-book),\na book about lessons learned in the field of software engineering, with the\nsubtitle \"lessons learned from programming over time\". In it, the authors go to\ngreat lengths to implore the implications of the fact that things change. This\nfact also impacted much of the design of Tink. In cryptography, it is important\nthat one prepares for change. Keys will leak, and algorithms will be broken.\nBeing able to switch out keys and algorithms is crucial for many users, and\nbeing prepared is prudent.\n\n### Security reviews and local properties\n\nTink promotes the use of interfaces, such as our AEAD interface, which allows\nusers to encrypt data. Among [other security guarantees](https://developers.google.com/tink/aead#security_guarantees), an AEAD\nguarantees that multiple encryptions of the same string result in different\nciphertexts.\n\nTo see how this can be used, suppose an engineer wants to store some sensitive\nID in a user cookie. They might provide a class such as this: \n\n class IdEncrypter {\n public static IdEncrypter createFromAead(Aead aead);\n\n public String encrypt(long id) throws GeneralSecurityException;\n public long decrypt(String encrypted) throws GeneralSecurityException;\n };\n\nPassing an `Aead` obtains the following properties:\n\n1. The code communicates that for `IdEncrypter` to do its job, it requires an encryption scheme with the security properties an [`Aead` provides](https://developers.google.com/tink/aead#security_guarantees). Alternatively, a [`DeterministicAead`](https://developers.google.com/tink/deterministic-aead) wouldn't be enough -- the `IdEncrypter` requires that two encryptions of the same id are different. On the other hand, taking as parameter an instance of an AES GCM encrypter (one particular instance of an `Aead`) would be overly strict: any Aead is enough for `IdEncrypter` to do its job, and it does not need to be one specific algorithm.\n2. A security review can take this point into account. A security reviewer does not need to go through all of the entire code repository to check if somewhere, someone made a subclass of `Aead` which is not secure for use with `IdEncrypter`. Instead, Tink provides security properties which all Aead objects have, and the reviewer can check that these are sufficient.\n\nIn particular the second point requires a lot of care. Users often ask to add\nalgorithms which are 'not quite' an `Aead`. The previous point illustrates why\nthis is dangerous: if there is any implementation of `Aead` available which does\nnot provide the required security guarantees, `IdEncrypter` can become insecure,\nand the engineer performing a security review needs to examine additional code\nto check that the object is instantiated correctly."]]