Jws ActiveX Reference Documentation

Jws

Current Version: 11.5.0

Chilkat.Jws

Create, serialize, load, inspect, and validate JSON Web Signatures.

Chilkat.Jws is the Chilkat class for creating and validating JSON Web Signatures. It supports compact serialization, flattened JSON serialization, general JSON serialization, single or multiple signatures, protected and unprotected headers, text and binary payloads, detached or embedded payload workflows, and signature algorithms such as HMAC, RSA, ECDSA, and RSA-PSS.

Create JWS signatures

Sign text or binary payloads using the key type and algorithm required by the target protocol or application.

Validate signed data

Load a JWS and verify its signature using the matching shared secret, public key, certificate, or other verification key.

Compact and JSON forms

Use compact serialization for common single-signature workflows, or JSON serialization when headers, multiple signatures, or richer structure is needed.

Multiple signatures

Use general JSON serialization when the same payload must be signed by more than one key or party.

Header control

Set protected and unprotected header fields such as alg, kid, typ, cty, or other protocol-specific values.

Algorithm flexibility

Work with HMAC, RSA, ECDSA, and RSA-PSS signatures depending on the trust model, key material, and interoperability requirements.

Common pattern: Choose the JWS serialization format, set the protected header values such as alg, provide the payload, add one or more signing keys, and create the JWS. To verify, load the JWS, provide the matching verification key for the signature, validate it, and then retrieve or inspect the payload and headers.

Object Creation

Note:
For a specific major version, use "Chilkat.Jws.<major_version>", such as "Chilkat.Jws.10" for Chilkat v10.*.*
See Chilkat ActiveX Object Creation

(ASP)
set obj = Server.CreateObject("Chilkat.Jws")

(AutoIt)
$obj = ObjCreate("Chilkat.Jws")

(Visual Basic 6.0)
Dim obj As New ChilkatJws

(VBScript)
set obj = CreateObject("Chilkat.Jws")

(VBA, such as Excel)
Dim obj As New ChilkatJws
See How to Use ActiveX in Excel

(Delphi)
obj := TChilkatJws.Create(Self);

(FoxPro)
loObject = CreateObject('Chilkat.Jws')

(PowerBuilder)
lole_object = create oleobject
li_rc = lole_object.ConnectToNewObject("Chilkat.Jws")

(SQL Server)
EXEC @hr = sp_OACreate 'Chilkat.Jws', @obj OUT

(Javascript)
var obj = new ActiveXObject("Chilkat.Jws");

Properties

DebugLogFilePath
DebugLogFilePath As String

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.

top
LastBinaryResult
LastBinaryResult As Variant (read-only)

This property is mainly used in SQL Server stored procedures to retrieve binary data from the last method call that returned binary data. It is only accessible if Chilkat.Global.KeepBinaryResult is set to 1. This feature allows for the retrieval of large varbinary results in an SQL Server environment, which has restrictions on returning large data via method calls, though temp tables can handle binary properties.

top
LastErrorHtml
LastErrorHtml As String (read-only)

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
LastErrorText As String (read-only)

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
LastErrorXml As String (read-only)

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
LastMethodSuccess As Long

Indicates the success or failure of the most recent method call: 1 means success, 0 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. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.

top
LastStringResult
LastStringResult As String (read-only)

In SQL Server stored procedures, this property holds the string return value of the most recent method call that returns a string. It is accessible only when Chilkat.Global.KeepStringResult is set to TRUE. SQL Server has limitations on string lengths returned from methods and properties, but temp tables can be used to access large strings.

top
LastStringResultLen
LastStringResultLen As Long (read-only)

The length, in characters, of the string contained in the LastStringResult property.

top
NumSignatures
NumSignatures As Long (read-only)
Introduced in version 9.5.0.66

Returns the number of signatures currently represented by this object.

After loading a JWS, this is the number of signatures found in the serialization. During JWS creation, it reflects the configured signature indexes. Compact and flattened JSON serializations contain one signature; general JWS JSON Serialization can contain one or more.

