Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Nesta página, descrevemos como usar checksums para manter e verificar a integridade dos dados do seu secret ao adicionar e acessar versões dele.
Pense em um checksum como uma impressão digital exclusiva dos seus dados. É um código curto gerado com base nos dados secretos usando o algoritmo CRC32C. Se até mesmo um único bit nos seus dados secretos mudar, o checksum também vai mudar. Isso permite que o Secret Manager detecte modificações ou corrupções acidentais.
O Secret Manager usa checksums das seguintes maneiras:
Ao adicionar uma versão do secret:
O Secret Manager calcula a soma de verificação CRC32C dos seus dados secretos.
Essa soma de verificação é armazenada com os dados secretos.
Ao acessar uma versão do secret:
O Secret Manager retorna os dados secretos com a soma de verificação.
Use essa soma de verificação para verificar se os dados recebidos são exatamente iguais aos armazenados no Secret Manager.
Para garantir que a soma de verificação seja compatível com a estrutura SecretPayload, a soma de verificação dos dados secretos precisa ser calculada usando o algoritmo CRC32C e codificada como um número inteiro decimal. A resposta SecretVersion inclui um campo que indica se o servidor recebeu e validou a soma de verificação.
O exemplo a seguir mostra como os checksums funcionam no Secret Manager:
Com os dados secretos armazenados em um arquivo de dados, calcule o checksum usando gcloud storage hash.
O checksum precisa ser convertido para o formato decimal. Ele é codificado como int64 no proto SecretPayload.
$ gcloud storage hash "/path/to/file.txt" --hex
Com os dados secretos transmitidos na linha de comando, calcule o checksum da seguinte maneira:
No console, quando você
adiciona uma versão do secret,
o checksum é calculado automaticamente quando você insere um valor para o secret.
As versões secretas criptografadas com chaves de criptografia gerenciadas pelo cliente (CMEK) e
criadas antes de 16 de julho de 2021 não têm checksums armazenados.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-03 UTC."],[],[],null,["# Data integrity assurance\n\nThis page describes how to use checksums to maintain and verify the integrity of your secret's data\nwhen [adding](/secret-manager/docs/add-secret-version) and\n[accessing](/secret-manager/docs/access-secret-version) secret versions.\n\nThink of a checksum as a unique fingerprint for your data. It's a short code generated from the\nsecret data using the CRC32C algorithm. If even a single bit in your\nsecret data changes, the checksum also changes. This lets Secret Manager detect any accidental\nmodifications or corruption.\n\nSecret Manager uses checksums in the following ways:\n\n1. When you add a secret version:\n\n - Secret Manager calculates the CRC32C checksum of your secret data.\n\n - This checksum is stored along with the secret data.\n\n2. When you access a secret version:\n\n - Secret Manager returns the secret data along with its checksum.\n\n - You can use this checksum to verify that the data you received is exactly the same\n as the data stored in Secret Manager.\n\nTo ensure that the checksum is compatible with the [SecretPayload](/secret-manager/docs/reference/rpc/google.cloud.secretmanager.v1#secretpayload)\nstructure, the checksum of the secret data must be calculated using the CRC32C algorithm and encoded\nas a decimal integer. The [SecretVersion](/secret-manager/docs/reference/rest/v1/projects.secrets.versions#SecretVersion.FIELDS)\nresponse includes a field indicating whether the server has successfully received and validated this\nchecksum.\n\nThe following example shows how checksums work in Secret Manager: \n\n### API\n\nThese examples use [curl](https://curl.haxx.se/) to demonstrate using the API. You can generate [access tokens](/iam/docs/creating-short-lived-service-account-credentials) with gcloud auth print-access-token.\nOn Compute Engine or GKE, you must\n[authenticate with the cloud-platform scope](/secret-manager/docs/accessing-the-api#oauth-scopes).\n\nWith secret data stored in a data file, calculate the checksum,\nusing [gcloud storage hash](/sdk/gcloud/reference/storage/hash).\nChecksum must be converted to decimal format; it is encoded as int64 in SecretPayload proto. \n\n```\n$ gcloud storage hash \"/path/to/file.txt\" --hex\n```\n\nWith secret data passed on the command line, calculate the checksum as follows: \n\n```\n$ gcloud storage hash --hex cat \u003c(echo ${SECRET_DATA})\n```\n\nBase64-encode the secret data and save it as a shell variable. \n\n```\n$ SECRET_DATA=$(echo \"seCr3t\" | base64)\n```\n\nInvoke the API using curl. \n\n```\n$ curl \"https://secretmanager.googleapis.com/v1/projects/project-id/secrets/secret-id:addVersion\" \\\n --request \"POST\" \\\n --header \"authorization: Bearer $(gcloud auth print-access-token)\" \\\n --header \"content-type: application/json\" \\\n --data \"{\\\"payload\\\": {\\\"data\\\": \\\"${SECRET_DATA}\\\", \\\"data_crc32c\\\": $CHECKSUM}}\"\n```\n\nWhen the secret version is accessed, the returned\n[SecretPayload](/secret-manager/docs/reference/rpc/google.cloud.secretmanager.v1#secretpayload)\ncontains the data along with its checksum. Following is a sample response: \n\n```gdscript\n{\n \"name\": \"projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/secrets/\u003cvar translate=\"no\"\u003eSECRET_ID\u003c/var\u003e/versions/\u003cvar translate=\"no\"\u003eVERSION_ID\u003c/var\u003e\",\n \"payload\": {\n \"data\": \"YQo=\",\n \"dataCrc32c\": \"163439259\"\n }\n}\n```\n\nIn the console, when you\n[add a secret version](/secret-manager/docs/add-secret-version),\nthe checksum is automatically calculated when you enter a value for the secret.\n\nSecret versions encrypted with customer-managed encryption keys (CMEK) and\ncreated before July 16, 2021 do not have checksums stored.\n\nWhat's next\n-----------\n\n- Learn how to [set up notifications on a secret](/secret-manager/docs/event-notifications).\n- Learn how to [analyze secrets with Cloud Asset Inventory](/secret-manager/docs/analyze-resources)."]]