Class Jws
- All Implemented Interfaces:
AutoCloseable
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.
For an extended overview, see Jws Class Overview.
</section>
Instances hold a native Chilkat object: close them with ChilkatObject.close() (try-with-resources) when
done; an unclosed instance is freed when it becomes unreachable.
- See Also:
- Online reference
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates and returns a JWS from the current payload, headers, and signing keys.voidcreateJwsSb(StringBuilder sbJws)Creates a JWS using the same rules asand writes it tocreateJws()sbJws.intReturns the number of signature slots represented by this object.getPayload(String charset)Returns the loaded payload as text after decoding its bytes using charsetcharset.voidgetPayloadBd(BinData binData)Writes the exact loaded JWS payload bytes tobinDatawithout charset conversion.voidgetPayloadSb(String charset, StringBuilder sbPayload)Decodes the loaded payload bytes using charsetcharsetand writes the resulting text tosbPayload.booleanControls whether Chilkat uses JWS Compact Serialization for a single signature.booleanControls which JSON form is used when creating a JWS with exactly one signature andisgetPreferCompact().falsevoidgetProtectedH(int index, JsonObject json)Copies the decoded protected header of signatureindexintojson.Provides a catch-all string for specialized compatibility options.voidgetUnprotectedH(int index, JsonObject json)Copies the optional unprotected header of signatureindexintojson.voidLoads a JWS fromjwsStr.voidloadJwsSb(StringBuilder sbJws)Loads a JWS from the current contents ofsbJws.voidSets the symmetric MAC key for signatureindex.voidsetMacKeyBd(int index, BinData key)Sets the symmetric MAC key for signatureindexfrom a copy of the raw bytes inkey.voidsetPayload(String payload, String charset, boolean includeBom)Replaces the current payload withpayloadconverted to bytes using charsetcharset.voidsetPayloadBd(BinData binData)Replaces the current JWS payload with a copy of all bytes inbinData.voidsetPayloadSb(StringBuilder sbPayload, String charset, boolean includeBom)Replaces the current payload with the text insbPayload, converted to bytes using charsetcharset.voidsetPreferCompact(boolean value)Sets thePreferCompactproperty; seegetPreferCompact().voidsetPreferFlattened(boolean value)Sets thePreferFlattenedproperty; seegetPreferFlattened().voidsetPrivateKey(int index, PrivateKey privKey)Sets a private key for creating signatureindex.voidsetProtectedHeader(int index, JsonObject json)Sets the protected JOSE header for signatureindex.voidsetPublicKey(int index, PublicKey pubKey)Sets the public key used to validate signatureindex.voidsetSigningCert(int index, Cert cert)Sets the certificate whose associated private key will be used to create signatureindex.voidsetUncommonOptions(String value)Sets theUncommonOptionsproperty; seegetUncommonOptions().voidsetUnprotectedHeader(int index, JsonObject json)Sets the optional unprotected JOSE header for signatureindex.intvalidate(int index)Validates exactly one signature, identified by zero-basedindex, using the MAC key or public key configured at that same index.Methods inherited from class com.chilkatsoft.chilkat2.ChilkatObject
close, getDebugLogFilePath, getLastErrorHtml, getLastErrorText, getLastErrorXml, getLastMethodSuccess, getVerboseLogging, getVersion, isClosed, setDebugLogFilePath, setLastMethodSuccess, setVerboseLogging, toString
-
Constructor Details
-
Jws
public Jws()Creates a newJwsobject.
-
-
Method Details
-
getNumSignatures
public int getNumSignatures()Returns the number of signature slots represented by this object.After a successful
LoadJwsorLoadJwsSb, this is the number of signatures in the loaded serialization:1for compact or flattened form, or the number of elements in the general JSONsignaturesarray.During creation, only
SetProtectedHeaderandSetUnprotectedHeaderestablish signature slots. The value is one greater than the highest index having either type of header. Key setters attach key material but do not change this property.Contiguous indexes are required: Indexes are valid from
0through1000. If a header is set at index2, this property becomes3;CreateJwsthen requires configured headers at indexes0,1, and2. A gap causes creation to fail.- Returns:
- the value of the
NumSignaturesproperty (read-only)
-
getPreferCompact
public boolean getPreferCompact()Controls whether Chilkat uses JWS Compact Serialization for a single signature. The default is.trueConfigured state Output
No signature headers Creation fails.
One signature and
PreferCompact =Compact Serialization. A protected header must exist. Any unprotected header is not represented.trueOne signature,
PreferCompact =,falsePreferFlattened =Flattened JWS JSON Serialization.trueOne signature, both preference properties
General JWS JSON Serialization with one element infalsesignatures.More than one signature General JWS JSON Serialization, regardless of the preference properties.
Compact output has the form
protected.payload.signature. It requires a protected header and cannot represent an unprotected header. If both header types are configured and compact output is selected, the unprotected header is omitted from the result.Attached payload only: Chilkat always emits the base64url-encoded payload. The class has no built-in detached-payload mode and does not support RFC 7797
b64=falsepayloads.- Returns:
- the value of the
PreferCompactproperty
-
setPreferCompact
public void setPreferCompact(boolean value)Sets thePreferCompactproperty; seegetPreferCompact().- Parameters:
value- the new value
-
getPreferFlattened
public boolean getPreferFlattened()Controls which JSON form is used when creating a JWS with exactly one signature andisgetPreferCompact(). The default isfalse.trueSetting One-signature JSON output
Flattened JSON, withtrueprotected,header, andsignaturedirectly in the top-level object.General JSON, with one signature object in the top-levelfalsesignaturesarray.When more than one signature is configured, General JSON Serialization is always used and this property is ignored. Signature objects are emitted in ascending index order.
- Returns:
- the value of the
PreferFlattenedproperty
-
setPreferFlattened
public void setPreferFlattened(boolean value)Sets thePreferFlattenedproperty; seegetPreferFlattened().- Parameters:
value- the new value
-
getUncommonOptions
Provides a catch-all string for specialized compatibility options. The default is an empty string.No public JWS options are currently documented: Leave this property empty unless an exact keyword and value are supplied by a Chilkat release note, example, or support response. Undocumented values should not be used as substitutes for JOSE headers or application policy.
- Returns:
- the value of the
UncommonOptionsproperty
-
setUncommonOptions
Sets theUncommonOptionsproperty; seegetUncommonOptions().- Parameters:
value- the new value (notnull)
-
createJws
Creates and returns a JWS from the current payload, headers, and signing keys.Configured state Output
No signature headers Creation fails.
One signature and
PreferCompact =Compact Serialization. A protected header must exist. Any unprotected header is not represented.trueOne signature,
PreferCompact =,falsePreferFlattened =Flattened JWS JSON Serialization.trueOne signature, both preference properties
General JWS JSON Serialization with one element infalsesignatures.More than one signature General JWS JSON Serialization, regardless of the preference properties.
Signature slots must form a contiguous range from
0through. Each slot must have at least one header, angetNumSignatures()- 1algvalue, and compatible signing material. Chilkat looks foralgin the protected header first and then the unprotected header; matching is case-insensitive after trimming.The payload is always attached and base64url encoded. If no payload setter was called, Chilkat signs a valid zero-length payload. Detached payloads and RFC 7797 unencoded payloads are not supported.
Calling after
LoadJws: The loaded payload and headers are reused, but the existing serialized signatures are discarded and recomputed using the currently configured keys. Key material survives loads. For unrelated operations, a freshJwsobject avoids carrying keys forward.Signing algorithms:CreateJwsandCreateJwsSbsupportHS256,HS384,HS512;RS256,RS384,RS512;PS256,PS384,PS512;ES256,ES384,ES512; andnone. Thenonealgorithm produces an empty signature. Other identifiers, includingEdDSA,Ed25519,Ed448,ES256K, Brainpoolbp*identifiers, legacy SHA-1 algorithms, and private-use names, are not supported for signing.- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
createJwsSb
Creates a JWS using the same rules asand writes it tocreateJws()sbJws.The destination
StringBuilderis cleared at the start. On success it contains the complete serialized JWS; on failure it remains empty and no partial JWS is returned.Creation requirements: Signature indexes must be contiguous, each slot must have a header and
alg, and the required MAC key, private key, or signing certificate must be configured at that same index.- Parameters:
sbJws- thesbJwsargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getPayload
Returns the loaded payload as text after decoding its bytes using charsetcharset.If the charset is unsupported or the payload bytes are invalid for that charset, the method fails and returns no decoded text. Use
to retrieve exact bytes.getPayloadBd(BinData)Extraction is not validation: This method does not verify a signature. Treat the returned value as untrusted until the signatures required by the application have returned
1from.validate(int)- Parameters:
charset- thecharsetargument (notnull)- Returns:
- the result (never
null) - Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getPayloadBd
Writes the exact loaded JWS payload bytes tobinDatawithout charset conversion.The destination
BinDatais cleared first. On success it contains only the payload bytes; on failure it remains empty.Validate before use: Loading and extracting a payload does not establish integrity or signer identity. Validate the required signature indexes before trusting these bytes.
- Parameters:
binData- thebinDataargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getPayloadSb
Decodes the loaded payload bytes using charsetcharsetand writes the resulting text tosbPayload.The destination
StringBuilderis cleared first. On success it contains the decoded payload; on failure, including a charset conversion error, it remains empty. Usewhen the payload is binary or its encoding is unknown.getPayloadBd(BinData)Extraction is not validation: This method does not verify a signature. Treat the payload as untrusted until
returnsvalidate(int)1for every signer required by the application.- Parameters:
charset- thecharsetargument (notnull)sbPayload- thesbPayloadargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getProtectedH
Copies the decoded protected header of signatureindexintojson. The valid zero-based index range is0through1000.On success, the destination
JsonObjectis replaced with a clone of the header. On failure—an invalid index or no protected header—the destination is left unchanged. The method does not merge members.Exact signed representation: The returned JSON is decoded content, not the original base64url text. During creation, Chilkat preserves JSON member insertion order and emits compact JSON; byte-for-byte test vectors require the same member order and formatting.Critical parameters: Chilkat preserves but does not process
crit. Inspect and enforce critical-extension and expected-algorithm policy before trusting a valid signature.- Parameters:
index- theindexargumentjson- thejsonargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
getUnprotectedH
Copies the optional unprotected header of signatureindexintojson. The valid zero-based index range is0through1000.On success, the destination
JsonObjectis replaced with a clone of the header. If no unprotected header exists, this method returnsas a normal absence result and leaves the destination unchanged. An invalid index also returnsfalseand records an error.falseNot signed: These members are not part of the JWS Signing Input. Chilkat does not reject a member name that also appears in the protected header; protected values take precedence when Chilkat looks up parameters such as
alg.- Parameters:
index- theindexargumentjson- thejsonargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
loadJws
Loads a JWS fromjwsStr.Loads and parses a compact, flattened JSON, or general JSON JWS. Leading and trailing whitespace around the complete input is accepted. Input whose first non-whitespace character is
{is parsed as JSON; all other input is treated as compact serialization.Form Load requirements
Compact Exactly three dot-separated parts. The protected header must base64url-decode to a JSON object. An empty payload segment is allowed.
Flattened JSON A top-level
payloadandsignatureare required.General JSON A top-level
payloadandsignaturesarray are required. Each array element must containsignature. An empty array is accepted and producesNumSignatures = 0.If a
signaturesarray is present, general form takes precedence and top-level flattened signature fields are ignored. Unknown top-level JSON members are ignored. Structural and payload/protected-header decoding errors are detected while loading; algorithm, key compatibility, and cryptographic signature checks are deferred until.validate(int)State replacement: Loading clears the previous payload and all protected and unprotected headers before parsing, but retains MAC keys, public keys, private keys, and signing certificates. A failed load does not restore the prior JWS; the object is left cleared or partially populated while key material remains.No detached input: The payload must be present. JSON without a
payloadmember fails, and there is no method to supply external detached content for validation.- Parameters:
jwsStr- thejwsStrargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
loadJwsSb
Loads a JWS from the current contents ofsbJws.Loads and parses a compact, flattened JSON, or general JSON JWS. Leading and trailing whitespace around the complete input is accepted. Input whose first non-whitespace character is
{is parsed as JSON; all other input is treated as compact serialization.Form Load requirements
Compact Exactly three dot-separated parts. The protected header must base64url-decode to a JSON object. An empty payload segment is allowed.
Flattened JSON A top-level
payloadandsignatureare required.General JSON A top-level
payloadandsignaturesarray are required. Each array element must containsignature. An empty array is accepted and producesNumSignatures = 0.If a
signaturesarray is present, general form takes precedence and top-level flattened signature fields are ignored. Unknown top-level JSON members are ignored. Structural and payload/protected-header decoding errors are detected while loading; algorithm, key compatibility, and cryptographic signature checks are deferred until.validate(int)State replacement: Loading clears the previous payload and all protected and unprotected headers before parsing, but retains MAC keys, public keys, private keys, and signing certificates. A failed load does not restore the prior JWS; the object is left cleared or partially populated while key material remains.No detached input: The payload must be present. JSON without a
payloadmember fails, and there is no method to supply external detached content for validation.- Parameters:
sbJws- thesbJwsargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setMacKey
Sets the symmetric MAC key for signatureindex. The valid zero-based index range is0through1000.keyis decoded using binary encodingencoding, and the resulting bytes are copied.This setter attaches key material but does not establish a signature slot or change
. Calling it again at the same index replaces the previous MAC key. A successful return means the key text decoded and was stored; algorithm and key-length compatibility are checked when creating or validating.getNumSignatures()algApplication-recommended minimum key lengthHS25632 bytesHS38448 bytesHS51264 bytesKey length is not enforced: Chilkat accepts shorter HMAC keys silently for both creation and validation. The application is responsible for meeting its security policy and the JOSE recommendation that the key be at least as long as the hash output.
- Parameters:
index- theindexargumentkey- thekeyargument (notnull)encoding- theencodingargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setMacKeyBd
Sets the symmetric MAC key for signatureindexfrom a copy of the raw bytes inkey. The valid zero-based index range is0through1000.This setter does not create a signature slot. Calling it again replaces only the MAC key at this index. Key length is not checked until use—and Chilkat does not enforce the recommended minimum even during creation or validation.
algApplication-recommended minimum key lengthHS25632 bytesHS38448 bytesHS51264 bytesKey selection: The MAC key is used only when
algisHS256,HS384, orHS512. Other key objects configured at the same index are ignored for an HMAC algorithm.- Parameters:
index- theindexargumentkey- thekeyargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setPayload
Replaces the current payload withpayloadconverted to bytes using charsetcharset.If
includeBomis, a byte-order mark is included when the charset defines one. Unsupported charsets or unrepresentable text cause this method to returntrue. The payload bytes are copied.falseAn empty string establishes a valid zero-length payload, which is equivalent to having never set a payload. Chilkat always includes the base64url-encoded payload in generated output.
JWS signs bytes: Charset and BOM choices change the exact signing input. UTF-8 without a BOM is normally preferred. Built-in detached payloads and RFC 7797
b64=falseare not supported.- Parameters:
payload- thepayloadargument (notnull)charset- thecharsetargument (notnull)includeBom- theincludeBomargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setPayloadBd
Replaces the current JWS payload with a copy of all bytes inbinData. Use this method for binary data or whenever the exact byte sequence must be preserved without charset conversion.An empty
BinDataestablishes a valid zero-length payload. The class does not distinguish this from never having called a payload setter.Attached, encoded payload: Chilkat always base64url encodes these bytes and includes the resulting payload segment or JSON member. Built-in detached payloads and
b64=falseunencoded payloads are not supported.- Parameters:
binData- thebinDataargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setPayloadSb
Replaces the current payload with the text insbPayload, converted to bytes using charsetcharset. The bytes are copied; the sourceStringBuilderdoes not need to remain alive.If
includeBomis, a byte-order mark is included when the chosen charset defines one. Charset conversion failure, including unsupported charset or unrepresentable text, causes this method to returntrue.falseAn empty input establishes a valid zero-length payload. Chilkat always base64url encodes and includes the payload in the generated JWS.
Exact bytes are signed: The charset and BOM determine the octets covered by the signature. UTF-8 without a BOM is the usual interoperable choice for textual or JSON payloads. Use
SetPayloadBdfor exact binary bytes.- Parameters:
sbPayload- thesbPayloadargument (notnull)charset- thecharsetargument (notnull)includeBom- theincludeBomargument- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setPrivateKey
Sets a private key for creating signatureindex. The valid zero-based index range is0through1000. The key is cloned, so the source object does not need to remain alive.This setter does not establish a signature slot. A successful return means the key was accepted and copied; key type, RSA size, EC curve, and compatibility with the header's
algare validated duringCreateJws.algfamily Key usedRS256,RS384,RS512RSA key; RSASSA-PKCS1-v1_5 with the corresponding SHA-2 hash.PS256,PS384,PS512RSA key; RSASSA-PSS using the same hash for MGF1 and a salt whose length equals the hash output length.ES256EC key on P-256; JWS signature is the 64-byte fixed-widthR || Svalue.ES384EC key on P-384; JWS signature is the 96-byte fixed-widthR || Svalue.ES512EC key on P-521; JWS signature is the 132-byte fixed-widthR || Svalue.Precedence: For RSA or ECDSA signing, an explicitly set private key takes precedence over a signing certificate at the same index. A public key may coexist and is used only by
Validate. Setting one key kind does not clear the others.ECDSA details: Chilkat produces JOSE fixed-widthR || Ssignatures. It does not force low-S normalization. The curve must exactly match ES256/P-256, ES384/P-384, or ES512/P-521.- Parameters:
index- theindexargumentprivKey- theprivKeyargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setProtectedHeader
Sets the protected JOSE header for signatureindex. The valid zero-based index range is0through1000. Setting either a protected or unprotected header establishes the signature slot and can increase.getNumSignatures()jsonis cloned; later modification or disposal of the sourceJsonObjectdoes not change the stored header. Calling this method again at the same index replaces only that protected header. An empty object is stored as{}and still counts as a configured slot.During signing, Chilkat serializes the object compactly, preserving member insertion order, UTF-8 encodes it, and base64url encodes the result. These exact encoded bytes are included in the JWS Signing Input.
Where
algis found: Chilkat checks the protected header first and then the unprotected header. Putalgin the protected header so the algorithm choice is integrity protected. If the same name appears in both headers, Chilkat does not reject the overlap; the protected value takes precedence.Unsupported extensions: Thecritparameter is preserved but not processed, and RFC 7797b64=falseis not supported. Applications that use critical extensions must inspect and enforce them independently.- Parameters:
index- theindexargumentjson- thejsonargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setPublicKey
Sets the public key used to validate signatureindex. The valid zero-based index range is0through1000. The key is cloned, so the source object does not need to remain alive.This setter does not create a signature slot. Key type, RSA size, applicable EC-curve requirements, and compatibility with
algare checked duringValidate, not by this method.algfamily Key usedRS256,RS384,RS512RSA key; RSASSA-PKCS1-v1_5 with the corresponding SHA-2 hash.PS256,PS384,PS512RSA key; RSASSA-PSS using the same hash for MGF1 and a salt whose length equals the hash output length.ES256EC key on P-256; JWS signature is the 64-byte fixed-widthR || Svalue.ES384EC key on P-384; JWS signature is the 96-byte fixed-widthR || Svalue.ES512EC key on P-521; JWS signature is the 132-byte fixed-widthR || Svalue.Other
es*identifiers, such asES256KVerification only. Chilkat performs generic ECDSA verification using SHA-256 without enforcing a particular EC curve.Brainpool
bp*identifiers Verification only. These are non-standard JOSE identifiers; Chilkat uses an EC key and SHA-256 without enforcing a particular curve.No automatic key resolution: Chilkat never resolves
jkuorx5u, imports an embeddedjwk, extracts a key fromx5c, or searches a certificate store bykid. The application must resolve and set the verification key at the same signature index.ECDSA verification: For the standard identifiers, Chilkat accepts the JOSE raw fixed-width format: 64 bytes forES256, 96 bytes forES384, and 132 bytes forES512, with the corresponding P-256, P-384, and P-521 curve requirements. High-S signatures are accepted. Otheres*identifiers and Brainpoolbp*identifiers are handled as verification-only generic ECDSA with SHA-256 and no curve check.- Parameters:
index- theindexargumentpubKey- thepubKeyargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setSigningCert
Sets the certificate whose associated private key will be used to create signatureindex. The valid zero-based index range is0through1000. This setter attaches key material but does not establish a signature slot.algfamily Key usedRS256,RS384,RS512RSA key; RSASSA-PKCS1-v1_5 with the corresponding SHA-2 hash.PS256,PS384,PS512RSA key; RSASSA-PSS using the same hash for MGF1 and a salt whose length equals the hash output length.ES256EC key on P-256; JWS signature is the 64-byte fixed-widthR || Svalue.ES384EC key on P-384; JWS signature is the 96-byte fixed-widthR || Svalue.ES512EC key on P-521; JWS signature is the 132-byte fixed-widthR || Svalue.If the certificate has an exportable private key, Chilkat copies the key and the source certificate need not remain alive. For a non-exportable smart-card or HSM-backed key, Chilkat retains the certificate and uses the platform key provider during
CreateJws; keep the certificate and provider available until signing completes.Validation is deferred: This method can return
even when no usable private key is currently accessible; it logs a warning and the definitive failure occurs duringtrueCreateJws. PIN prompts and provider errors also occur while signing.Certificate status is not checked: Chilkat does not require the certificate to be trusted, unexpired, or authorized for digital signatures, and it does not choosealgautomatically. The application must set a compatible algorithm and apply any certificate policy it requires. An explicitly configured private key takes precedence over the certificate at the same index.- Parameters:
index- theindexargumentcert- thecertargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
setUnprotectedHeader
Sets the optional unprotected JOSE header for signatureindex. The valid zero-based index range is0through1000. Setting either header type establishes the signature slot.jsonis cloned. Calling this method again at the same index replaces only the unprotected header; it does not change the protected header or any key material. An empty object is stored and is emitted as"header":{}in JSON serialization.An unprotected header is emitted only in flattened or general JWS JSON Serialization. It is not included in the JWS Signing Input. If compact output is selected for one signature, the unprotected header is omitted; if no protected header exists, compact creation fails.
Not integrity protected: Do not place trusted algorithm selection, authorization decisions, or key-selection data solely in this header. Chilkat does not reject names duplicated in the protected header; protected-header values take precedence.
- Parameters:
index- theindexargumentjson- thejsonargument (notnull)- Throws:
ChilkatException- if the operation fails;ChilkatException.getLastErrorText()says why
-
validate
public int validate(int index)Validates exactly one signature, identified by zero-basedindex, using the MAC key or public key configured at that same index.Return value Meaning
1The signature or MAC is cryptographically valid for this signature index.0A well-formed signature was checked but did not match. For HMAC, a wrong key or wrong-length signature normally produces this result.-1Validation could not be performed because of an error such as an invalid index, missing or unsupportedalg, missing key, incompatible key type, a required curve mismatch for the standardES256/ES384/ES512algorithms, a malformed signature, or an RSA/ECDSA verification error.Chilkat obtains
algfrom the protected header first and then the unprotected header. Matching is case-insensitive after trimming. If the same name is present in both headers, the protected value wins; the duplicate is not rejected.Verification algorithms:
ValidatesupportsHS256,HS384,HS512;RS256,RS384,RS512;PS256,PS384,PS512; andES256,ES384,ES512. Algorithm-family matching is prefix-based after trimming and case normalization. Otheres*identifiers, such asES256K, are treated as generic ECDSA using SHA-256 with no curve restriction. Brainpoolbp*identifiers are also accepted for verification using an EC key and SHA-256 with no curve check; these are non-standard JOSE identifiers and are not supported for signing.noneis rejected.EdDSA,Ed25519,Ed448, legacy SHA-1 algorithms, and names that do not begin with a recognizedhs,rs,ps,es, orbpprefix are rejected with-1.Multiple signatures: This method does not validate all signatures automatically. Loop from0throughNumSignatures - 1, set the appropriate key at each index, and apply the application's required all/any/threshold signer policy.Header policy remains application-controlled: The class does not processcritor enforce an expected-algorithm allowlist. A valid cryptographic result can still use an algorithm or header policy unacceptable to the application. Chilkat also never treats an RSA public key as an HMAC secret; HS algorithms require a separately configured MAC key.- Parameters:
index- theindexargument- Returns:
- the result (see
ChilkatObject.getLastMethodSuccess()where the description mentions failure)
-