PaymentCryptographyControlPlane / Client / export_key

export_key#

PaymentCryptographyControlPlane.Client.export_key(**kwargs)#

Exports a key from Amazon Web Services Payment Cryptography.

Amazon Web Services Payment Cryptography simplifies key exchange by replacing the existing paper-based approach with a modern electronic approach. With ExportKey you can export symmetric keys using either symmetric and asymmetric key exchange mechanisms. Using this operation, you can share your Amazon Web Services Payment Cryptography generated keys with other service partners to perform cryptographic operations outside of Amazon Web Services Payment Cryptography

For symmetric key exchange, Amazon Web Services Payment Cryptography uses the ANSI X9 TR-31 norm in accordance with PCI PIN guidelines. And for asymmetric key exchange, Amazon Web Services Payment Cryptography supports ANSI X9 TR-34 norm and RSA wrap and unwrap key exchange mechanism. Asymmetric key exchange methods are typically used to establish bi-directional trust between the two parties exhanging keys and are used for initial key exchange such as Key Encryption Key (KEK). After which you can export working keys using symmetric method to perform various cryptographic operations within Amazon Web Services Payment Cryptography.

The TR-34 norm is intended for exchanging 3DES keys only and keys are imported in a WrappedKeyBlock format. Key attributes (such as KeyUsage, KeyAlgorithm, KeyModesOfUse, Exportability) are contained within the key block. With RSA wrap and unwrap, you can exchange both 3DES and AES-128 keys. The keys are imported in a WrappedKeyCryptogram format and you will need to specify the key attributes during import.

You can also use ExportKey functionality to generate and export an IPEK (Initial Pin Encryption Key) from Amazon Web Services Payment Cryptography using either TR-31 or TR-34 export key exchange. IPEK is generated from BDK (Base Derivation Key) and ExportDukptInitialKey attribute KSN ( KeySerialNumber). The generated IPEK does not persist within Amazon Web Services Payment Cryptography and has to be re-generated each time during export.

For key exchange using TR-31 or TR-34 key blocks, you can also export optional blocks within the key block header which contain additional attribute information about the key. The KeyVersion within KeyBlockHeaders indicates the version of the key within the key block. Furthermore, KeyExportability within KeyBlockHeaders can be used to further restrict exportability of the key after export from Amazon Web Services Payment Cryptography.

The OptionalBlocks contain the additional data related to the key. For information on data type that can be included within optional blocks, refer to ASC X9.143-2022.

Note

Data included in key block headers is signed but transmitted in clear text. Sensitive or confidential information should not be included in optional blocks. Refer to ASC X9.143-2022 standard for information on allowed data type.

To export initial keys (KEK) or IPEK using TR-34

Using this operation, you can export initial key using TR-34 asymmetric key exchange. You can only export KEK generated within Amazon Web Services Payment Cryptography. In TR-34 terminology, the sending party of the key is called Key Distribution Host (KDH) and the receiving party of the key is called Key Receiving Device (KRD). During key export process, KDH is Amazon Web Services Payment Cryptography which initiates key export and KRD is the user receiving the key.

To initiate TR-34 key export, the KRD must obtain an export token by calling GetParametersForExport. This operation also generates a key pair for the purpose of key export, signs the key and returns back the signing public key certificate (also known as KDH signing certificate) and root certificate chain. The KDH uses the private key to sign the the export payload and the signing public key certificate is provided to KRD to verify the signature. The KRD can import the root certificate into its Hardware Security Module (HSM), as required. The export token and the associated KDH signing certificate expires after 7 days.

Next the KRD generates a key pair for the the purpose of encrypting the KDH key and provides the public key cerificate (also known as KRD wrapping certificate) back to KDH. The KRD will also import the root cerificate chain into Amazon Web Services Payment Cryptography by calling ImportKey for RootCertificatePublicKey. The KDH, Amazon Web Services Payment Cryptography, will use the KRD wrapping cerificate to encrypt (wrap) the key under export and signs it with signing private key to generate a TR-34 WrappedKeyBlock. For more information on TR-34 key export, see section Exporting symmetric keys in the Amazon Web Services Payment Cryptography User Guide.

