Jws Unicode C Reference Documentation

Jws

Current Version: 10.1.2

An API for JSON Web Signature (JWS). Provides the ability to create and verify JWSs.

Create/Dispose

HCkJwsW instance = CkJwsW_Create();
// ...
CkJwsW_Dispose(instance);
HCkJwsW CkJwsW_Create(void);

Creates an instance of the HCkJwsW object and returns a handle ("void *" pointer). The handle is passed in the 1st argument for the functions listed on this page.

void CkJwsW_Dispose(HCkJwsW handle);

Objects created by calling CkJwsW_Create must be freed by calling this method. A memory leak occurs if a handle is not disposed by calling this function. Also, any handle returned by a Chilkat "C" function must also be freed by the application by calling the appropriate Dispose method, such as CkJwsW_Dispose.

Properties

DebugLogFilePath
void CkJwsW_getDebugLogFilePath(HCkJwsW cHandle, HCkString retval);
void CkJwsW_putDebugLogFilePath(HCkJwsW cHandle, const wchar_t *newVal);
const wchar_t *CkJwsW_debugLogFilePath(HCkJwsW cHandle);

If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.

Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.

Possible causes of hangs include:

  • A timeout property set to 0, indicating an infinite timeout.
  • A hang occurring within an event callback in the application code.
  • An internal bug in the Chilkat code causing the hang.

More Information and Examples
top
LastErrorHtml
void CkJwsW_getLastErrorHtml(HCkJwsW cHandle, HCkString retval);
const wchar_t *CkJwsW_lastErrorHtml(HCkJwsW cHandle);

Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorText
void CkJwsW_getLastErrorText(HCkJwsW cHandle, HCkString retval);
const wchar_t *CkJwsW_lastErrorText(HCkJwsW cHandle);

Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastErrorXml
void CkJwsW_getLastErrorXml(HCkJwsW cHandle, HCkString retval);
const wchar_t *CkJwsW_lastErrorXml(HCkJwsW cHandle);

Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

top
LastMethodSuccess
BOOL CkJwsW_getLastMethodSuccess(HCkJwsW cHandle);
void CkJwsW_putLastMethodSuccess(HCkJwsW cHandle, BOOL newVal);

Indicates the success or failure of the most recent method call: TRUE means success, FALSE means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages.

top
NumSignatures
int CkJwsW_getNumSignatures(HCkJwsW cHandle);
Introduced in version 9.5.0.66

The number of signatures contained in this JWS.

top
PreferCompact
BOOL CkJwsW_getPreferCompact(HCkJwsW cHandle);
void CkJwsW_putPreferCompact(HCkJwsW cHandle, BOOL newVal);
Introduced in version 9.5.0.66

Controls whether to use the JWS Compact Serialization or JWS JSON Serialization when creating JWSs. The default value is TRUE, which is to choose the compact serialization when possible. If multiple signatures exist, or if any unprotected headers exist, then JWS JSON Serialization is used regardless of this property setting.

top
PreferFlattened
BOOL CkJwsW_getPreferFlattened(HCkJwsW cHandle);
void CkJwsW_putPreferFlattened(HCkJwsW cHandle, BOOL newVal);
Introduced in version 9.5.0.66

Controls whether to use the flattened or general JWE JSON Serialization when creating JWSs. The default value is TRUE, which is to choose the flattened serialization when possible. If multiple signatures exist, then the general (non-flattened) JWS JSON Serialization is used regardless of this property setting.

top
UncommonOptions
void CkJwsW_getUncommonOptions(HCkJwsW cHandle, HCkString retval);
void CkJwsW_putUncommonOptions(HCkJwsW cHandle, const wchar_t *newVal);
const wchar_t *CkJwsW_uncommonOptions(HCkJwsW cHandle);
Introduced in version 10.1.0

This is a catch-all property to be used for uncommon needs. This property defaults to the empty string and should typically remain empty.

top
VerboseLogging
BOOL CkJwsW_getVerboseLogging(HCkJwsW cHandle);
void CkJwsW_putVerboseLogging(HCkJwsW cHandle, BOOL newVal);

If set to TRUE, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is FALSE. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

top
Version
void CkJwsW_getVersion(HCkJwsW cHandle, HCkString retval);
const wchar_t *CkJwsW_version(HCkJwsW cHandle);

Version of the component/library, such as "10.1.0"

More Information and Examples
top

Methods

CreateJws
BOOL CkJwsW_CreateJws(HCkJwsW cHandle, const wchar_t *outStr);
const wchar_t *CkJwsW_createJws(HCkJwsW cHandle);
Introduced in version 9.5.0.66