top
PreferCompact
PreferCompact As Long
Introduced in version 9.5.0.66

Controls whether Chilkat prefers JWS Compact Serialization when creating a JWS. The default is 1.

SettingBehavior when permitted
1Use the compact form protected.payload.signature.
0Use JWS JSON Serialization, with PreferFlattened selecting flattened or general form when possible.

Compact Serialization is possible only for a single signature and has no unprotected-header member. If multiple signatures or any unprotected header is configured, Chilkat uses JWS JSON Serialization regardless of this property.

Format choice does not change the signature algorithm: Compact, flattened, and general forms represent the same JWS security model. Choose the form required by the surrounding protocol and data model.

top
PreferFlattened
PreferFlattened As Long
Introduced in version 9.5.0.66

Controls whether Chilkat prefers flattened JWS JSON Serialization when JSON serialization is used. The default is 1.

SettingBehavior for one signature
1Use flattened JSON, placing protected, header, and signature directly in the top-level object.
0Use general JSON, placing signature objects in the top-level signatures array.

When more than one signature exists, general JWS JSON Serialization is required and this preference is ignored. This property has no effect when Compact Serialization is selected.

top
UncommonOptions
UncommonOptions As String
Introduced in version 10.1.0

Provides a catch-all string for specialized compatibility options that are not exposed as ordinary properties. The default is an empty string, which is appropriate for normal use.

Leave empty unless specifically documented: Set this property only when a Chilkat example, release note, or support response identifies an exact option needed for an unusual interoperability case. Undocumented values should not be used as a substitute for ordinary JOSE headers or application security policy.

top
VerboseLogging
VerboseLogging As Long

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

top
Version
Version As String (read-only)

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

top

Methods

CreateJws
CreateJws() As String
Introduced in version 9.5.0.66

Creates and returns a JWS from the payload, headers, and signing or MAC keys previously configured on this object. The result contains one signature for each configured signature index.

The serialization format is selected by PreferCompact and PreferFlattened, subject to the structural requirements of JWS: Compact Serialization can contain only one signature and no unprotected header; flattened JSON can contain only one signature; general JSON is used for multiple signatures.

Required setup: Set the payload, set a protected header containing an appropriate alg value for each signature, and provide the matching MAC key, private key, or signing certificate before calling this method.
JWS provides authenticity and integrity, not confidentiality: The payload is normally readable by anyone who receives the JWS. Use JWE when the payload must also be encrypted.

Returns Nothing on failure

top
CreateJwsSb
CreateJwsSb(sbJws As ChilkatStringBuilder) As Long
Introduced in version 9.5.0.66

Creates a JWS from the payload, headers, and keys previously configured on this object and appends the serialized JWS to sbJws.

The same serialization-selection rules as CreateJws apply. Existing text in the destination StringBuilder is preserved because the new JWS is appended rather than replacing it.

Check the return value: Use the appended output only when the method returns 1. On failure, inspect LastErrorText for missing headers, keys, payload state, or an unsupported key/algorithm combination.

Returns 1 for success, 0 for failure.

top
GetPayload
GetPayload(charset As String) As String
Introduced in version 9.5.0.66

Returns the loaded JWS payload as text by interpreting the payload bytes using the character encoding named by charset, such as utf-8, windows-1252, or utf-16.

If the payload is binary or its text encoding is unknown, use GetPayloadBd to retrieve the exact bytes.

Validate before trusting: This method extracts data; it does not validate a signature. Treat the returned string as untrusted until Validate returns 1 for every signature required by the application.

Returns Nothing on failure

top
GetPayloadBd
GetPayloadBd(binData As ChilkatBinData) As Long
Introduced in version 9.5.0.66

Appends the exact payload bytes from the loaded JWS to binData. Existing bytes in the destination BinData are preserved.

This method performs no character-set conversion and is therefore appropriate for binary payloads or when the original payload bytes must be retained exactly.

Validate before trusting: Payload extraction is separate from signature validation. Do not treat the returned bytes as authentic until Validate returns 1 for the signature or signatures required by the application.