Set the following parameters:

  • ExportAttributes: Specify export attributes in case of IPEK export. This parameter is optional for KEK export.

  • ExportKeyIdentifier: The KeyARN of the KEK or BDK (in case of IPEK) under export.

  • KeyMaterial: Use Tr34KeyBlock parameters.

  • CertificateAuthorityPublicKeyIdentifier: The KeyARN of the certificate chain that signed the KRD wrapping key certificate.

  • ExportToken: Obtained from KDH by calling GetParametersForImport.

  • WrappingKeyCertificate: The public key certificate in PEM format (base64 encoded) of the KRD wrapping key Amazon Web Services Payment Cryptography uses for encryption of the TR-34 export payload. This certificate must be signed by the root certificate (CertificateAuthorityPublicKeyIdentifier) imported into Amazon Web Services Payment Cryptography.

When this operation is successful, Amazon Web Services Payment Cryptography returns the KEK or IPEK as a TR-34 WrappedKeyBlock.

To export initial keys (KEK) or IPEK using RSA Wrap and Unwrap

Using this operation, you can export initial key using asymmetric RSA wrap and unwrap key exchange method. To initiate export, generate an asymmetric key pair on the receiving HSM and obtain the public key certificate in PEM format (base64 encoded) for the purpose of wrapping and the root certifiate chain. Import the root certificate into Amazon Web Services Payment Cryptography by calling ImportKey for RootCertificatePublicKey.

Next call ExportKey and set the following parameters:

  • CertificateAuthorityPublicKeyIdentifier: The KeyARN of the certificate chain that signed wrapping key certificate.

  • KeyMaterial: Set to KeyCryptogram.

  • WrappingKeyCertificate: The public key certificate in PEM format (base64 encoded) obtained by the receiving HSM and signed by the root certificate (CertificateAuthorityPublicKeyIdentifier) imported into Amazon Web Services Payment Cryptography. The receiving HSM uses its private key component to unwrap the WrappedKeyCryptogram.

When this operation is successful, Amazon Web Services Payment Cryptography returns the WrappedKeyCryptogram.

To export working keys or IPEK using TR-31

Using this operation, you can export working keys or IPEK using TR-31 symmetric key exchange. In TR-31, you must use an initial key such as KEK to encrypt or wrap the key under export. To establish a KEK, you can use CreateKey or ImportKey.

Set the following parameters:

  • ExportAttributes: Specify export attributes in case of IPEK export. This parameter is optional for KEK export.

  • ExportKeyIdentifier: The KeyARN of the KEK or BDK (in case of IPEK) under export.

  • KeyMaterial: Use Tr31KeyBlock parameters.

When this operation is successful, Amazon Web Services Payment Cryptography returns the working key or IPEK as a TR-31 WrappedKeyBlock.

Cross-account use: This operation can’t be used across different Amazon Web Services accounts.

Related operations:

See also: AWS API Documentation

Request Syntax