Creates and returns the JWS containing one or more signatures according to the previously set payload, headers, and keys.

Returns TRUE for success, FALSE for failure.

top
CreateJwsSb
BOOL CkJwsW_CreateJwsSb(HCkJwsW cHandle, HCkStringBuilderW sbJws);
Introduced in version 9.5.0.66

Creates and returns the JWS by appending it to the contents of sbJws.

Returns TRUE for success, FALSE for failure.

top
GetPayload
BOOL CkJwsW_GetPayload(HCkJwsW cHandle, const wchar_t *charset, const wchar_t *outStr);
const wchar_t *CkJwsW_getPayload(HCkJwsW cHandle, const wchar_t *charset);
Introduced in version 9.5.0.66

Returns the JWS payload. The charset specifies the byte representation to be used in interpreting the bytes of the payload. (For example, "utf-8", "windows-1252", "utf-16", etc.)

Returns TRUE for success, FALSE for failure.

More Information and Examples
top
GetPayloadBd
BOOL CkJwsW_GetPayloadBd(HCkJwsW cHandle, HCkBinDataW binData);
Introduced in version 9.5.0.66

Returns the JWS payload by appending it to the binData.

Returns TRUE for success, FALSE for failure.

top
GetPayloadSb
BOOL CkJwsW_GetPayloadSb(HCkJwsW cHandle, const wchar_t *charset, HCkStringBuilderW sbPayload);
Introduced in version 9.5.0.66

Returns the JWS payload by appending it to the sbPayload. The charset specifies the byte representation to be used in interpreting the bytes of the payload. (For example, "utf-8", "windows-1252", "utf-16", etc.)

Returns TRUE for success, FALSE for failure.

top
GetProtectedHeader
HCkJsonObjectW CkJwsW_GetProtectedHeader(HCkJwsW cHandle, int index);
Introduced in version 9.5.0.66

Returns the protected header for the Nth signature. The index is the index of the signature. The 1st signature is at index 0. In most cases, a JWS contains a single signature at index 0.

Returns NULL on failure

More Information and Examples
top
GetUnprotectedHeader
HCkJsonObjectW CkJwsW_GetUnprotectedHeader(HCkJwsW cHandle, int index);
Introduced in version 9.5.0.66

Returns the optional unprotected header for the Nth signature. The index is the index of the signature. The 1st signature is at index 0. In most cases, a JWS contains a single signature at index 0.

Returns NULL on failure

top
LoadJws
BOOL CkJwsW_LoadJws(HCkJwsW cHandle, const wchar_t *jwsStr);
Introduced in version 9.5.0.66

Loads a JWS contained in jwsStr.

Returns TRUE for success, FALSE for failure.

More Information and Examples
top
LoadJwsSb
BOOL CkJwsW_LoadJwsSb(HCkJwsW cHandle, HCkStringBuilderW sbJws);
Introduced in version 9.5.0.66

Loads a JWS from the contents of sbJws.

Returns TRUE for success, FALSE for failure.

More Information and Examples
top
SetMacKey
BOOL CkJwsW_SetMacKey(HCkJwsW cHandle, int index, const wchar_t *key, const wchar_t *encoding);
Introduced in version 9.5.0.66

Sets the MAC key to be used for creating or validating a signature for the algorithms "HS256", "HS384", or "HS512". The key is an encoded string representation of the MAC key bytes. The encoding is an encoding, such as "base64url", "base64", "hex", etc. The 1st signature is at index 0. (Most JWSs only contain a single signature.)

Returns TRUE for success, FALSE for failure.

More Information and Examples
top
SetMacKeyBd
BOOL CkJwsW_SetMacKeyBd(HCkJwsW cHandle, int index, HCkBinDataW key);
Introduced in version 9.5.0.66

Sets the MAC key to be used for creating or validating a signature for the algorithms "HS256", "HS384", or "HS512". The key contains the binary bytes of the MAC key for the Nth signature. The 1st signature is at index 0.

Returns TRUE for success, FALSE for failure.

top
SetPayload
BOOL CkJwsW_SetPayload(HCkJwsW cHandle, const wchar_t *payload, const wchar_t *charset, BOOL includeBom);
Introduced in version 9.5.0.66

Sets the JWS payload from the contents of payload. The charset specifies the byte representation to be used for the string that is to be the payload. (For example, "utf-8", "windows-1252", "utf-16", etc.). If includeBom is TRUE, then the byte-order-mark (BOM), also known as preamble, if one exists for the given charset, is included in the payload. Normally, includeBom should be set to FALSE.

Returns TRUE for success, FALSE for failure.

