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.
Các API Tink lấy các blob nhị phân tuỳ ý làm dữ liệu đầu vào. Điều này có nghĩa là nếu bạn muốn
mã hoá dữ liệu có cấu trúc, như
bộ đệm giao thức, bạn cần
mã hoá dữ liệu trước.
Mã hoá một protobuf
Cách mã hoá:
Tuần tự hoá protobuf thành một mảng byte.
Mã hoá các byte được chuyển đổi tuần tự, sau đó lưu trữ hoặc gửi bản mã hoá thu được.
Sử dụng:
Lưu trữ các byte được chuyển đổi tuần tự cùng với chữ ký (hoặc MAC).
Để xác minh:
Lấy protobuf được chuyển đổi tuần tự và chữ ký của protobuf đó (hoặc MAC).
Xác minh chữ ký (hoặc MAC).
Giải tuần tự protobuf.
Lưu ý rằng chữ ký hoặc MAC hợp lệ không đảm bảo rằng dữ liệu chính xác
đã định dạng. Việc triển khai phân tích cú pháp dữ liệu phải luôn dự kiến rằng
dữ liệu của bạn có thể bị hỏng.
Bảo vệ nhiều mục dữ liệu
Để bảo vệ nhiều mục dữ liệu, hãy sử dụng phương thức chuyển đổi tuần tự. Thêm tất cả dữ liệu
mục với một protobuf và mã hoá (hoặc xác thực) nó như mô tả ở trên.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-25 UTC."],[[["\u003cp\u003eTink APIs accept arbitrary binary data as input, requiring serialization of structured data like Protocol Buffers before encryption.\u003c/p\u003e\n"],["\u003cp\u003eTink provides various encryption methods like AEAD, hybrid encryption, and deterministic AEAD to secure serialized data.\u003c/p\u003e\n"],["\u003cp\u003eTink supports data integrity through digital signatures and MACs, but verification doesn't guarantee data formatting.\u003c/p\u003e\n"],["\u003cp\u003eProtecting multiple data items involves serialization, preferably using Protocol Buffers or length-prefixed concatenation, followed by encryption or authentication.\u003c/p\u003e\n"]]],["Tink API handles binary blobs, requiring structured data like protocol buffers to be encoded first. To encrypt a protobuf, serialize it to bytes, then encrypt using AEAD, hybrid, or deterministic AEAD methods. Decryption involves decrypting the ciphertext and deserializing the protobuf. To protect from tampering, serialize, then sign or authenticate using digital signature or MAC, storing the signature with the data, verifying the signature before deserializing. Protecting multiple items requires serialization via a protobuf or a length-prefixed method, followed by encryption or authentication.\n"],null,["# I want to protect structured data\n\nTink APIs take arbitrary binary blobs as input. This means that if you want to\nencrypt structured data, like\n[protocol buffers](https://developers.google.com/protocol-buffers), you need to\nencode the data first.\n\nEncrypt a protobuf\n------------------\n\nTo encrypt:\n\n1. Serialize the protobuf to a byte array.\n2. Encrypt the serialized bytes, then store or send the resulting ciphertext. Use:\n - [Authenticated encryption with associated data (AEAD)](/tink/aead)\n - [Hybrid encryption](/tink/hybrid)\n - [Deterministic AEAD](/tink/deterministic-aead)\n\nTo decrypt:\n\n1. Decrypt the ciphertext.\n2. If Step 1 was successful, deserialize the protobuf.\n\nProtect a protobuf from tampering\n---------------------------------\n\nIn most cases, encrypting a protobuf is preferable to authentication alone.\n\nTo protect a protobuf from tampering:\n\n1. Serialize the protobuf to a byte array.\n2. Sign or authenticate the serialized bytes. Use:\n - [Digital signature](/tink/digital-signature)\n - [MAC](/tink/mac)\n3. Store the serialized bytes together with the signature (or MAC).\n\nTo verify:\n\n1. Get the serialized protobuf and its signature (or MAC).\n2. Verify the signature (or MAC).\n3. Deserialize the protobuf.\n\nNote that a valid signature or MAC does not guarantee that the data is correctly\nformatted. An implementation that parses the data should always expect that the\ndata might be corrupt.\n\nProtect multiple data items\n---------------------------\n\nTo protect multiple data items, use a serialization method. Add all of the data\nitems to a protobuf, and encrypt (or authenticate) it as described above.\n\nYou can also serialize as follows: \n\n serialize(data1 , data2 , ..., datan) = 4-byte-data1's length || data1 || 4-byte-data2's length || data2 || ... || 4-byte-dataN's length || dataN\n\n| **Warning:** Concatenating without a length prefix, like `data1 || data2 || ... || dataN`, can lead to vulnerabilities as the resulting encoding is ambiguous. For example if `data1 = \"foo\"` and `data2 = \"bar\"`, this would lead to the same encoded data as `data1 = \"fooba\"` and `data2 = \"r\"`.\n\nFinally, encrypt (or authenticate) the resulting byte array."]]