response = client.export_key(
    KeyMaterial={
        'Tr31KeyBlock': {
            'WrappingKeyIdentifier': 'string',
            'KeyBlockHeaders': {
                'KeyModesOfUse': {
                    'Encrypt': True|False,
                    'Decrypt': True|False,
                    'Wrap': True|False,
                    'Unwrap': True|False,
                    'Generate': True|False,
                    'Sign': True|False,
                    'Verify': True|False,
                    'DeriveKey': True|False,
                    'NoRestrictions': True|False
                },
                'KeyExportability': 'EXPORTABLE'|'NON_EXPORTABLE'|'SENSITIVE',
                'KeyVersion': 'string',
                'OptionalBlocks': {
                    'string': 'string'
                }
            }
        },
        'Tr34KeyBlock': {
            'CertificateAuthorityPublicKeyIdentifier': 'string',
            'WrappingKeyCertificate': 'string',
            'ExportToken': 'string',
            'KeyBlockFormat': 'X9_TR34_2012',
            'RandomNonce': 'string',
            'KeyBlockHeaders': {
                'KeyModesOfUse': {
                    'Encrypt': True|False,
                    'Decrypt': True|False,
                    'Wrap': True|False,
                    'Unwrap': True|False,
                    'Generate': True|False,
                    'Sign': True|False,
                    'Verify': True|False,
                    'DeriveKey': True|False,
                    'NoRestrictions': True|False
                },
                'KeyExportability': 'EXPORTABLE'|'NON_EXPORTABLE'|'SENSITIVE',
                'KeyVersion': 'string',
                'OptionalBlocks': {
                    'string': 'string'
                }
            }
        },
        'KeyCryptogram': {
            'CertificateAuthorityPublicKeyIdentifier': 'string',
            'WrappingKeyCertificate': 'string',
            'WrappingSpec': 'RSA_OAEP_SHA_256'|'RSA_OAEP_SHA_512'
        }
    },
    ExportKeyIdentifier='string',
    ExportAttributes={
        'ExportDukptInitialKey': {
            'KeySerialNumber': 'string'
        },
        'KeyCheckValueAlgorithm': 'CMAC'|'ANSI_X9_24'
    }
)
Parameters:
  • KeyMaterial (dict) –

    [REQUIRED]

    The key block format type, for example, TR-34 or TR-31, to use during key material export.

    Note

    This is a Tagged Union structure. Only one of the following top level keys can be set: Tr31KeyBlock, Tr34KeyBlock, KeyCryptogram.

    • Tr31KeyBlock (dict) –

      Parameter information for key material export using symmetric TR-31 key exchange method.

      • WrappingKeyIdentifier (string) – [REQUIRED]

        The KeyARN of the the wrapping key. This key encrypts or wraps the key under export for TR-31 key block generation.

      • KeyBlockHeaders (dict) –

        Optional metadata for export associated with the key material. This data is signed but transmitted in clear text.

        • KeyModesOfUse (dict) –

          The list of cryptographic operations that you can perform using the key. The modes of use are defined in section A.5.3 of the TR-31 spec.

          • Encrypt (boolean) –

            Specifies whether an Amazon Web Services Payment Cryptography key can be used to encrypt data.

          • Decrypt (boolean) –

            Specifies whether an Amazon Web Services Payment Cryptography key can be used to decrypt data.

          • Wrap (boolean) –

            Specifies whether an Amazon Web Services Payment Cryptography key can be used to wrap other keys.

          • Unwrap (boolean) –

            Specifies whether an Amazon Web Services Payment Cryptography key can be used to unwrap other keys.

          • Generate (boolean) –

            Specifies whether an Amazon Web Services Payment Cryptography key can be used to generate and verify other card and PIN verification keys.

          • Sign (boolean) –

            Specifies whether an Amazon Web Services Payment Cryptography key can be used for signing.

          • Verify (boolean) –

            Specifies whether an Amazon Web Services Payment Cryptography key can be used to verify signatures.

          • DeriveKey (boolean) –

            Specifies whether an Amazon Web Services Payment Cryptography key can be used to derive new keys.

          • NoRestrictions (boolean) –

            Specifies whether an Amazon Web Services Payment Cryptography key has no special restrictions other than the restrictions implied by KeyUsage.

        • KeyExportability (string) –

          Specifies subsequent exportability of the key within the key block after it is received by the receiving party. It can be used to further restrict exportability of the key after export from Amazon Web Services Payment Cryptography.

          When set to EXPORTABLE, the key can be subsequently exported by the receiver under a KEK using TR-31 or TR-34 key block export only. When set to NON_EXPORTABLE, the key cannot be subsequently exported by the receiver. When set to SENSITIVE, the key can be exported by the receiver under a KEK using TR-31, TR-34, RSA wrap and unwrap cryptogram or using a symmetric cryptogram key export method. For further information refer to ANSI X9.143-2022.

        • KeyVersion (string) –

          Parameter used to indicate the version of the key carried in the key block or indicate the value carried in the key block is a component of a key.

        • OptionalBlocks (dict) –

          Parameter used to indicate the type of optional data in key block headers. Refer to ANSI X9.143-2022 for information on allowed data type for optional blocks.

          Optional block character limit is 112 characters. For each optional block, 2 characters are reserved for optional block ID and 2 characters reserved for optional block length. More than one optional blocks can be included as long as the combined length does not increase 112 characters.

          • (string) –

            • (string) –

    • Tr34KeyBlock (dict) –

      Parameter information for key material export using the asymmetric TR-34 key exchange method.

      • CertificateAuthorityPublicKeyIdentifier (string) – [REQUIRED]

        The KeyARN of the certificate chain that signs the wrapping key certificate during TR-34 key export.

      • WrappingKeyCertificate (string) – [REQUIRED]

        The KeyARN of the wrapping key certificate. Amazon Web Services Payment Cryptography uses this certificate to wrap the key under export.

      • ExportToken (string) – [REQUIRED]

        The export token to initiate key export from Amazon Web Services Payment Cryptography. It also contains the signing key certificate that will sign the wrapped key during TR-34 key block generation. Call GetParametersForExport to receive an export token. It expires after 7 days. You can use the same export token to export multiple keys from the same service account.

      • KeyBlockFormat (string) – [REQUIRED]

        The format of key block that Amazon Web Services Payment Cryptography will use during key export.

      • RandomNonce (string) –

        A random number value that is unique to the TR-34 key block generated using 2 pass. The operation will fail, if a random nonce value is not provided for a TR-34 key block generated using 2 pass.

      • KeyBlockHeaders (dict) –

        Optional metadata for export associated with the key material. This data is signed but transmitted in clear text.

        • KeyModesOfUse (dict) –

          The list of cryptographic operations that you can perform using the key. The modes of use are defined in section A.5.3 of the TR-31 spec.

          • Encrypt (boolean) –

            Specifies whether an Amazon Web Services Payment Cryptography key can be used to encrypt data.

          • Decrypt (boolean) –

            Specifies whether an Amazon Web Services Payment Cryptography key can be used to decrypt data.

          • Wrap (boolean) –

            Specifies whether an Amazon Web Services Payment Cryptography key can be used to wrap other keys.

          • Unwrap (boolean) –

            Specifies whether an Amazon Web Services Payment Cryptography key can be used to unwrap other keys.

          • Generate (boolean) –

            Specifies whether an Amazon Web Services Payment Cryptography key can be used to generate and verify other card and PIN verification keys.

          • Sign (boolean) –

            Specifies whether an Amazon Web Services Payment Cryptography key can be used for signing.

          • Verify (boolean) –

            Specifies whether an Amazon Web Services Payment Cryptography key can be used to verify signatures.

          • DeriveKey (boolean) –

            Specifies whether an Amazon Web Services Payment Cryptography key can be used to derive new keys.

          • NoRestrictions (boolean) –

            Specifies whether an Amazon Web Services Payment Cryptography key has no special restrictions other than the restrictions implied by KeyUsage.

        • KeyExportability (string) –

          Specifies subsequent exportability of the key within the key block after it is received by the receiving party. It can be used to further restrict exportability of the key after export from Amazon Web Services Payment Cryptography.

          When set to EXPORTABLE, the key can be subsequently exported by the receiver under a KEK using TR-31 or TR-34 key block export only. When set to NON_EXPORTABLE, the key cannot be subsequently exported by the receiver. When set to SENSITIVE, the key can be exported by the receiver under a KEK using TR-31, TR-34, RSA wrap and unwrap cryptogram or using a symmetric cryptogram key export method. For further information refer to ANSI X9.143-2022.

        • KeyVersion (string) –

          Parameter used to indicate the version of the key carried in the key block or indicate the value carried in the key block is a component of a key.

        • OptionalBlocks (dict) –

          Parameter used to indicate the type of optional data in key block headers. Refer to ANSI X9.143-2022 for information on allowed data type for optional blocks.

          Optional block character limit is 112 characters. For each optional block, 2 characters are reserved for optional block ID and 2 characters reserved for optional block length. More than one optional blocks can be included as long as the combined length does not increase 112 characters.

          • (string) –

            • (string) –

    • KeyCryptogram (dict) –

      Parameter information for key material export using asymmetric RSA wrap and unwrap key exchange method

      • CertificateAuthorityPublicKeyIdentifier (string) – [REQUIRED]

        The KeyARN of the certificate chain that signs the wrapping key certificate during RSA wrap and unwrap key export.

      • WrappingKeyCertificate (string) – [REQUIRED]

        The wrapping key certificate in PEM format (base64 encoded). Amazon Web Services Payment Cryptography uses this certificate to wrap the key under export.

      • WrappingSpec (string) –

        The wrapping spec for the key under export.

  • ExportKeyIdentifier (string) –

    [REQUIRED]

    The KeyARN of the key under export from Amazon Web Services Payment Cryptography.

  • ExportAttributes (dict) –

    The attributes for IPEK generation during export.

    • ExportDukptInitialKey (dict) –

      Parameter information for IPEK export.

      • KeySerialNumber (string) – [REQUIRED]

        The KSN for IPEK generation using DUKPT.

        KSN must be padded before sending to Amazon Web Services Payment Cryptography. KSN hex length should be 20 for a TDES_2KEY key or 24 for an AES key.

    • KeyCheckValueAlgorithm (string) –

      The algorithm that Amazon Web Services Payment Cryptography uses to calculate the key check value (KCV). It is used to validate the key integrity. Specify KCV for IPEK export only.

      For TDES keys, the KCV is computed by encrypting 8 bytes, each with value of zero, with the key to be checked and retaining the 3 highest order bytes of the encrypted result. For AES keys, the KCV is computed using a CMAC algorithm where the input data is 16 bytes of zero and retaining the 3 highest order bytes of the encrypted result.

