Encrypt Data (QC3ENCDT, Qc3EncryptData) API


  Required Parameter Group:


  Service Program Name: QC3DTAEN

  Default Public Authority: *USE

  Threadsafe: Yes

The Encrypt Data (OPM, QC3ENCDT; ILE, Qc3EncryptData) API protects data privacy by scrambling clear data into an unintelligible form. To recover the clear data from the encrypted data, use the Decrypt Data (OPM, QC3DECDT; ILE, Qc3DecryptData) API.

Information on cryptographic standards can be found in Create Algorithm Context (OPM, QC3CRTAX; ILE, Qc3CreateAlgorithmContext) API.


Authorities and Locks

Required device description authority
*USE

Required file authority
*OBJOPR, *READ

Required Parameter Group

Clear data
INPUT; CHAR(*)

The data to encrypt.
The format of the clear data is specified in the clear data format name parameter

Length of clear data
INPUT; BINARY(4)

For clear data format DATA0100, this is the length of the data to encrypt. For restrictions on the length of clear data, refer to the clear data length field below.
For clear data format DATA0200, this is the number of entries in the array.

Clear data format name
INPUT; CHAR(8)

The format of the clear data parameter.
The possible format names follow.

DATA0100
The clear data parameter contains the data to encrypt.

DATA0200
The clear data parameter contains an array of pointers and lengths to the data to encrypt.
See Clear Data Formats for a description of this format.

Algorithm description
INPUT; CHAR(*)

The algorithm and associated parameters for encrypting the data.
The format of the algorithm description is specified in the algorithm description format name parameter.

Algorithm description format name
INPUT; CHAR(8)

The format of the algorithm description.
The possible format names follow.

ALGD0100
The token for an algorithm context. This format must be used when performing the encrypt operation over multiple calls. After the last call (when the final operation flag is on), the context will reset to its initial state and can be used in another API. To create an algorithm context, use the Create Algorithm Context (OPM, QC3CRTAX; ILE, Qc3CreateAlgorithmContext) API.

ALGD0200
Parameters for a block cipher algorithm (DES, Triple DES, AES, and RC2).

ALGD0300
Parameters for a stream cipher algorithm (RC4-compatible).

ALGD0400
Parameters for a public key algorithm (RSA).

See Algorithm Description Formats for a description of these formats.

Key description
INPUT; CHAR(*)

The key to use for encrypting the data.
The format of the key description is specified in the key description format name parameter.
If the encrypt operation extends over multiple calls (see ALGD0100 description above), only the key description from the first call will be used. Therefore, on subsequent calls, you may set the pointer to this parameter to NULL.

Key description format name
INPUT; CHAR(8)

The format of the key description.
If the pointer to the key description parameter is NULL, this parameter will be ignored.
The possible format names follow.

KEYD0100
Key context token. This format identifies a key context. A key context is used to store a key value so it need not be recreated or retrieved every time it is used. To create a key context, use the Create Key Context (OPM, QC3CRTKX; ILE, Qc3CreateKeyContext) API.

KEYD0200
Key parameters.

KEYD0400
Keystore label. This format identifies a key from keystore. For more information on cryptographic services keystore, see the Cryptographic Services Keystore topic.

KEYD0500
PKCS5 passphrase. This format derives a key using RSA Data Security, Inc. Public-Key Cryptography Standard (PKCS) #5.

KEYD0600
PEM certificate. This format uses the PKA key in an ASCII encoded PEM based certificate.

KEYD0700
Certificate label. This format uses the public PKA key identified by a label into system certificate keystore (*SYSTEM).

KEYD0800
Distinguished name. This format uses the public PKA key identified by a distinguished name for a certificate in system certificate keystore (*SYSTEM).

KEYD0900
Application identifier. This format uses the private PKA key identified by an application identifier. The application identifier must be assigned to a valid certificate label in system certificate keystore (*SYSTEM).

See Key Description Formats for a description of these formats.

Cryptographic service provider
INPUT; CHAR(1)

The cryptographic service provider (CSP) that will perform the encryption operation.


Cryptographic device name
INPUT; CHAR(10)

