[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-18。"],[],[],null,["# Additional authenticated data (AAD) is any string that you pass to\nCloud Key Management Service as part of an encrypt or decrypt request. AAD is used as an\nintegrity check and can help protect your data from a\n[*confused deputy attack*](https://en.wikipedia.org/wiki/Confused_deputy_problem). The AAD string must be no larger than 64 KiB.\n\nCloud KMS will not decrypt ciphertext unless the same AAD value is\nused for both encryption and decryption.\n\nAAD is bound to the encrypted data, because you cannot decrypt the ciphertext\nunless you know the AAD, but it is not stored as part of the ciphertext. AAD also\ndoes not increase the cryptographic strength of the ciphertext. Instead it is an\nadditional check by Cloud KMS to authenticate a decryption request.\n\nIn Cloud KMS, AAD is always present when you make a call to encrypt\nor decrypt - if you do not provide a value for AAD, then an empty string is\nused. If an empty string is used as the AAD for the encryption of plaintext,\nthen only an empty string will allow decryption of the ciphertext.\n\nAAD is not logged by [Cloud Audit Logs](/logging/docs/audit).\n| **Warning:** Ensure that you securely store the AAD, or have the ability to reproduce the AAD, because without the AAD you will not be able to decrypt your ciphertext.\n\nWhen to use AAD\n---------------\n\nOne example of using AAD is when your application serves as a wrap/unwrap proxy\nwith a single key and an unbounded number of clients, with each client in\ndistinct security boundaries. For example, the application could be a diary\napplication that allows users to maintain a private diary. When a user needs to\nview a private diary entry, the application can use the unique user name as the\nAAD in the unwrap (decrypt) request to explicitly authenticate the user. In this\nscenario you can use a single key to serve multiple (unbounded) users. A primary\nbenefit is you don't need to maintain state for individual users.\n\nAnother example is if your application needs to use bearer tokens that contain\nsome private information, such as an email address. Inputs to the bearer token\nwould be the authenticated data used for a bearer token plus the plaintext email\naddress. These inputs would then get encrypted so the bearer token that gets\nexchanged is in the form of [Additional Encrypted Authenticated Data](https://en.wikipedia.org/wiki/Authenticated_encryption) (AEAD).\n\nConfused deputy attack example\n------------------------------\n\nThis example shows how an application could be tricked into decrypting\nciphertext on behalf of a malicious user. The application is the confused deputy\nin this example because the application is unaware the attacker has tricked the\napplication into misusing its authority. The result is the attacker is able to\nview decrypted data that originally was encrypted for another user. Note in this\nattack, the attacker does not need to know the encryption key, because it relies\non the confused deputy to perform the decryption.\n\n1. A diary application allows users to maintain a private diary. Each diary\n entry is encrypted and intended to be decrypted only by the user that created\n the diary entry.\n\n2. Alice creates a diary entry. The application encrypts the diary entry and\n then stores the encrypted diary entry at a location reserved for diary entries\n that belong to Alice.\n\n3. Alice sends a request to view her diary entry. Because the encrypted diary\n entry is at a location reserved for Alice, the application decrypts the data and\n returns it as the response to Alice's request. This is the intended behaviour of\n the application.\n\n4. Mallory copies Alice's diary entry from the location reserved for Alice\n to the location reserved for Mallory.\n\n5. Mallory sends a request to view Mallory's copy of Alice's diary entry.\n Because the copy of Alice's diary entry is at a location reserved for Mallory,\n the application decrypts the diary entry and returns the plaintext as the\n response to Mallory's request. Mallory can then view Alice's diary entry, which\n is not the intended behaviour of the application.\n\nTo defend against this type of attack, the application can use a non-empty\nstring as AAD for encryption and decryption. The AAD provides an extra\ncheck for decryption requests. When Mallory sends the decryption request to view\nMallory's copy of Alice's diary entry, Mallory's request will not succeed unless\nMallory can also trick the application into using the correct AAD.\n\nStoring or reproducing AAD\n--------------------------\n\nBefore encrypting with AAD, decide whether you will *store* the AAD side-by-side\nwith the encrypted data, or *reproduce* the AAD, for subsequent decryption.\n\nA reason to store AAD is to make it straightforward to use the AAD when you need\nto decrypt ciphertext. For example, a database row could contain both the\nciphertext and the AAD used when the plaintext was encrypted. When a decrypt\nrequest is received, the application can retrieve both the AAD and the\nciphertext from the database. The application can then use the AAD for the\nciphertext decryption process.\n\nA reason to reproduce AAD is to verify any non-private data while also avoiding\nstorage of the AAD. For example, if you want to ensure that the filepath and\nfilename of an encrypted file has not changed, you can include the filepath and\nfilename as AAD when you encrypt the file. Then, when a decrypt request is sent\nfor the file, you can reproduce the AAD by examining the filepath and filename.\n\n### Storing AAD\n\nStoring AAD means AAD is saved and then readily available by your application\nfor future use. For example, a database table could contain a column for\nciphertext and a column for the AAD used when the ciphertext was created. When\nit is time to decrypt the ciphertext, the application retrieves the AAD and uses\nit for the decryption.\n| **Warning:** If you store AAD, ensure that you keep it secure.\n\nConsider a diary application that is designed to show a diary entry only to the\nuser that created it. When a diary entry is created, it is encrypted and then\nsaved to a database, in column `ENCRYPTED_DIARY_ENTRY`. For each request to view\na diary entry, the application authenticates the user and then provides the\ndiary entry to the user.\n\nSuppose no AAD is used (other than the default empty string) and hypothetically\nMallory was able to copy Alice's `ENCRYPTED_DIARY_ENTRY` data to Mallory's\n`ENCRYPTED_DIARY_ENTRY` data. When Mallory sends a decrypt request for Mallory's\n`ENCRYPTED_DIARY_ENTRY` data (which was copied from Alice's data), the\napplication performs the decryption without realizing it has been tricked.\nMallory is able to see Alice's diary entry as plaintext.\n\nNow let's suppose the user email address is used as the AAD when a diary entry\nis encrypted. When Alice creates a diary entry, the application stores her\nunencrypted email address in the column `EMAIL`, side-by-side with the\n`ENCRYPTED_DIARY_ENTRY` data. Let's suppose again that Mallory was able to copy\nAlice's `ENCRYPTED_DIARY_ENTRY` data to Mallory's `ENCRYPTED_DIARY_ENTRY` data.\nWhen Mallory sends a decrypt request, the application retrieves Mallory's email\naddress from the `EMAIL` column to use as the AAD for the decrypt request.\nMallory's email address will not succeed as the AAD for decryption, so the\napplication does not let Mallory see Alice's diary entry as plaintext.\n\n### Reproducing AAD\n\nReproducing AAD means it isn't stored anywhere, but you can reproduce when it is\ntime for decryption.\n| **Warning:** If you do not store the AAD and you cannot reproduce the AAD, you will not be able to decrypt the ciphertext.\n\nAs an example, you can use a filepath and filename as AAD. During the encryption\nprocess, suppose the encrypted file was saved to `MY_PATH\\MY_FILE1.enc`, so\n`\"MY_PATH\\MY_FILE1.enc\"` was used as the AAD. This AAD is not stored. When a\ndecrypt request is received, the application reproduces the AAD by examining the\nfilepath and filename of the file to decrypt. If the encrypted file has not been\nmoved to another location, `\"MY_PATH\\MY_FILE1.enc\"` will be used as the AAD\nduring decryption, which is the same as the AAD used during encryption, so the\ndecryption can proceed.\n\nIf the encrypted file has been moved, for example to\n`SOME_OTHER_PATH\\MY_FILE1.enc`, then `\"SOME_OTHER_PATH\\MY_FILE1.enc\"` will be\nused as the AAD for decryption. This AAD value does not match the AAD value used\nfor encryption, so the decryption will fail."]]