Return type:

dict

Returns:

Response Syntax

{
    'WrappedKey': {
        'WrappingKeyArn': 'string',
        'WrappedKeyMaterialFormat': 'KEY_CRYPTOGRAM'|'TR31_KEY_BLOCK'|'TR34_KEY_BLOCK',
        'KeyMaterial': 'string',
        'KeyCheckValue': 'string',
        'KeyCheckValueAlgorithm': 'CMAC'|'ANSI_X9_24'
    }
}

Response Structure

  • (dict) –

    • WrappedKey (dict) –

      The key material under export as a TR-34 WrappedKeyBlock or a TR-31 WrappedKeyBlock. or a RSA WrappedKeyCryptogram.

      • WrappingKeyArn (string) –

        The KeyARN of the wrapped key.

      • WrappedKeyMaterialFormat (string) –

        The key block format of a wrapped key.

      • KeyMaterial (string) –

        Parameter information for generating a wrapped key using TR-31 or TR-34 skey exchange method.

      • KeyCheckValue (string) –

        The key check value (KCV) is used to check if all parties holding a given key have the same key or to detect that a key has changed.

      • KeyCheckValueAlgorithm (string) –

        The algorithm that Amazon Web Services Payment Cryptography uses to calculate the key check value (KCV). It is used to validate the key integrity.

        For TDES keys, the KCV is computed by encrypting 8 bytes, each with value of zero, with the key to be checked and retaining the 3 highest order bytes of the encrypted result. For AES keys, the KCV is computed using a CMAC algorithm where the input data is 16 bytes of zero and retaining the 3 highest order bytes of the encrypted result.

Exceptions