AddHeaderParam Method
Adds additional header parameters.
Syntax
ANSI (Cross Platform) int AddHeaderParam(const char* lpszname, const char* lpszvalue, int idataType); Unicode (Windows) INT AddHeaderParam(LPCWSTR lpszname, LPCWSTR lpszvalue, INT idataType);
- (void)addHeaderParam:(NSString*)name :(NSString*)value :(int)dataType;
#define MID_JWE_ADDHEADERPARAM 2 IPWORKSENCRYPT_EXTERNAL int IPWORKSENCRYPT_CALL IPWorksEncrypt_JWE_Do(void *lpObj, int methid, int cparam, void *param[], int cbparam[], int64 *lpllVal);
Remarks
This method is used to add additional header parameters before calling Encrypt.
The Name and Value parameters define the name and value of the parameter respectively. The DataType parameter specifies the JSON data type of the value. Possible values for DataType are:
- 0 (Object)
- 1 (Array)
- 2 (String)
- 3 (Number)
- 4 (Bool)
- 5 (Null)
{
"alg"
:
"A256GCMKW"
,
"crit"
: [
"exp"
],
"enc"
:
"A128CBC-HS256"
,
"exp"
: 12345687,
"iv"
:
"SFZ9o0KKN8qF8yod"
,
"tag"
:
"tREHGKuViLo7s3QpRTulkg"
,
"type"
:
"JWT"
}
The following code can be used:
Jwe jwe =
new
Jwe();
jwe.EncryptionAlgorithm = JweEncryptionAlgorithms.eaA256GCMKW;
jwe.KeyB = key;
jwe.AddHeaderParam(
"type"
,
"JWT"
, 2);
jwe.AddHeaderParam(
"crit"
,
"[\"exp\"]"
, 1);
jwe.AddHeaderParam(
"exp"
,
"12345687"
, 3);
jwe.InputMessage =
"test"
;
jwe.Encrypt();
string
encryptedData = jwe.OutputMessage;
Note: When calling Encrypt the class will automatically add headers based on the selected EncryptionAlgorithm and other properties that may be set.
Parameters Automatically Set:
Header Param | Property |
alg | EncryptionAlgorithm |
enc | ContentEncryptionAlgorithm |
kid | KeyId |
zip | CompressionAlgorithm |
p2c | PBES2Count (PBES Algorithms Only) |
apu | PartyUInfo (ECDH Algorithms Only) |
apv | PartyVInfo (ECDH Algorithms Only) |
iv | N/A - Automatically Generated (AES Algorithms Only) |
tag | N/A - Automatically Generated (AES Algorithms Only) |
p2s | N/A - Automatically Generated (PBES Algorithms Only) |
epk | N/A - Automatically Generated (ECDH Algorithms Only) |
Error Handling (C++)
This method returns a result code; 0 indicates success, while a non-zero error code indicates that this method encountered an error during its execution. If an error occurs, the GetLastError() method can be called to retrieve the associated error message. (Note: This method's result code can also be obtained by calling the GetLastErrorCode() method after it returns.)