Returns 1 for success, 0 for failure.

top
GetPayloadSb
GetPayloadSb(charset As String, sbPayload As ChilkatStringBuilder) As Long
Introduced in version 9.5.0.66

Interprets the loaded JWS payload bytes using the character encoding named by charset and appends the resulting text to sbPayload. Existing text in the destination StringBuilder is preserved.

Use the same charset that was used to create the payload. If the payload is binary or its encoding is unknown, use GetPayloadBd instead.

Validate before trusting: Loading a JWS and reading its payload does not verify its signature. Treat the returned text as untrusted until Validate returns 1 for the required signature or signatures.

Returns 1 for success, 0 for failure.

top
GetProtectedH
GetProtectedH(ByVal index As Long, json As ChilkatJsonObject) As Long
Introduced in version 11.0.0

Loads json with the decoded protected header of signature index. Signature indexes are zero-based; index 0 is the first signature.

The returned JSON is the header object obtained after base64url decoding the JWS protected-header value. The original encoded representation remains part of the signing input.

Signed header data: The protected header is covered by the signature, but its contents should be treated as untrusted until that signature validates and the application has enforced its algorithm and critical-header policy.

Returns 1 for success, 0 for failure.

top
GetUnprotectedH
GetUnprotectedH(ByVal index As Long, json As ChilkatJsonObject) As Long
Introduced in version 11.0.0

Loads json with the optional unprotected header of signature index. Signature indexes are zero-based; index 0 is the first signature.

Unprotected headers exist only in JWS JSON Serialization. An absent unprotected header and an invalid signature are separate conditions; retrieving this JSON does not perform signature validation.

Not covered by the signature: Never use an unprotected member as trusted algorithm, key-selection, or authorization data unless it is independently authenticated by the surrounding protocol.

Returns 1 for success, 0 for failure.

top
LoadJws
LoadJws(jwsStr As String) As Long
Introduced in version 9.5.0.66

Loads and parses a serialized JWS from jwsStr, making its payload, protected and unprotected headers, and signatures available to the other methods and properties of this object.

Compact Serialization, flattened JWS JSON Serialization, and general JWS JSON Serialization are accepted when structurally valid.

Parsing is not verification: A successful load means only that the JWS was parsed. It does not establish who created it or whether its payload and headers are authentic. Supply the expected verification key and call Validate before trusting any loaded content.

Returns 1 for success, 0 for failure.

top
LoadJwsSb
LoadJwsSb(sbJws As ChilkatStringBuilder) As Long
Introduced in version 9.5.0.66

Loads and parses a serialized JWS from the current contents of sbJws, making its payload, protected and unprotected headers, and signatures available to the other methods and properties of this object.

Compact Serialization, flattened JWS JSON Serialization, and general JWS JSON Serialization are accepted when structurally valid.

Parsing is not verification: A successful load means only that the JWS was parsed. It does not establish who created it or whether its payload and headers are authentic. Supply the expected verification key and call Validate before trusting any loaded content.

Returns 1 for success, 0 for failure.

top
SetMacKey
SetMacKey(ByVal index As Long, key As String, encoding As String) As Long
Introduced in version 9.5.0.66

Sets the symmetric MAC key for creating or validating signature index when its alg value is HS256, HS384, or HS512. Signature indexes are zero-based.

key contains an encoded representation of the key bytes. encoding names that representation, such as base64url, base64, or hex. This argument describes binary-to-text encoding; it is not a character set and the key should not be passed as an ordinary human-readable password unless the protocol explicitly defines how that password is converted to key bytes.

algMinimum recommended key size
HS256256 bits (32 bytes)
HS384384 bits (48 bytes)
HS512512 bits (64 bytes)
Shared-secret trust model: Anyone who can validate an HMAC JWS with this key can also create one. Use a high-entropy secret and do not use an HMAC key where verifiers must be unable to impersonate the signer.

Returns 1 for success, 0 for failure.

