Jws Delphi DLL Reference Documentation

Jws

Current Version: 10.0.0

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

Create/Dispose

var
myObject: HCkJws;

begin
myObject := CkJws_Create();

// ...

CkJws_Dispose(myObject);
end;
function CkJws_Create: HCkJws; stdcall;

Creates an instance of the HCkJws object and returns a handle (i.e. a Pointer). The handle is passed in the 1st argument for the functions listed on this page.

procedure CkJws_Dispose(handle: HCkJws); stdcall;

Objects created by calling CkJws_Create must be freed by calling this method. A memory leak occurs if a handle is not disposed by calling this function.

Properties

DebugLogFilePath
procedure CkJws_getDebugLogFilePath(objHandle: HCkJws; outPropVal: HCkString); stdcall;
procedure CkJws_putDebugLogFilePath(objHandle: HCkJws; newPropVal: PWideChar); stdcall;
function CkJws__debugLogFilePath(objHandle: HCkJws): PWideChar; stdcall;

If set to a file path, causes each Chilkat method or property call to automatically append it's LastErrorText to the specified log file. The information is appended such that if a hang or crash occurs, it is possible to see the context in which the problem occurred, as well as a history of all Chilkat calls up to the point of the problem. The VerboseLogging property can be set to provide more detailed information.

This property is typically used for debugging the rare cases where a Chilkat method call hangs or generates an exception that halts program execution (i.e. crashes). A hang or crash should generally never happen. The typical causes of a hang are:

  1. a timeout related property was set to 0 to explicitly indicate that an infinite timeout is desired,
  2. the hang is actually a hang within an event callback (i.e. it is a hang within the application code), or
  3. there is an internal problem (bug) in the Chilkat code that causes the hang.

See the notes about PWideChar memory ownership and validity.

More Information and Examples
top
LastErrorHtml
procedure CkJws_getLastErrorHtml(objHandle: HCkJws; outPropVal: HCkString); stdcall;
function CkJws__lastErrorHtml(objHandle: HCkJws): PWideChar; stdcall;

Provides information in HTML format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

See the notes about PWideChar memory ownership and validity.

top
LastErrorText
procedure CkJws_getLastErrorText(objHandle: HCkJws; outPropVal: HCkString); stdcall;
function CkJws__lastErrorText(objHandle: HCkJws): PWideChar; stdcall;

Provides information in plain-text format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

See the notes about PWideChar memory ownership and validity.

top
LastErrorXml
procedure CkJws_getLastErrorXml(objHandle: HCkJws; outPropVal: HCkString); stdcall;
function CkJws__lastErrorXml(objHandle: HCkJws): PWideChar; stdcall;

Provides information in XML format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

See the notes about PWideChar memory ownership and validity.

top
LastMethodSuccess
function CkJws_getLastMethodSuccess(objHandle: HCkJws): wordbool; stdcall;
procedure CkJws_putLastMethodSuccess(objHandle: HCkJws; newPropVal: wordbool); stdcall;

Indicate whether the last method call succeeded or failed. A value of True indicates success, a value of False indicates failure. This property is automatically set for method calls. It is not modified by property accesses. The property is automatically set to indicate success for the following types of method calls:

  • Any method that returns a string.
  • Any method returning a Chilkat object, binary bytes, or a date/time.
  • Any method returning a standard boolean status value where success = True and failure = False.
  • Any method returning an integer where failure is defined by a return value less than zero.

Note: Methods that do not fit the above requirements will always set this property equal to True. For example, a method that returns no value (such as a "void" in C++) will technically always succeed.

top
NumSignatures
function CkJws_getNumSignatures(objHandle: HCkJws): Integer; stdcall;
Introduced in version 9.5.0.66

The number of signatures contained in this JWS.

