ImportKeyMaterial
Imports key material into an existing symmetric encryption KMS key that was created without key material. After you successfully import key material into a KMS key, you can reimport the same key material into that KMS key, but you cannot import different key material.
You cannot perform this operation on an asymmetric KMS key, an HMAC KMS key, or on any KMS key in a different Amazon Web Services account. For more information about creating KMS keys with no key material and then importing key material, see Importing Key Material in the Amazon Key Management Service Developer Guide.
Before using this operation, call GetParametersForImport. Its response
includes a public key and an import token. Use the public key to encrypt the key material.
Then, submit the import token from the same GetParametersForImport
response.
When calling this operation, you must specify the following values:
-
The key ID or key ARN of a KMS key with no key material. Its
Origin
must beEXTERNAL
.To create a KMS key with no key material, call CreateKey and set the value of its
Origin
parameter toEXTERNAL
. To get theOrigin
of a KMS key, call DescribeKey.) -
The encrypted key material. To get the public key to encrypt the key material, call GetParametersForImport.
-
The import token that GetParametersForImport returned. You must use a public key and token from the same
GetParametersForImport
response. -
Whether the key material expires and if so, when. If you set an expiration date, Amazon KMS deletes the key material from the KMS key on the specified date, and the KMS key becomes unusable. To use the KMS key again, you must reimport the same key material. The only way to change an expiration date is by reimporting the same key material and specifying a new expiration date.
When this operation is successful, the key state of the KMS key changes from
PendingImport
to Enabled
, and you can use the KMS key.
If this operation fails, use the exception to help determine the problem. If the error is related to the key material, the import token, or wrapping key, use GetParametersForImport to get a new public key and import token for the KMS key and repeat the import procedure. For help, see How To Import Key Material in the Amazon Key Management Service Developer Guide.
The KMS key that you use for this operation must be in a compatible key state. For details, see Key states of Amazon KMS keys in the Amazon Key Management Service Developer Guide.
Cross-account use: No. You cannot perform this operation on a KMS key in a different Amazon Web Services account.
Required permissions: kms:ImportKeyMaterial (key policy)
Related operations:
Request Syntax
{
"EncryptedKeyMaterial": blob
,
"ExpirationModel": "string
",
"ImportToken": blob
,
"KeyId": "string
",
"ValidTo": number
}
Request Parameters
For information about the parameters that are common to all actions, see Common Parameters.
The request accepts the following data in JSON format.
In the following list, the required parameters are described first.
- EncryptedKeyMaterial
-
The encrypted key material to import. The key material must be encrypted with the public wrapping key that GetParametersForImport returned, using the wrapping algorithm that you specified in the same
GetParametersForImport
request.Type: Base64-encoded binary data object
Length Constraints: Minimum length of 1. Maximum length of 6144.
Required: Yes
- ImportToken
-
The import token that you received in the response to a previous GetParametersForImport request. It must be from the same response that contained the public key that you used to encrypt the key material.
Type: Base64-encoded binary data object
Length Constraints: Minimum length of 1. Maximum length of 6144.
Required: Yes
- KeyId
-
The identifier of the symmetric encryption KMS key that receives the imported key material. This must be the same KMS key specified in the
KeyID
parameter of the corresponding GetParametersForImport request. TheOrigin
of the KMS key must beEXTERNAL
. You cannot perform this operation on an asymmetric KMS key, an HMAC KMS key, a KMS key in a custom key store, or on a KMS key in a different Amazon Web Services accountSpecify the key ID or key ARN of the KMS key.
For example:
-
Key ID:
1234abcd-12ab-34cd-56ef-1234567890ab
-
Key ARN:
arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab
To get the key ID and key ARN for a KMS key, use ListKeys or DescribeKey.
Type: String
Length Constraints: Minimum length of 1. Maximum length of 2048.
Required: Yes
-
- ExpirationModel
-
Specifies whether the key material expires. The default is
KEY_MATERIAL_EXPIRES
, in which case you must include theValidTo
parameter. When this parameter is set toKEY_MATERIAL_DOES_NOT_EXPIRE
, you must omit theValidTo
parameter.Type: String
Valid Values:
KEY_MATERIAL_EXPIRES | KEY_MATERIAL_DOES_NOT_EXPIRE
Required: No
- ValidTo
-
The time at which the imported key material expires. When the key material expires, Amazon KMS deletes the key material and the KMS key becomes unusable. You must omit this parameter when the
ExpirationModel
parameter is set toKEY_MATERIAL_DOES_NOT_EXPIRE
. Otherwise it is required.Type: Timestamp
Required: No
Response Elements
If the action is successful, the service sends back an HTTP 200 response with an empty HTTP body.
Errors
For information about the errors that are common to all actions, see Common Errors.
- DependencyTimeoutException
-
The system timed out while trying to fulfill the request. The request can be retried.
HTTP Status Code: 500
- ExpiredImportTokenException
-
The request was rejected because the specified import token is expired. Use GetParametersForImport to get a new import token and public key, use the new public key to encrypt the key material, and then try the request again.
HTTP Status Code: 400
- IncorrectKeyMaterialException
-
The request was rejected because the key material in the request is, expired, invalid, or is not the same key material that was previously imported into this KMS key.
HTTP Status Code: 400
- InvalidArnException
-
The request was rejected because a specified ARN, or an ARN in a key policy, is not valid.
HTTP Status Code: 400
- InvalidCiphertextException
-
From the Decrypt or ReEncrypt operation, the request was rejected because the specified ciphertext, or additional authenticated data incorporated into the ciphertext, such as the encryption context, is corrupted, missing, or otherwise invalid.
From the ImportKeyMaterial operation, the request was rejected because Amazon KMS could not decrypt the encrypted (wrapped) key material.
HTTP Status Code: 400
- InvalidImportTokenException
-
The request was rejected because the provided import token is invalid or is associated with a different KMS key.
HTTP Status Code: 400
- KMSInternalException
-
The request was rejected because an internal exception occurred. The request can be retried.
HTTP Status Code: 500
- KMSInvalidStateException
-
The request was rejected because the state of the specified resource is not valid for this request.
For more information about how key state affects the use of a KMS key, see Key states of Amazon KMS keys in the Amazon Key Management Service Developer Guide .
HTTP Status Code: 400
- NotFoundException
-
The request was rejected because the specified entity or resource could not be found.
HTTP Status Code: 400
- UnsupportedOperationException
-
The request was rejected because a specified parameter is not supported or a specified resource is not valid for this operation.
HTTP Status Code: 400
Examples
Example Request
The following example is formatted for legibility.
POST / HTTP/1.1 Host: kms.us-east-2.amazonaws.com Content-Length: 2835 X-Amz-Target: TrentService.ImportKeyMaterial X-Amz-Date: 20161201T212609Z Content-Type: application/x-amz-json-1.1 Authorization: AWS4-HMAC-SHA256\ Credential=AKIAI44QH8DHBEXAMPLE/20161201/us-east-2/kms/aws4_request,\ SignedHeaders=content-type;host;x-amz-date;x-amz-target,\ Signature=dda4e269d4fd93decf1401aeb651e49c206c412c609141f6c743f146e1afb4e3 { "ExpirationModel": "KEY_MATERIAL_DOES_NOT_EXPIRE", "KeyId": "1234abcd-12ab-34cd-56ef-1234567890ab", "ImportToken": "AQECAHgybIx2X9LNs5ADpvmFm5Sv//daUB9ZeCKoiJxmiw09YQAABrQwggawBgkqhkiG9w0BBwagggahMIIGnQ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W20fcZ1KQG/GPHuScFgBsWawQf1spqKwZyHAHPaWZCymD9Fo2yHBHi+/ARPwM02iuqDLi9Tqv/g0=", "EncryptedKeyMaterial": "CubeyZ4cm/xMEA0UG5jP1iBzh/0E+uUg407JDcXhIC+iuMm+wPgITaEby+Y3nM/e6gjUls5vy9TdBRFv4+JtksvB5hW4Znb2lUQhTUv+SSAZpaI14kAgTq/jC2GTLkaC6Vf5zJx2xaLrOKGV2Xu4YgONIGslubHNffTC3aL/YBJ/FXTXaVu7rS2phOFCrZ+ATittS03w4DiCVoNwo2v0QE0+dVoUNjXNQC1veWxhPlC7FezfK7AIsBSSXotJfANxRkybg8KcmkSoYdzr3N0L0v7oMorgbTgaTvdrLXu/PzphK6RWJGJig4tk+lxUT8hV7xiLkFskGjIHFmp6Xbon8w==" }
Example Response
This example illustrates one usage of ImportKeyMaterial.
HTTP/1.1 200 OK Server: Server Date: Thu, 01 Dec 2016 21:26:10 GMT Content-Type: application/x-amz-json-1.1 Content-Length: 2 Connection: keep-alive x-amzn-RequestId: c72fb6ff-b80c-11e6-ae07-61b14fe11739 {}
See Also
For more information about using this API in one of the language-specific Amazon SDKs, see the following: