Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Phương thức gốc Mã hoá đã xác thực với dữ liệu liên kết (AEAD) là phương thức gốc phổ biến nhất để mã hoá dữ liệu và phù hợp với hầu hết các nhu cầu.
AEAD có các thuộc tính sau:
Secrecy: Không có thông tin nào về văn bản thô, ngoại trừ độ dài.
Tính xác thực: Không thể thay đổi văn bản thô đã mã hoá cơ bản của văn bản đã mã hoá mà không bị phát hiện.
Đối xứng: Quá trình mã hoá văn bản thô và giải mã văn bản đã mã hoá được thực hiện bằng cùng một khoá.
Sắp xếp ngẫu nhiên: Phương thức mã hoá được sắp xếp ngẫu nhiên. Hai thông điệp có cùng văn bản thô sẽ tạo ra các văn bản đã mã hoá khác nhau. Kẻ tấn công không thể biết văn bản đã mã hoá nào tương ứng với một văn bản thô nhất định. Nếu muốn tránh điều này, hãy sử dụng AEAD có tính xác định.
Dữ liệu liên quan
Bạn có thể sử dụng AEAD để liên kết văn bản đã mã hoá với dữ liệu liên kết cụ thể. Giả sử bạn có một cơ sở dữ liệu với các trường user-id và encrypted-medical-history. Trong trường hợp này, user-id có thể được dùng làm dữ liệu liên kết khi mã hoá encrypted-medical-history. Điều này giúp ngăn kẻ tấn công chuyển hồ sơ y tế từ người dùng này sang người dùng khác.
Chọn loại khoá
Mặc dù bạn nên sử dụng AES128_GCM cho hầu hết các trường hợp sử dụng, nhưng có nhiều loại khoá cho các nhu cầu khác nhau (để bảo mật 256 bit, hãy thay thế AES128 bằng AES256 bên dưới).
Nhìn chung:
AES128_CTR_HMAC_SHA256 với Vectơ khởi tạo (IV) 16 byte là chế độ bảo thủ nhất với các giới hạn tốt.
AES128_EAX ít bảo thủ hơn một chút và nhanh hơn một chút so với AES128_CTR_HMAC_SHA256.
AES128_GCM thường là chế độ nhanh nhất, với các giới hạn nghiêm ngặt nhất về số lượng tin nhắn và kích thước tin nhắn. Khi vượt quá các giới hạn này về văn bản thô và chiều dài dữ liệu liên kết (dưới đây), AES128_GCM sẽ không thành công và rò rỉ tài liệu khoá.
AES128_GCM_SIV gần như nhanh như AES128_GCM. Phương thức này có các giới hạn giống như AES128_GCM về số lượng và kích thước thông báo, nhưng khi vượt quá các giới hạn này, phương thức này sẽ không thành công theo cách ít nghiêm trọng hơn: phương thức này có thể chỉ rò rỉ thực tế là hai thông báo bằng nhau. Điều này giúp bạn sử dụng an toàn hơn so với AES128_GCM, nhưng phương thức này ít được sử dụng rộng rãi hơn trong thực tế.
Để sử dụng tính năng này trong Java, bạn phải cài đặt Conscrypt.
XChaCha20Poly1305 có giới hạn lớn hơn nhiều về số lượng tin nhắn và kích thước tin nhắn so với AES128_GCM, nhưng khi không thành công (rất khó xảy ra), phương thức này cũng rò rỉ tài liệu khoá. Chế độ này không được tăng tốc phần cứng, do đó, có thể chậm hơn các chế độ AES trong trường hợp có thể tăng tốc phần cứng.
Cam kết bảo mật
Các phương thức triển khai AEAD cung cấp:
Bảo mật CCA2.
Độ mạnh của chế độ xác thực tối thiểu là 80 bit.
Khả năng mã hoá ít nhất 232 thư với tổng số 250 byte. Không có cuộc tấn công nào với tối đa 232 văn bản thuần tuý hoặc văn bản đã mã hoá được chọn có xác suất thành công lớn hơn 2-32.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-25 UTC."],[[["\u003cp\u003eAuthenticated Encryption with Associated Data (AEAD) is the recommended primitive for most data encryption needs, providing secrecy, authenticity, and randomization.\u003c/p\u003e\n"],["\u003cp\u003eAEAD utilizes the same key for encryption and decryption, and randomizes the encryption process for enhanced security, although deterministic options are available.\u003c/p\u003e\n"],["\u003cp\u003eWhile AES128_GCM is generally the fastest and recommended key type, other options like AES128_CTR_HMAC_SHA256, AES128_EAX, AES128_GCM_SIV, and XChaCha20Poly1305 cater to specific security and performance requirements.\u003c/p\u003e\n"],["\u003cp\u003eAssociated data used in AEAD is authenticated but not encrypted, meaning it can be verified but is still visible.\u003c/p\u003e\n"],["\u003cp\u003eAEAD implementations provide strong security guarantees, including CCA2 security and at least 80-bit authentication strength, but do not guarantee the secrecy of associated data.\u003c/p\u003e\n"]]],["AEAD, a common data encryption primitive, ensures secrecy, authenticity, and uses symmetric keys with randomized encryption. Associated data is authenticated but not encrypted and can link ciphertext to specific contexts, like user IDs. Various key types are available, with AES128_GCM recommended for most cases, offering speed but with strict limits. AES128_GCM_SIV is a safer, albeit less common, alternative. AEAD guarantees CCA2 security and 80-bit authentication strength, encrypting up to 2^32 messages with 2^50 total bytes.\n"],null,["# Authenticated Encryption with Associated Data (AEAD)\n\nThe Authenticated Encryption with Associated Data (AEAD) primitive is the most\ncommon primitive for data encryption and is suitable for most needs.\n\nAEAD has the following properties:\n\n- **Secrecy**: Nothing about the plaintext is known, except its length.\n- **Authenticity**: It is impossible to change the encrypted plaintext underlying the ciphertext without being detected.\n- **Symmetric**: Encrypting the plaintext and decrypting the ciphertext is done with the same key.\n- **Randomization** : Encryption is randomized. Two messages with the same plaintext yield different ciphertexts. Attackers cannot know which ciphertext corresponds to a given plaintext. If you want to avoid this, use [Deterministic AEAD](/tink/deterministic-aead) instead.\n\n### Associated data\n\n| **Caution:** Associated data is authenticated but *NOT* encrypted.\n\nAEAD can be used to [tie ciphertext to specific associated\ndata](/tink/bind-ciphertext). Suppose you have a database with the fields `user-id`\nand `encrypted-medical-history`. In this scenario, `user-id` can be used as\nassociated data when encrypting `encrypted-medical-history`. This prevents an\nattacker from moving medical history from one user to another.\n\n### Choose a key type\n\nWhile we recommend **AES128_GCM** for most uses, there are various key types for\ndifferent needs (for 256-bit security, replace AES128 with AES256 below).\nGenerally:\n\n- AES128_CTR_HMAC_SHA256 with a 16-byte Initialization Vector (IV) is the most conservative mode with good bounds.\n- AES128_EAX is slightly less conservative and slightly faster than AES128_CTR_HMAC_SHA256.\n- AES128_GCM is usually the fastest mode, with the strictest limits on the number of messages and message size. When these limits on plaintext and associated data lengths (below) are exceeded, AES128_GCM fails and leaks key material.\n- AES128_GCM_SIV is nearly as fast as AES128_GCM. It has the same limits as AES128_GCM on the number of messages and message size, but when these limits are exceeded, it fails in a less catastrophic way: it may only leak the fact that two messages are equal. This makes it safer to use than AES128_GCM, but it is less widely used in practice. To use this in Java, you have to install [Conscrypt](https://conscrypt.org).\n- XChaCha20Poly1305 has a much greater limit on the number of messages and message size than AES128_GCM, but when it does fail (very unlikely) it also leaks key material. It isn't hardware accelerated, so it can be slower than AES modes in situations where hardware acceleration is available.\n\n| **Note:** The plaintext and associated data may have any length within 0..2^32^ bytes.\n\n### Security guarantees\n\nAEAD implementations offer:\n\n- CCA2 security.\n- At least 80-bit authentication strength.\n- The ability to encrypt at least 2^32^ messages with a total of 2^50^ bytes. No attack with up to 2^32^ chosen plaintexts or chosen ciphertexts has success probability larger than 2^-32^.\n\n| **Caution:** **AEAD offers no secrecy guarantees for associated data.**\n\n### Example use cases\n\nSee I want to [encrypt data](/tink/encrypt-data) and I want to [bind ciphertext to\nits context](/tink/bind-ciphertext)."]]