The name of a cryptographic device description.
This parameter is valid when the cryptographic service provider parameter specifies 2 (hardware CSP). Otherwise, this parameter must be blanks or the pointer to this parameter set to NULL.

Encrypted data
OUTPUT; CHAR(*)

The area to store the encrypted data.

Length of area provided for encrypted data
INPUT; BINARY(4)

The length of the encrypted data parameter.
If the mode of operation is CFB 1-bit, this length must be specified in bits.
If the length of area provided for encrypted data is too small, an error will be generated and no data will be returned in the encrypted data parameter.


Length of encrypted data returned
OUTPUT; BINARY(4)

The length of encrypted data returned in the encrypted data parameter.
If the mode of operation is CFB 1-bit, this length will be returned in bits.

Error code
I/O; CHAR(*)

The structure in which to return error information.
For the format of the structure, see Error code parameter.


Clear Data Formats

For detailed descriptions of the table fields, see Clear Data Formats Field Descriptions.

DATA0200 Format



Clear Data Formats Field Descriptions

Clear data length
The length of data to encrypt. Some cipher algorithms have restrictions on the clear data length.
DES, Triple DES, AES, RC2
When mode is 0 (ECB), 1 (CBC), 2 (OFB), or 5 (CFB 64-bit) and pad option is 0 (no pad), the total of the clear data lengths for the entire encrypt operation must be a multiple of the block length. For mode 3 (CFB 1-bit), the clear data length is specified in bits, not bytes.
RSA
For PKA block formats 0, 1, and 2, the clear data length must be at least 11 bytes shorter than the key size. For PKA block format 4, the data to encrypt must be shorter than or equal to the key size.
Clear data pointer
A space pointer to the data to encrypt.
Reserved
Must be null (binary 0s).


Algorithm Description Formats

For detailed descriptions of the table fields, see Algorithm Description Formats Field Descriptions. For algorithm standards and resources, see Create Algorithm Context (OPM, QC3CRTAX; ILE, Qc3CreateAlgorithmContext) API.

ALGD0100 Format

ALGD0200 Format

ALGD0300 Format

ALGD0400 Format



Algorithm Description Formats Field Descriptions

Algorithm context token
A token for an algorithm context. The algorithm context is created by using the Create Algorithm Context (OPM, QC3CRTAX; ILE, Qc3CreateAlgorithmContext) API.

Block cipher algorithm
The encryption algorithm. Following are the valid block cipher algorithms.
Block length
The algorithm block length. For DES, Triple DES, and RC2 the block length field must specify 8. The valid block length values for AES are 16, 24, and 32.

Effective key size
For RC2, the number of key bits to use in the cipher operation. Valid values are from 1 to 1024. If RC2 is not specified for the block cipher algorithm, this field must be set to 0.

Final operation flag
The final processing indicator.

Initialization vector or counter
An initialization vector (IV) is used for modes CBC, OFB, CFB, and CUSP. A counter is used for CTR mode. Refer to the mode standards for an explanation of how each mode uses the IV or counter. This field is not used for ECB mode, and must be set to NULL (binary 0s).
For DES, Triple DES, and RC2, the first 8 bytes are used as the IV/counter. For AES, the length is that specified by block length.
The IV/Counter need not be secret, but it should be unique for each message. For CBC, CFB, and CUSP modes, the IV must be significantly unique. If not unique, it may compromise security.
The IV can be any value. To obtain a good random IV or counter value, use the Generate Pseudorandom Numbers (OPM, QC3GENPRN; ILE, Qc3GenPRNs)API.

MAC length
This field is not used on an encrypt operation and must be set to null (binary 0s).

Mode
The mode of operation. Information on modes can be found in FIPS PUB 81, NIST Special Publication 800-38A, and ANSI X9.52. Following are the valid modes.
Pad character
The pad character for pad option 1. Using hex 00 as the pad character is equivalent to ANSI X9.23 padding.