top
PreferCompact
function CkJws_getPreferCompact(objHandle: HCkJws): wordbool; stdcall;
procedure CkJws_putPreferCompact(objHandle: HCkJws; newPropVal: wordbool); stdcall;
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
function CkJws_getPreferFlattened(objHandle: HCkJws): wordbool; stdcall;
procedure CkJws_putPreferFlattened(objHandle: HCkJws; newPropVal: wordbool); stdcall;
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
VerboseLogging
function CkJws_getVerboseLogging(objHandle: HCkJws): wordbool; stdcall;
procedure CkJws_putVerboseLogging(objHandle: HCkJws; newPropVal: wordbool); stdcall;

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
procedure CkJws_getVersion(objHandle: HCkJws; outPropVal: HCkString); stdcall;
function CkJws__version(objHandle: HCkJws): PWideChar; stdcall;

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

See the notes about PWideChar memory ownership and validity.

More Information and Examples
top

Methods

CreateJws
function CkJws_CreateJws(objHandle: HCkJws;
    outStr: HCkString): wordbool; stdcall;
function CkJws__createJws(objHandle: HCkJws): PWideChar; stdcall;
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.

See the notes about PWideChar memory ownership and validity.

top
CreateJwsSb
function CkJws_CreateJwsSb(objHandle: HCkJws;
    sbJws: HCkStringBuilder): wordbool; stdcall;
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
function CkJws_GetPayload(objHandle: HCkJws;
    charset: PWideChar;
    outStr: HCkString): wordbool; stdcall;
function CkJws__getPayload(objHandle: HCkJws;
    charset: PWideChar): PWideChar; stdcall;
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.

See the notes about PWideChar memory ownership and validity.

More Information and Examples
top
GetPayloadBd
function CkJws_GetPayloadBd(objHandle: HCkJws;
    binData: HCkBinData): wordbool; stdcall;
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
function CkJws_GetPayloadSb(objHandle: HCkJws;
    charset: PWideChar;
    sbPayload: HCkStringBuilder): wordbool; stdcall;
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
function CkJws_GetProtectedHeader(objHandle: HCkJws;
    index: Integer): HCkJsonObject; stdcall;
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 nil on failure

More Information and Examples
top
GetUnprotectedHeader
function CkJws_GetUnprotectedHeader(objHandle: HCkJws;
    index: Integer): HCkJsonObject; stdcall;
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 nil on failure

top
LoadJws
function CkJws_LoadJws(objHandle: HCkJws;
    jwsStr: PWideChar): wordbool; stdcall;
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
function CkJws_LoadJwsSb(objHandle: HCkJws;
    sbJws: HCkStringBuilder): wordbool; stdcall;
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
function CkJws_SetMacKey(objHandle: HCkJws;
    index: Integer;
    key: PWideChar;
    encoding: PWideChar): wordbool; stdcall;
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
function CkJws_SetMacKeyBd(objHandle: HCkJws;
    index: Integer;
    key: HCkBinData): wordbool; stdcall;
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
function CkJws_SetPayload(objHandle: HCkJws;
    payload: PWideChar;
    charset: PWideChar;
    includeBom: wordbool): wordbool; stdcall;
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
function CkJws_SetPayloadBd(objHandle: HCkJws;
    binData: HCkBinData): wordbool; stdcall;
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
function CkJws_SetPayloadSb(objHandle: HCkJws;
    sbPayload: HCkStringBuilder;
    charset: PWideChar;
    includeBom: wordbool): wordbool; stdcall;
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
function CkJws_SetPrivateKey(objHandle: HCkJws;
    index: Integer;
    privKey: HCkPrivateKey): wordbool; stdcall;
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
function CkJws_SetProtectedHeader(objHandle: HCkJws;
    index: Integer;
    json: HCkJsonObject): wordbool; stdcall;
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
function CkJws_SetPublicKey(objHandle: HCkJws;
    index: Integer;
    pubKey: HCkPublicKey): wordbool; stdcall;
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
function CkJws_SetUnprotectedHeader(objHandle: HCkJws;
    index: Integer;
    json: HCkJsonObject): wordbool; stdcall;
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
function CkJws_Validate(objHandle: HCkJws;
    index: Integer): Integer; stdcall;
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