top
SetMacKeyBd
SetMacKeyBd(ByVal index As Long, key As ChilkatBinData) As Long
Introduced in version 9.5.0.66

Sets the symmetric MAC key for creating or validating signature index when its alg value is HS256, HS384, or HS512. Signature indexes are zero-based, and key supplies the key as raw bytes.

algMinimum recommended key size
HS256256 bits (32 bytes)
HS384384 bits (48 bytes)
HS512512 bits (64 bytes)
Shared-secret trust model: HMAC verification and signing use the same secret. Every verifier holding the key is also capable of generating valid JWS values.

Returns 1 for success, 0 for failure.

top
SetPayload
SetPayload(payload As String, charset As String, ByVal includeBom As Long) As Long
Introduced in version 9.5.0.66

Sets the JWS payload from payload. charset names the character encoding used to convert the string to payload bytes, such as utf-8, windows-1252, or utf-16.

If includeBom is 1, Chilkat prepends the byte-order mark (BOM), when the selected charset defines one. In most JWS applications includeBom should be 0, because a BOM becomes part of the signed payload and changes the exact byte sequence.

JWS signs bytes, not characters: The charset and BOM choice determine the exact octets covered by the signature. A verifier interpreting the payload as text must use the same character encoding. For JSON payloads, UTF-8 without a BOM is normally the interoperable choice.

Returns 1 for success, 0 for failure.

top
SetPayloadBd
SetPayloadBd(binData As ChilkatBinData) As Long
Introduced in version 9.5.0.66

Sets the JWS payload to the binary bytes currently contained in binData. Use this method when the payload is not text or when the application must preserve an exact byte sequence without character-set conversion.

Arbitrary binary payloads: A JWS payload is an octet sequence and does not need to be JSON or text. In the ordinary JWS serializations, these bytes are base64url encoded before being placed in the serialized JWS and before the signing input is formed.

Returns 1 for success, 0 for failure.

top
SetPayloadSb
SetPayloadSb(sbPayload As ChilkatStringBuilder, charset As String, ByVal includeBom As Long) As Long
Introduced in version 9.5.0.66

Sets the JWS payload from the current contents of sbPayload. charset names the character encoding used to convert the string to payload bytes, such as utf-8, windows-1252, or utf-16.

If includeBom is 1, Chilkat prepends the byte-order mark (BOM), when the selected charset defines one. In most JWS applications includeBom should be 0, because a BOM becomes part of the signed payload and changes the exact byte sequence.

JWS signs bytes, not characters: The charset and BOM choice determine the exact octets covered by the signature. A verifier interpreting the payload as text must use the same character encoding. For JSON payloads, UTF-8 without a BOM is normally the interoperable choice.

Returns 1 for success, 0 for failure.

top
SetPrivateKey
SetPrivateKey(ByVal index As Long, privKey As PrivateKey) As Long
Introduced in version 9.5.0.66

Sets the private key used to create signature index. Signature indexes are zero-based. The key type and parameters must match the alg value in that signature's JOSE header.

AlgorithmsRequired key
RS256, RS384, RS512RSA; RSASSA-PKCS1-v1_5 with the corresponding SHA-2 hash.
PS256, PS384, PS512RSA; RSASSA-PSS with the corresponding SHA-2 hash and MGF1.
ES256EC key on curve P-256.
ES384EC key on curve P-384.
ES512EC key on curve P-521, used with SHA-512.

This method is for RSA and ECDSA signatures. Use SetMacKey or SetMacKeyBd for the HS* algorithms.

ECDSA signature format: JWS represents ECDSA signatures as the fixed-width concatenation of the R and S integers, not as an ASN.1 DER SEQUENCE. Chilkat performs this JOSE-specific formatting automatically.
Algorithm policy: Set the expected algorithm explicitly in the protected header and use a key of the corresponding type. For RSA, modern JOSE deployments should use keys of at least 2048 bits. Do not permit the received alg value alone to determine what algorithms the application is willing to accept.

Returns 1 for success, 0 for failure.

