Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
In diesem Thema wird beschrieben, wie Sie Ihre Schlüssel formatieren, damit sie von Cloud KMS als neue Schlüsselversionen importiert werden können.
Welches Format für das Schlüsselmaterial verwendet werden muss, hängt davon ab, ob das Schlüsselmaterial in einen symmetrischen oder in einen asymmetrischen Schlüssel importiert wird. Weitere Informationen zum Unterschied zwischen symmetrischen und asymmetrischen Schlüsseln finden Sie unter Schlüsselzwecke und -algorithmen.
Unterstützte Schlüsselformate
Symmetrische Schlüssel für die Verschlüsselung:
Importierte symmetrische Schlüssel müssen 16 Byte (nur für rohe symmetrische Verschlüsselung) oder 32 Byte Binärdaten umfassen und dürfen nicht codiert sein.
Wenn Ihr Schlüssel hex- oder base64-codiert ist, müssen Sie ihn vor dem Import entschlüsseln.
Symmetrische Schlüssel zum Signieren (MAC-Schlüssel): Importierte HMAC-Signaturschlüssel müssen eine Länge haben, die der Ausgabelänge der verwendeten kryptografischen Hash-Funktion entspricht (z. B. HMAC-SHA256-Schlüssel müssen eine Länge von 32 Byte haben) und dürfen nicht codiert sein. Wenn Ihr Schlüssel hex- oder base64-codiert ist, müssen Sie ihn vor dem Import entschlüsseln.
Asymmetrische Schlüssel für die Verschlüsselung oder Signatur: Importierte asymmetrische Schlüssel müssen im PKCS #8-Format vorliegen und DER-codiert sein. Das PCKS #8-Format ist in RFC 5208 definiert. Die DER-Codierung ist in der International Telecommunications Union X.680 definiert. Asymmetrische Schlüssel müssen eine der von Cloud KMS unterstützten Längen- und Algorithmuskombinationen verwenden.
Einige Aspekte eines Schlüssels, z. B. die Länge des Schlüssels, können nach der Erstellung des Schlüssels nicht mehr geändert werden. In diesen Fällen kann der Schlüssel nicht in Cloud KMS importiert werden.
Einen symmetrischen Schlüssel überprüfen
Mit dem Befehl wc können Sie die Länge eines symmetrischen Schlüssels überprüfen.
wc -c /path/to/unwrapped-key
Einen symmetrischen Verschlüsselungschlüssel mit einer anderen Länge als 32 können Sie nicht importieren.
Symmetrische Signaturschlüssel (MAC-Schlüssel) müssen eine Länge haben, die der Ausgabelänge der verwendeten kryptografischen Hash-Funktion entspricht (Beispiel: HMAC-SHA256-Schlüssel müssen eine Länge von 32 Byte haben).
Prüfen Sie das Format eines Schlüssels mit dem Befehl file.
file /path/to/unwrapped-key
Wenn die Ausgabe data lautet, hat der Schlüssel das richtige Format für den Import.
Wenn die Ausgabe ASCII text ist, zeigen Sie mit dem Befehl cat den Inhalt der Datei an.
Wenn es sich um eine Zeichenfolge aus Buchstaben und Zahlen handelt, die mit einem =-Zeichen endet, ist sie möglicherweise base64-codiert. Verwenden Sie den Befehl base64 (Base64.exe unter Windows), um ihn zu decodieren. Das folgende Beispiel zeigt einen base64-codierten Schlüssel:
THzArjassB+giKeNeT1Zr74OgV24t+Ep+37Ec6ojB3Y=
Wenn sie eine oder mehrere Zeilen mit Hexadezimalzahlen enthält, ist sie möglicherweise Hex-codiert. Verwenden Sie zum Decodieren den Befehl xxd (oder den Format-Hex PowerShell-Befehl unter Windows). Das folgende Beispiel zeigt einen Hex-codierten Schlüssel:
Wenn er einen anderen Text enthält, ist er möglicherweise kein gültiger symmetrischer Schlüssel.
Asymmetrische Schlüssel formatieren
Asymmetrische Schlüssel, die einen der unterstützten Algorithmen verwenden, können importiert werden. In der Praxis ist es schwierig, rückwirkend den Algorithmus zu ermitteln, der zum Erstellen eines asymmetrischen Schlüssels verwendet wird. Aus diesem Grund empfehlen wir, die folgenden Befehle für jeden asymmetrischen Schlüssel auszuführen, bevor Sie versuchen, ihn in Cloud KMS zu importieren.
Prüfen Sie das Format eines Schlüssels mit dem Befehl file.
file /path/to/unwrapped-key
Wenn die Ausgabe PEM ist, liegt der Schlüssel im PEM-Format vor. Wenn es sich um ASCII text handelt, liegt er wahrscheinlich im PEM-Format vor. Führen Sie in beiden Fällen den folgenden Befehl aus, um sie in das PCKS#8 DER-Format zu konvertieren:
Wenn die Ausgabe data ist, liegt der Schlüssel wahrscheinlich im DER-Format vor, aber möglicherweise nicht im PKCS #8-Format. Führen Sie den folgenden Befehl aus, um sicherzustellen, dass der Schlüssel das richtige Format hat. Der Befehl hat keine Auswirkungen, wenn der Schlüssel bereits im richtigen Format vorliegt. In diesem Fall können Sie mit dem Befehl diff überprüfen, ob die Ein- und Ausgabedatei identisch sind.
openssl pkcs8 -topk8 -nocrypt -inform DER -outform DER \
-in /path/to/asymmetric-key-der \
-out /path/to/formatted-key
Fehlerbehebung
Wenn Sie die oben genannten Befehle ausführen und meinen, dass der Schlüssel in einem geeigneten Format vorliegt, der Import jedoch weiterhin fehlschlägt, überprüfen Sie in der Google Cloud Console auf Fehler und lesen Sie den Hilfeartikel Fehlerbehebung bei fehlgeschlagenen Importen.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-09-05 (UTC)."],[],[],null,["# Formatting keys for import\n\nThis topic describes how to format your keys so that they can be imported by\nCloud KMS as new key versions.\n\nThe correct format for your key material varies based on whether the key\nmaterial is being imported into a symmetric key, or into an asymmetric key. For\nmore information about the difference between symmetric and asymmetric keys, see\n[Key purposes and algorithms](/kms/docs/algorithms).\n\nSupported key formats\n---------------------\n\n- **Symmetric keys for encryption** : Imported symmetric keys must be 16 bytes (for [raw symmetric encryption](/kms/docs/raw-encryption) only) or 32 bytes of binary data, and must *not* be encoded. If your key is hex-encoded or base64-encoded, then you must decode it before attempting to import it.\n- **Symmetric keys for signing (MAC keys)** : Imported HMAC signing keys must have a length equal to the output length of the cryptographic hash function being used (for example, HMAC-SHA256 keys must have a length of 32 bytes), and must *not* be encoded. If your key is hex-encoded or base64-encoded, then you must decode it before attempting to import it.\n- **Asymmetric keys for encryption or signing** : Imported asymmetric keys must be in PKCS #8 format and must be DER-encoded. PCKS #8 format is defined in [RFC 5208](https://tools.ietf.org/html/rfc5208). DER encoding is defined in [International\n Telecommunications Union X.680](https://www.itu.int/rec/T-REC-X.680/en). Asymmetric keys must use one of the [length and algorithm combinations](/kms/docs/algorithms) supported by Cloud KMS.\n\n| **Important:** An RSA key's public exponent must be 65,537 or higher. This is a Digital Signature Standard (DSS) requirement noted in the Criteria for IFC Key Pairs section of [FIPS PUB 186-4](https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.186-4.pdf), Section B.3.1\n\nSome aspects of a key, such as the key's length, cannot be changed after the key\nis created. In these cases, the key cannot be imported into Cloud KMS.\n\nChecking a symmetric key\n------------------------\n\nUse the `wc` command to check a symmetric key's length. \n\n```\nwc -c /path/to/unwrapped-key\n```\n\n- You cannot import a symmetric encryption key with a length other than 32.\n\n- Symmetric signing keys (MAC keys) must have a length equal to the output\n length of the cryptographic hash function being used (e.g. HMAC-SHA256 keys\n must have a length of 32 bytes).\n\nUse the `file` command to check a key's format. \n\n```\nfile /path/to/unwrapped-key\n```\n\n- If the output is `data`, the key is in the correct format to be imported.\n\n- If the output is `ASCII text`, use the `cat` command to display the contents\n of the file.\n\n - If it is a string of letters and numbers ending in an `=` sign, it might\n be base64-encoded. Use the `base64` command (`Base64.exe` on Windows) to\n decode it. The following is an example of a base64-encoded key:\n\n ```\n THzArjassB+giKeNeT1Zr74OgV24t+Ep+37Ec6ojB3Y=\n ```\n - If it contains one or more lines of hexadecimal numbers, it might be\n hex-encoded. Use the `xxd` command (or the\n [`Format-Hex` PowerShell command](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/format-hex)\n on Windows) to decode it. The following is an example of a hex-encoded\n key:\n\n ```\n 00000000: 4c7c c0ae 36ac b01f a088 a78d 793d 59af L|..6.......y=Y.\n 00000010: be0e 815d b8b7 e129 fb7e c473 aa23 0776 ...]...).~.s.#.v\n ```\n - If it contains any other text, it may not be a valid symmetric key.\n\nFormatting asymmetric keys\n--------------------------\n\nAsymmetric keys using any of the supported [algorithms](/kms/docs/algorithms)\ncan be imported. In practice, it is difficult to retroactively determine the\nalgorithm used to create an asymmetric key. For that reason, we recommend that\nyou run the following commands on each asymmetric key before attempting to\nimport it into Cloud KMS.\n\n1. Use the `file` command to check a key's format.\n\n ```\n file /path/to/unwrapped-key\n ```\n - If the output is `PEM`, the key is in PEM format. If it is `ASCII text`,\n it is probably in PEM format. In either case, run the following command\n to convert it to PCKS#8 DER format:\n\n ```\n openssl pkcs8 -topk8 -nocrypt -inform PEM -outform DER \\\n -in /path/to/asymmetric-key-pem \\\n -out /path/to/formatted-key\n ```\n - If the output is `data`, the key is likely to be in DER format, but it\n may not be in PKCS #8 format. Run the following command to ensure that\n the key is in the correct format. The command has no effect if the key\n is already in the correct format. In that case, you can use the `diff`\n command to verify that the input and output file are identical.\n\n ```\n openssl pkcs8 -topk8 -nocrypt -inform DER -outform DER \\\n -in /path/to/asymmetric-key-der \\\n -out /path/to/formatted-key\n ```\n\nTroubleshooting\n---------------\n\nIf you run the commands above and you believe the key is in an appropriate\nformat, but the import still fails, check for errors in Google Cloud console, and\nthen see [Troubleshooting failed\nimports](/kms/docs/troubleshooting-failed-imports).\n\nWhat's next\n-----------\n\n- Continue to [Import a key version](/kms/docs/importing-a-key)\n- Learn about [key import](/kms/docs/key-import)"]]