IPWorks Encrypt 2020 C++ Edition

Questions / Feedback?

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_JWS_ADDHEADERPARAM 2

IPWORKSENCRYPT_EXTERNAL int IPWORKSENCRYPT_CALL IPWorksEncrypt_JWS_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 Sign.

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)
To add additional parameters to the JOSE header use this method. For instance to create this header:


{
  "alg": "HS512",
  "crit": [
    "exp"
  ],
  "exp": 12345687,
  "kid": "myKeyId",
  "type": "JWT"
}

The following code can be used:


jws.Algorithm = JwsAlgorithms.jwsHS512;
jws.KeyId = "myKeyId";
jws.KeyB = key;
jws.AddHeaderParam("type", "JWT", 2);
jws.AddHeaderParam("crit", "[\"exp\"]", 1);
jws.AddHeaderParam("exp", "12345687", 3);
jws.InputMessage = "test";
jws.Sign();
string signedData = jws.OutputMessage;

Note: when calling Sign the class will automatically add some headers based on properties that are set.

Parameters Automatically Set:

Header ParamProperty
algAlgorithm
kidKeyId

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.)

Copyright (c) 2022 /n software inc. - All rights reserved.
IPWorks Encrypt 2020 C++ Edition - Version 20.0 [Build 8155]