top
SetProtectedHeader
SetProtectedHeader(ByVal index As Long, json As ChilkatJsonObject) As Long
Introduced in version 9.5.0.66

Sets the protected header for the signature at index. Signature indexes are zero-based; index 0 is the first and, for a typical single-signature JWS, the only signature.

The supplied JsonObject contains JOSE header parameters such as alg, kid, typ, cty, or crit. When the JWS is created, this JSON is serialized, UTF-8 encoded, and base64url encoded. The encoded protected header becomes part of the JWS Signing Input and is therefore covered by the signature or MAC.

Protected versus unprotected: Place security-sensitive parameters—especially alg and any parameter used to select a verification key or processing rule—in the protected header. A parameter name must not appear in both the protected and unprotected headers for the same signature.

Returns 1 for success, 0 for failure.

top
SetPublicKey
SetPublicKey(ByVal index As Long, pubKey As PublicKey) As Long
Introduced in version 9.5.0.66

Sets the public key used to validate signature index. Signature indexes are zero-based. The key type and parameters must match the signature's alg value.

AlgorithmsRequired key
RS256, RS384, RS512RSA; RSASSA-PKCS1-v1_5 with the corresponding SHA-2 hash.
PS256, PS384, PS512RSA; RSASSA-PSS with the corresponding SHA-2 hash and MGF1.
ES256EC key on curve P-256.
ES384EC key on curve P-384.
ES512EC key on curve P-521, used with SHA-512.

This method is for RSA and ECDSA verification. Use SetMacKey or SetMacKeyBd for HMAC verification.

Trust the key, not an unverified header: Resolve pubKey from a trusted configuration or a securely validated key-distribution mechanism. Do not blindly trust a jwk, jku, x5c, x5u, or kid value supplied by the same unverified JWS.

Returns 1 for success, 0 for failure.

top
SetSigningCert
SetSigningCert(ByVal index As Long, cert As ChilkatCert) As Long
Introduced in version 11.5.0

Sets the certificate whose associated private key will be used to create signature index. Signature indexes are zero-based. The certificate must have an accessible RSA or EC private key, and that key must match the signature's alg value.

AlgorithmsRequired key
RS256, RS384, RS512RSA; RSASSA-PKCS1-v1_5 with the corresponding SHA-2 hash.
PS256, PS384, PS512RSA; RSASSA-PSS with the corresponding SHA-2 hash and MGF1.
ES256EC key on curve P-256.
ES384EC key on curve P-384.
ES512EC key on curve P-521, used with SHA-512.

This method is convenient when the private key is associated with a certificate in an operating-system store, smart card, hardware token, or other key provider. It selects the private key for signing; applications should separately add any required x5c, x5t, x5t#S256, or related certificate header parameters to the appropriate protected header.

Certificate trust is separate: Creating a signature with a certificate-backed key does not prove that recipients trust the certificate. Verifiers must validate the JWS signature and apply their own certificate-chain, key-usage, revocation, identity, and algorithm policies.

Returns 1 for success, 0 for failure.

top
SetUnprotectedHeader
SetUnprotectedHeader(ByVal index As Long, json As ChilkatJsonObject) As Long
Introduced in version 9.5.0.66

Sets the optional unprotected header for the signature at index. Signature indexes are zero-based; index 0 is the first signature.

An unprotected header is available only in JWS JSON Serialization. Its members are transmitted as ordinary JSON and are not included in the JWS Signing Input. Consequently, setting an unprotected header prevents Compact Serialization from being used, regardless of PreferCompact.

Not integrity protected: An attacker may alter an unprotected header without invalidating the signature. Do not place alg, trusted key-selection data, or other security decisions here unless the surrounding protocol independently protects and validates them. A parameter name must not also appear in the protected header for the same signature.

Returns 1 for success, 0 for failure.

top
Validate
Validate(ByVal index As Long) As Long
Introduced in version 9.5.0.66

Validates signature index using the public key or MAC key configured for that same zero-based signature index.

