Encrypt
Specification
This operation requests the server to perform an encryption operation on the provided data using a Managed Cryptographic Object as the key for the encryption operation.
The request contains information about the cryptographic parameters (mode and padding method), the data to be encrypted, and the IV/Counter/Nonce to use. The cryptographic parameters MAY be omitted from the request as they can be specified as associated attributes of the Managed Cryptographic Object. The IV/Counter/Nonce MAY also be omitted from the request if the cryptographic parameters indicate that the server shall generate a Random IV on behalf of the client or the encryption algorithm does not need an IV/Counter/Nonce. The server does not store or otherwise manage the IV/Counter/Nonce.
If the Managed Cryptographic Object referenced has a Usage Limits attribute, then the server SHALL obtain an allocation from the current Usage Limits value prior to performing the encryption operation. If the allocation is unable to be obtained, the operation SHALL return with a result status of Operation Failed and result reason of Permission Denied.
The response contains the Unique Identifier of the Managed Cryptographic Object used as the key and the result of the encryption operation.
The success or failure of the operation is indicated by the Result Status (and, if failure, the Result Reason) in the response header.
Implementation
Encryption is supported for symmetric keys, public keys, certificates, and OpenPGP keys (PGPKey, non-FIPS mode). To see the list of supported cryptographic algorithms, please refer to Supported Algorithms.
Symmetric encryption can be split into parts (Init Indicator, Correlation Value, Final Indicator); see
multi-part decryption for the rules and limits. Each part returns its own
ciphertext; a server-generated IV comes with the first part and the authentication tag with the final part. Only
symmetric keys can be used for multi-part encryption (Feature Not Supported otherwise). Bulk encryption of several
items always uses a fresh random IV per item: a request that supplies an IV for several items is rejected with
Invalid Field.
IV and tag rules:
IV Lengthsizes a server-generated IV and is ignored when the request carries an IV. It is in bits: a multiple of 8, at most 1024, and equal to the cipher's nonce size except for GCM; otherwise the request fails withBad Cryptographic Parameters. A length in bytes equal to the nonce size (for example12) is also accepted. A server-generated GCM IV is at least 96 bits long.- A FIPS build always generates the AES-GCM IV inside the OpenSSL FIPS provider (NIST SP 800-38D ยง9.1, FIPS 140-3
IG C.H) and returns it in
IV/Counter/Nonce: a request that carries an IV for an AES-GCM encryption is refused, andTag Lengthmust be 16 bytes. Decryption accepts the 96-bit IV the server generated. A non-FIPS build still accepts an IV chosen by the client, which must then be unique under one key. - The server counts the server-generated AES-GCM IVs of each key (one per single-part request, per multi-part
stream and per bulk item) and fails
EncryptwithPermission Deniedonce a key has made 2^32 of them (SP 800-38D ยง8.3); decryption is not affected. See thegcm_invocationstable. Random IVset to false with no IV in the request fails withMissing Initialization Vector.Fixed Field Length,Invocation Field Length,Counter LengthandInitial Counter Valuefail withUnsupported Cryptographic Parameters.- For GCM and ChaCha20-Poly1305,
Tag Lengthmust be 12 to 16 bytes (Bad Cryptographic Parametersotherwise); aTag Lengthon a non-AEAD mode fails withUnsupported Cryptographic Parameters. - Unsupported block cipher modes and padding methods fail with
Unsupported Cryptographic Parameters.
A key in the wrong state fails with Wrong Key Lifecycle State, a usable object of the wrong type with
Invalid Object Type, and a key whose Cryptographic Usage Mask lacks Encrypt with
Incompatible Cryptographic Usage Mask.
Example - AES GCM encryption
Encrypting the text Hello, world! with symmetric key 027cced1-ff2b-4bd3-a200-db1041583bd (go to Create
to see how to create the symmetric key).
Corresponding KMS CLI command:
ckms sym encrypt -t "MySymmetricKey" /tmp/hello_world.txt
Note: the file /tmp/hello_world.txt contains the text Hello, world!.
Please note that the response contains:
- the encrypted data
- the nonce: 12 bytes
- the authentication tag: 16 bytes
{
"tag": "Encrypt",
"type": "Structure",
"value": [
{
"tag": "UniqueIdentifier",
"type": "TextString",
"value": "[\"MySymmetricKey\"]"
},
{
"tag": "CryptographicParameters",
"type": "Structure",
"value": [
{
"tag": "BlockCipherMode",
"type": "Enumeration",
"value": "GCM"
},
{
"tag": "CryptographicAlgorithm",
"type": "Enumeration",
"value": "AES"
}
]
},
{
"tag": "Data",
"type": "ByteString",
"value": "48656C6C6F2C20776F726C64210A"
}
]
}
Example - Covercrypt
Encrypting the text Hello, world! with the Covercrypt master public key 0fd1f684-156c-4ca6-adc2-0a6f4b620463
(go to Create Key Pair to see how to create the mater key pair) and attributes Security Level::Confidential && Department::FIN.
Corresponding KMS CLI command:
ckms cc encrypt -k 0fd1f684-156c-4ca6-adc2-0a6f4b620463 \
/tmp/hello_world.txt "Security Level::Confidential && Department::FIN"
Note: the file /tmp/hello_world.txt contains the text Hello, world!.
In the request, please note that the Data parameter contains:
- the length of the bytes of the attributes:
47 = 2Fin hexadecimal - the attributes as bytes:
Security Level::Confidential && Department::FIN - the bytes to encrypt:
Hello, world!as UTF-8 bytes
{
"tag": "Encrypt",
"type": "Structure",
"value": [
{
"tag": "UniqueIdentifier",
"type": "TextString",
"value": "0fd1f684-156c-4ca6-adc2-0a6f4b620463"
},
{
"tag": "CryptographicParameters",
"type": "Structure",
"value": [
{
"tag": "CryptographicAlgorithm",
"type": "Enumeration",
"value": "CoverCrypt"
}
]
},
{
"tag": "Data",
"type": "ByteString",
"value": "2F5365637572697479204C6576656C3A3A436F6E666964656E7469616C202626204465706172746D656E743A3A46494E0048656C6C6F2C20776F726C64210A"
}
]
}