Pad option
If requested, padding is performed at the end of the encrypt operation. Be sure the encrypted data parameter is large enough to include any padding. The data will be padded up to the next block length byte multiple. For example, when using DES and total data to encrypt is 20, the text is padded to 24. The last byte is filled with a 1-byte binary counter containing the number of pad characters used. The preceeding pad characters are filled as specified by this field. Padding is not performed for modes CFB 1-bit, CFB 8-bit, and CUSP. In these cases, the pad option must be set to 0. Following are the valid pad options.
PKA block format
The public key algorithm block format. Following are the valid values.
Public key cipher algorithm
The encryption algorithm. Following are the valid public key cipher algorithms.
Reserved
Must be null (binary 0s).

Signing hash algorithm
This field is not used on an encrypt operation and must be set to null (binary 0s).

Stream cipher algorithm
The encryption algorithm. Following are the valid stream cipher algorithms.

Key Description Formats

For detailed descriptions of the table fields, see Key Description Formats Field Descriptions.

KEYD0100 Format


KEYD0200 Format

KEYD0400 Format

KEYD0500 Format

KEYD0600 Format

KEYD0700 Format

KEYD0800 Format

KEYD0900 Format



Key Description Formats Field Descriptions

Application identifer
The application ID assigned to a certificate with a private key in system certificate keystore (*SYSTEM).

Application identifier length
The length of the application ID. The length can not be greater than 32.

Certificate label
The label of the certificate in system certificate keystore (*SYSTEM). The certificate's public key will be used in the encryption operation.

Certificate label length
The length of the certificate label.

Derived key length
The length of key requested. The minimum allowed length is 1.

Distinguished name
The distinguished name of the certificate in system certificate keystore (*SYSTEM). The certificate's public key will be used in the encryption operation.

Distinguished name length
The length of the distinguished name.

File name
The name of a keystore file. Keystore files are created by using the Create Keystore (OPM, QC3CRTKS; ILE, Qc3CreateKeyStore) API.

Iteration count
Used to greatly increase the cost of an exhaustive search while modestly increasing the cost of key derivation. The minimum allowed value is 1. The standard recommends a minimum of 1000. The maximum allowed length is 100,000.
Key context token
A token for a key context. The key context is created by using the Create Key Context (OPM, QC3CRTKX; ILE, Qc3CreateKeyContext) API.

Key format
The format of the key string field. Following are the valid values.
Key string
The key to use in the encrypt operation.

Key string length
Length of the key string specified in the key string field.

Key type
The type of key. Following are the valid values.
Passphrase
A text string.

Passphrase CCSID
INPUT; BINARY(4)

The CCSID of the passphrase. The passphrase will be converted from the specified CCSID to Unicode before calling the PKCS5 algorithm.


Passphrase length
The length of passphrase. The length must be in the range of 1 to 256.

PEM certificate
An ASCII encoded PEM formated certificate.

PEM certificate length
The length of the PEM certificate.

Qualified keystore file name
The keystore file where the key is stored. Keystore files are created by using the Create Keystore (OPM, QC3CRTKS; ILE, Qc3CreateKeyStore) API. The first 10 characters contain the file name. The second 10 characters contain the name of the library where the keystore file is located. You can use the following special values for the library name.
Record label
The label of a key record in a keystore file. The label will be converted from the job CCSID, or if 65535, the job default CCSID (DFTCCSID) job attribute to CCSID 1200 (Unicode UTF-16). Key records are created by using the Write Key Record (OPM, QC3WRTKR; ILE, Qc3WriteKeyRecord) API or the Generate Key Record (OPM, QC3GENKR; ILE, Qc3GenKeyRecord) API.

Reserved
Must be null (binary 0s).

Salt
Used to help thwart attacks by producing a large set of keys for each passphrase. The standard recommends the salt be generated at random and be at least 8 bytes long. You can use the Generate Pseudorandom Numbers (OPM, QC3GENPRN; ILE, Qc3GenPRNs) API to obtain a random value. Additionally, data that distinguishes between various operations can be added to the salt for additional security. Refer to the standard for more information.

Salt length
The length of salt. The length must be in the range of 1 to 16.

Error Messages



API introduced: V5R3

[ Back to top | Cryptographic Services APIs | APIs by category ]