[[["易于理解","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,["# Using gRPC with Cloud KMS\n\nIf you are using manually created [gRPC](https://grpc.io/) libraries to make calls to\nCloud Key Management Service, you must specify a `x-google-request-params` value in\nthe metadata, or header, of the call. The proper use of\n`x-google-request-params` will route the call to the appropriate region for\nyour Cloud KMS resources.\n\nSet the `x-google-request-params` value to a field in the method's request as\nshown in the following table.\n\nSetting the request field\n-------------------------\n\nThe following examples show where to specify the resource name in various\nmethods. Replace the text styled as \u003cvar translate=\"no\"\u003eplace-holder\u003c/var\u003e with the\nactual values used in your Cloud KMS resource IDs.\n\n### Decrypt example\n\nIf you are making a call to [Decrypt](/kms/docs/reference/rpc/google.cloud.kms.v1#google.cloud.kms.v1.KeyManagementService.Decrypt), you need to populate the following\nfields in your request: \n\n```\nname: 'projects/project-id/locations/location/keyRings/key-ring/cryptoKeys/key-name/'\nciphertext: 'iQALWM/r6alAxQm0VQe3...'\n```\n\nThe value assigned to the `name` field is the resource name of your CryptoKey.\nTo properly route the call, you must also include this resource name in the\ncall metadata, in the following form: \n\n```\nx-goog-request-params: 'name=projects/project-id/locations/location/keyRings/key-ring/cryptoKeys/key-name/'\n```\n\n### CreateKeyRing example\n\nIf you are making a call to [CreateKeyRing](/kms/docs/reference/rpc/google.cloud.kms.v1#google.cloud.kms.v1.KeyManagementService.CreateKeyRing), you need to populate the\nfollowing fields in your request: \n\n```\nparent: 'projects/project-id/locations/location/'\nkey_ring_id: 'myKeyRing'\n...\n```\n\nThe call metadata also needs to contain the `parent` resource name: \n\n```\nx-goog-request-params: 'parent=projects/project-id/locations/location/'\n```\n\n### UpdateCryptoKey example\n\nIf you are making a call to [UpdateCryptoKey](/kms/docs/reference/rpc/google.cloud.kms.v1#google.cloud.kms.v1.KeyManagementService.UpdateCryptoKey), you need to populate the\nfollowing fields in your request: \n\n```\nname: 'projects/project-id/locations/location/keyRings/key-ring/cryptoKeys/key-name/'\nfield_mask: ...\n```\n\nThe metadata also needs to contain the `name` resource name. Note the format\nuses `crypto_key.name=`, not `name=`: \n\n```\nx-goog-request-params: 'crypto_key.name=projects/project-id/locations/location/keyRings/key-ring/cryptoKeys/key-name/'\n```\n\nAdding metadata using C++\n-------------------------\n\nIf you are using C++, call `ClientContext::AddMetadata` before making your RPC\ncall to add the appropriate information to the call metadata.\n\nFor example, if you are adding metadata for a call to [Decrypt](/kms/docs/reference/rpc/google.cloud.kms.v1#google.cloud.kms.v1.KeyManagementService.Decrypt): \n\n```\ncontext.AddMetadata(\"x-goog-request-params\",\n \"name=projects/project-id/locations/location/keyRings/key-ring-name/cryptoKeys/key-name/\");\n```\n\nYou can then pass the context to your method call as usual, along with your\nrequest and response protocol buffers."]]