More Information and Examples
top
SetPayloadBd
BOOL CkJwsW_SetPayloadBd(HCkJwsW cHandle, HCkBinDataW binData);
Introduced in version 9.5.0.66

Sets the JWS payload from the contents of binData.

Returns TRUE for success, FALSE for failure.

top
SetPayloadSb
BOOL CkJwsW_SetPayloadSb(HCkJwsW cHandle, HCkStringBuilderW sbPayload, const wchar_t *charset, BOOL includeBom);
Introduced in version 9.5.0.66

Sets the JWS payload from the contents of sbPayload. The charset specifies the byte representation to be used for the string that is to be the payload. (For example, "utf-8", "windows-1252", "utf-16", etc.). If includeBom is TRUE, then the byte-order-mark (BOM), also known as preamble, if one exists for the given charset, is included in the payload. Normally, includeBom should be set to FALSE.

Returns TRUE for success, FALSE for failure.

top
SetPrivateKey
BOOL CkJwsW_SetPrivateKey(HCkJwsW cHandle, int index, HCkPrivateKeyW privKey);
Introduced in version 9.5.0.66

Sets the private key (ECC or RSA) to be used in creating a signature for the following algorithms:

RS256
RS384
RS512
ES256
ES384
ES512
PS256
PS384
PS512
The JWS algorithms are described in RFC 7518, section 3.1. Here is a summary:
   +--------------+-------------------------------+--------------------+
   | "alg" Param  | Digital Signature or MAC      | Implementation     |
   | Value        | Algorithm                     | Requirements       |
   +--------------+-------------------------------+--------------------+
   | HS256        | HMAC using SHA-256            | Required           |
   | HS384        | HMAC using SHA-384            | Optional           |
   | HS512        | HMAC using SHA-512            | Optional           |
   | RS256        | RSASSA-PKCS1-v1_5 using       | Recommended        |
   |              | SHA-256                       |                    |
   | RS384        | RSASSA-PKCS1-v1_5 using       | Optional           |
   |              | SHA-384                       |                    |
   | RS512        | RSASSA-PKCS1-v1_5 using       | Optional           |
   |              | SHA-512                       |                    |
   | ES256        | ECDSA using P-256 and SHA-256 | Recommended+       |
   | ES384        | ECDSA using P-384 and SHA-384 | Optional           |
   | ES512        | ECDSA using P-521 and SHA-512 | Optional           |
   | PS256        | RSASSA-PSS using SHA-256 and  | Optional           |
   |              | MGF1 with SHA-256             |                    |
   | PS384        | RSASSA-PSS using SHA-384 and  | Optional           |
   |              | MGF1 with SHA-384             |                    |
   | PS512        | RSASSA-PSS using SHA-512 and  | Optional           |
   |              | MGF1 with SHA-512             |                    |
   | none         | No digital signature or MAC   | Optional           |
   |              | performed                     |                    |
   +--------------+-------------------------------+--------------------+

Returns TRUE for success, FALSE for failure.

top
SetProtectedHeader
BOOL CkJwsW_SetProtectedHeader(HCkJwsW cHandle, int index, HCkJsonObjectW json);
Introduced in version 9.5.0.66

Sets a signature's protected header. The index is the index of the signature. The 1st signature is at index 0. In most cases, a JWS contains a single signature at index 0.

Returns TRUE for success, FALSE for failure.

More Information and Examples
top
SetPublicKey
BOOL CkJwsW_SetPublicKey(HCkJwsW cHandle, int index, HCkPublicKeyW pubKey);
Introduced in version 9.5.0.66

Sets the public key (ECC or RSA) to be used in validating a signature for the following algorithms:

RS256
RS384
RS512
ES256
ES384
ES512
PS256
PS384
PS512

Returns TRUE for success, FALSE for failure.

top
SetUnprotectedHeader
BOOL CkJwsW_SetUnprotectedHeader(HCkJwsW cHandle, int index, HCkJsonObjectW json);
Introduced in version 9.5.0.66

Sets a signature's optional unprotected header. The index is the index of the signature. The 1st signature is at index 0. In most cases, a JWS contains a single signature at index 0.

Returns TRUE for success, FALSE for failure.

top
Validate
int CkJwsW_Validate(HCkJwsW cHandle, int index);
Introduced in version 9.5.0.66

Validates the Nth signature or MAC using the Nth public key or MAC key.

Returns 1 if the signature was validated, thus verifying that the signer used the same MAC key or the matching private key.
Returns 0 if the incorrect public key or MAC key was provided.
Returns -1 for any other error, such as if no public key or MAC key was previously set for the given index.

Prior to calling this method, a program should provide the public key or MAC key via the SetPublicKey, SetMacKey, or SetMacKeyBd methods.

top