Return valueMeaning
1The signature or MAC is valid for the loaded payload and protected header using the supplied key.
0Cryptographic validation completed, but the signature or MAC did not match. This commonly indicates the wrong key or modified signed content.
-1Validation could not be performed because of an error, such as a missing key, invalid index, malformed JWS, unsupported algorithm, or incompatible key type. Inspect LastErrorText.

Before calling this method, set the appropriate verification key with SetPublicKey, SetMacKey, or SetMacKeyBd.

Cryptographic validity is only one policy check: Also enforce an application-defined allowlist of acceptable algorithms, obtain the verification key from a trusted source, and validate any protocol-specific payload claims, timestamps, audience, issuer, nonce, or critical header parameters. A valid JWS signature does not by itself make those values acceptable.
More Information and Examples
(AutoIt) JWS Using HMAC SHA-256(Classic ASP) JWS Using HMAC SHA-256(PowerBuilder) JWS Using HMAC SHA-256(SQL Server) JWS Using HMAC SHA-256(VBScript) JWS Using HMAC SHA-256(Visual Basic 6.0) JWS Using HMAC SHA-256(Visual FoxPro) JWS Using HMAC SHA-256(AutoIt) Validate JWS Using RSASSA-PKCS1-v1_5 SHA-256(Classic ASP) Validate JWS Using RSASSA-PKCS1-v1_5 SHA-256(PowerBuilder) Validate JWS Using RSASSA-PKCS1-v1_5 SHA-256(SQL Server) Validate JWS Using RSASSA-PKCS1-v1_5 SHA-256(VBScript) Validate JWS Using RSASSA-PKCS1-v1_5 SHA-256(Visual Basic 6.0) Validate JWS Using RSASSA-PKCS1-v1_5 SHA-256(Visual FoxPro) Validate JWS Using RSASSA-PKCS1-v1_5 SHA-256(AutoIt) Validate a JWS Using ECDSA P-256 SHA-256(Classic ASP) Validate a JWS Using ECDSA P-256 SHA-256(PowerBuilder) Validate a JWS Using ECDSA P-256 SHA-256(SQL Server) Validate a JWS Using ECDSA P-256 SHA-256(VBScript) Validate a JWS Using ECDSA P-256 SHA-256(Visual Basic 6.0) Validate a JWS Using ECDSA P-256 SHA-256(Visual FoxPro) Validate a JWS Using ECDSA P-256 SHA-256(AutoIt) Validate JWS with Multiple Signatures using the General JSON Serialization Format(Classic ASP) Validate JWS with Multiple Signatures using the General JSON Serialization Format(PowerBuilder) Validate JWS with Multiple Signatures using the General JSON Serialization Format(SQL Server) Validate JWS with Multiple Signatures using the General JSON Serialization Format(VBScript) Validate JWS with Multiple Signatures using the General JSON Serialization Format(Visual Basic 6.0) Validate JWS with Multiple Signatures using the General JSON Serialization Format(Visual FoxPro) Validate JWS with Multiple Signatures using the General JSON Serialization Format
top

Deprecated

GetProtectedHeader
GetProtectedHeader(ByVal index As Long) As ChilkatJsonObject
Introduced in version 9.5.0.66
This method is deprecated and replaced by GetProtectedH

Deprecated. Use GetProtectedH instead.

Returns a JsonObject containing the decoded protected header for the signature at index. Signature indexes are zero-based.

Integrity protected: The protected header is part of the JWS Signing Input. Its contents are trustworthy only after the corresponding signature has been successfully validated.

Returns Nothing on failure

top
GetUnprotectedHeader
GetUnprotectedHeader(ByVal index As Long) As ChilkatJsonObject
Introduced in version 9.5.0.66
This method is deprecated and replaced by GetUnprotectedH

Deprecated. Use GetUnprotectedH instead.

Returns a JsonObject containing the optional unprotected header for the signature at index. Signature indexes are zero-based.

Not integrity protected: These header members are not covered by the JWS signature and must not be trusted merely because the signature validates.

Returns Nothing on failure

top