ImportKeyMaterial
Imports or reimports key material into an existing KMS key that was created without key material. You can also use this operation to set or update the expiration model and expiration date of the imported key material.
By default, AWS KMS creates KMS keys with key material that it generates. You can also generate and import your own key material. For more information about importing key material, see Importing key material.
For asymmetric, HMAC and multi-Region keys, you cannot change the key material after the initial import.
You can import multiple key materials into single-Region, symmetric encryption keys and rotate the key material
on demand using RotateKeyOnDemand
.
After you import key material, you can reimport
the same key material into that KMS key or, if the key supports on-demand rotation,
import new key material. You can use the ImportType
parameter to indicate
whether you are importing new key material or re-importing previously imported key material.
You might reimport key material to replace key material that expired or key material
that you deleted. You might also reimport key material to change the expiration model or
expiration date of the key material.
Each time you import key material into AWS KMS, you can determine whether
(ExpirationModel
) and when (ValidTo
) the key material expires. To
change the expiration of your key material, you must import it again, either by calling
ImportKeyMaterial
or using the import features of the AWS KMS console.
Before you call ImportKeyMaterial
, complete these steps:
-
Create or identify a KMS key with
EXTERNAL
origin, which indicates that the KMS key is designed for imported key material.To create a new KMS key for imported key material, call the CreateKey operation with an
Origin
value ofEXTERNAL
. You can create a symmetric encryption KMS key, HMAC KMS key, asymmetric encryption KMS key, asymmetric key agreement key, or asymmetric signing KMS key. You can also import key material into a multi-Region key of any supported type. However, you can't import key material into a KMS key in a custom key store. -
Call the GetParametersForImport operation to get a public key and import token set for importing key material.
-
Use the public key in the GetParametersForImport response to encrypt your key material.
Then, in an ImportKeyMaterial
request, you submit your encrypted key
material and import token. When calling this operation, you must specify the following
values:
-
The key ID or key ARN of the KMS key to associate with the imported key material. Its
Origin
must beEXTERNAL
and itsKeyState
must bePendingImport
. You cannot perform this operation on a KMS key in a custom key store, or on a KMS key in a different AWS account. To get theOrigin
andKeyState
of a KMS key, call DescribeKey. -
The encrypted key material.
-
The import token that GetParametersForImport returned. You must use a public key and token from the same
GetParametersForImport
response. -
Whether the key material expires (
ExpirationModel
) and, if so, when (ValidTo
). For help with this choice, see Setting an expiration time in the AWS Key Management Service Developer Guide.If you set an expiration date, AWS KMS deletes the key material from the KMS key on the specified date, making the KMS key unusable. To use the KMS key in cryptographic operations again, you must reimport the same key material. However, you can delete and reimport the key material at any time, including before the key material expires. Each time you reimport, you can eliminate or reset the expiration time.
When this operation is successful, the key state of the KMS key changes from
PendingImport
to Enabled
, and you can use the KMS key in
cryptographic operations. For single-Region, symmetric encryption keys, you will need to
import all of the key materials associated with the KMS key to change its state to Enabled
.
Use the ListKeyRotations
operation to list the ID and import state of each key material
associated with a 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 Create a KMS key with imported key material in the AWS 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 AWS KMS keys in the AWS Key Management Service Developer Guide.
Cross-account use: No. You cannot perform this operation on a KMS key in a different AWS account.
Required permissions: kms:ImportKeyMaterial (key policy)
Related operations:
Eventual consistency: The AWS KMS API follows an eventual consistency model. For more information, see AWS KMS eventual consistency.
Request Syntax
{
"EncryptedKeyMaterial": blob
,
"ExpirationModel": "string
",
"ImportToken": blob
,
"ImportType": "string
",
"KeyId": "string
",
"KeyMaterialDescription": "string
",
"KeyMaterialId": "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.
Note
In the following list, the required parameters are described first.
- EncryptedKeyMaterial
-
The encrypted key material to import. The key material must be encrypted under 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 KMS key that will be associated with 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
and itsKeyState
must bePendingImport
.The KMS key can be a symmetric encryption KMS key, HMAC KMS key, asymmetric encryption KMS key, or asymmetric signing KMS key, including a multi-Region key of any supported type. You cannot perform this operation on a KMS key in a custom key store, or on a KMS key in a different AWS account.
Specify 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
. For help with this choice, see Setting an expiration time in the AWS Key Management Service Developer Guide.When the value of
ExpirationModel
isKEY_MATERIAL_EXPIRES
, you must specify a value for theValidTo
parameter. When value isKEY_MATERIAL_DOES_NOT_EXPIRE
, you must omit theValidTo
parameter.You cannot change the
ExpirationModel
orValidTo
values for the current import after the request completes. To change either value, you must reimport the key material.Type: String
Valid Values:
KEY_MATERIAL_EXPIRES | KEY_MATERIAL_DOES_NOT_EXPIRE
Required: No
- ImportType
-
Indicates whether the key material being imported is previously associated with this KMS key or not. This parameter is optional and only usable with symmetric encryption keys. The default is
EXISTING_KEY_MATERIAL
. If no key material has ever been imported into the KMS key, and this parameter is omitted, the parameter defaults toNEW_KEY_MATERIAL
.Type: String
Valid Values:
NEW_KEY_MATERIAL | EXISTING_KEY_MATERIAL
Required: No
- KeyMaterialDescription
-
Description for the key material being imported. This parameter is optional and only usable with symmetric encryption keys. If you do not specify a key material description, AWS KMS retains the value you specified when you last imported the same key material into this KMS key.
Type: String
Length Constraints: Minimum length of 0. Maximum length of 256.
Pattern:
^[a-zA-Z0-9:/_\s.-]+$
Required: No
- KeyMaterialId
-
Identifies the key material being imported. This parameter is optional and only usable with symmetric encryption keys. You cannot specify a key material ID with
ImportType
set toNEW_KEY_MATERIAL
. Whenever you import key material into a symmetric encryption key, AWS KMS assigns a unique identifier to the key material based on the KMS key ID and the imported key material. When you re-import key material with a specified key material ID, AWS KMS:-
Computes the identifier for the key material
-
Matches the computed identifier against the specified key material ID
-
Verifies that the key material ID is already associated with the KMS key
To get the list of key material IDs associated with a KMS key, use ListKeyRotations.
Type: String
Length Constraints: Fixed length of 64.
Pattern:
^[a-f0-9]+$
Required: No
-
- ValidTo
-
The date and time when the imported key material expires. This parameter is required when the value of the
ExpirationModel
parameter isKEY_MATERIAL_EXPIRES
. Otherwise it is not valid.The value of this parameter must be a future date and time. The maximum value is 365 days from the request date.
When the key material expires, AWS KMS deletes the key material from the KMS key. Without its key material, the KMS key is unusable. To use the KMS key in cryptographic operations, you must reimport the same key material.
You cannot change the
ExpirationModel
orValidTo
values for the current import after the request completes. To change either value, you must delete (DeleteImportedKeyMaterial) and reimport the key material.Type: Timestamp
Required: No
Response Syntax
{
"KeyId": "string",
"KeyMaterialId": "string"
}
Response Elements
If the action is successful, the service sends back an HTTP 200 response.
The following data is returned in JSON format by the service.
- KeyId
-
The Amazon Resource Name (key ARN) of the KMS key into which key material was imported.
Type: String
Length Constraints: Minimum length of 1. Maximum length of 2048.
- KeyMaterialId
-
Identifies the imported key material.
Type: String
Length Constraints: Fixed length of 64.
Pattern:
^[a-f0-9]+$
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. You can retry the request.
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 does not meet expectations. For example, it is not the same key material that was previously imported or AWS KMS expected new key material but the key material being imported is already associated with the 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 AWS 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.
This exceptions means one of the following:
-
The key state of the KMS key is not compatible with the operation.
To find the key state, use the DescribeKey operation. For more information about which key states are compatible with each AWS KMS operation, see Key states of AWS KMS keys in the AWS Key Management Service Developer Guide .
-
For cryptographic operations on KMS keys in custom key stores, this exception represents a general failure with many possible causes. To identify the cause, see the error message that accompanies the exception.
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//daUB9ZeCKoiJxmiw09YQAABrQwggawBgkqhkiG9w0BBwagggahMIIGnQIBADCCBpYGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMv9Fgs/U4Wg2Vw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02iuqDLi9Tqv/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 { "KeyId": "1234abcd-12ab-34cd-56ef-1234567890ab", "KeyMaterialId": "0b7fd7ddbac6eef27907413567cad8c810e2883dc8a7534067a82ee1142fc1e6", }
See Also
For more information about using this API in one of the language-specific AWS SDKs, see the following: