---
product: Chilkat
product_version: 11.7.0
language: sqlserver
language_label: SQL Server
class: Jwt
license: bundle
deprecated: false
reference_html: https://www.chilkatsoft.com/refdoc/sqlserver_JwtRef.html
---
# Chilkat Jwt — SQL Server — v11.7.0

> Chilkat 11.7.0 · language=sqlserver · class=Jwt
> Other versions: replace `11.7.0` in this URL. Other languages: `https://www.chilkatsoft.com/ai-docs/v/11.7.0/<lang>/classes/Jwt.md`.
> Language-wide rules (install, unlock, error model, strings/bytes): `https://www.chilkatsoft.com/ai-docs/v/11.7.0/sqlserver/guide.md`.

## Purpose

**Create, decode, verify, and time-validate compact JSON Web Tokens.**

`Chilkat.Jwt` is the Chilkat class for working with compact JSON Web Tokens. It can create signed JWTs, decode JWT headers and payloads, verify signatures, validate time-based claims, generate NumericDate values, and work with HMAC shared-secret tokens, RSA public/private-key tokens, ECC public/private-key tokens, and certificate-backed signing workflows.

**Create compact JWTs**

Build JWTs from JSON header and payload data, then sign them using the algorithm and key material required by the application or API.

**Decode headers and claims**

Decode the JWT header and payload without verification when an application needs to inspect claims, algorithms, key IDs, or token metadata.

**Verify signatures**

Verify JWT signatures using HMAC shared secrets, RSA public keys, ECC public keys, or certificates.

**Sign with keys or certs**

Create tokens using shared secrets, private keys, or certificates that have access to the associated private key.

**Time validation**

Validate `exp` and `nbf` claims and generate NumericDate values for token expiration, not-before, and issued-at timestamps.

**API authentication workflows**

Use JWTs for bearer-token style authentication, service-account flows, assertion-based OAuth flows, and other compact token formats.

**Common pattern:** To create a JWT, prepare the JSON header and payload, set claims such as `iss`, `sub`, `aud`, `iat`, `nbf`, or `exp`, then sign with the required shared secret, private key, or certificate. To consume a JWT, decode it as needed, verify the signature with the matching key, and separately validate the time-based claims required by the application.

For an extended overview, see [Jwt Class Overview](https://www.chilkatsoft.com/jwt_class_overview.asp).

## Object creation, unlocking and error handling

**Object Creation**

```sql
DECLARE @hr int
DECLARE @jwt int
EXEC @hr = sp_OACreate 'Chilkat.Jwt', @jwt OUT
IF @hr <> 0
BEGIN
    PRINT 'Failed to create ActiveX component'
    RETURN
END

-- ... use @jwt ...

EXEC @hr = sp_OADestroy @jwt
```

T-SQL uses the Chilkat ActiveX through the OLE Automation stored procedures. They must be enabled once on the server (`EXEC sp_configure 'Ole Automation Procedures', 1; RECONFIGURE;`), and the Chilkat ActiveX registered must match the bitness of the SQL Server instance (64-bit for a 64-bit SQL Server). To bind to a specific major version of Chilkat, append the major version number to the ProgID, such as `sp_OACreate 'Chilkat.Jwt.11'` for Chilkat v11.\*.\*.

`sp_OACreate` returns an object token (an `int`) that is passed as the first argument of every `sp_OAMethod`, `sp_OAGetProperty` and `sp_OASetProperty` call, and released with `sp_OADestroy`. Objects returned by methods (such as an `HttpResponse` or `JsonObject`) are also tokens received through an `int` OUT parameter; they must likewise be destroyed, and the OUT parameter is `NULL` when the method fails to return an object. Objects passed as arguments are passed by their token. When an OLE Automation procedure itself fails (non-zero `@hr`), `sp_OAGetErrorInfo` describes the error.

Data types: strings are `nvarchar(4000)`; integers, booleans (1 or 0) and object tokens are `int`; dates are `datetime`. In the signatures on this page, `@success`, `@iResult`, `@sResult` and the like are the OUT variables receiving a method's return value, `@iValue` / `@sValue` receive or supply a property value, and the remaining `@` variables are the method's arguments in order.

A string returned through an OUT parameter is limited to 4000 characters. For longer values, retrieve the result as a result set into a table variable instead of an OUT parameter, for example `DECLARE @tmp TABLE (outputLine ntext)` followed by `INSERT INTO @tmp EXEC sp_OAGetProperty @jwt, 'LastErrorText'`. See [string length limitations for strings returned by sp_OAMethod calls](https://www.chilkatsoft.com/sql_server_nvarchar_max_limitation.asp).

Methods that pass or return raw byte arrays are not shown on this page, because `varbinary(max)` values cannot be exchanged through `sp_OAMethod` (see [varbinary(max) limitation](https://www.chilkatsoft.com/sql_server_varbinary_max_limitation.asp)). Use the `BinData`-based alternatives (methods ending in *Bd*) or the base64 / hex string-encoded variants instead. Binary *properties* (such as `LastBinaryResult`) can be retrieved as a result set into a table variable, as shown in their signatures. Asynchronous (*\*Async*) methods and event callbacks are not available from SQL Server.

Call `Global.UnlockBundle` once at the start of the program, before using this or any other Chilkat class. Any string unlocks a fully functional 30-day trial; a purchased unlock code is used in production. See `guide.md` for the exact code in SQL Server.

How failure is reported depends on the method's return type and is stated in the note under each method below. In every case the diagnostic text is in the `LastErrorText` property of the object whose method was called.

## Members common to every Chilkat class

Documented once per language in `common-members.md`; listed here so this page is self-contained.

| Property | Signature | Access | Meaning |
|---|---|---|---|
| `DebugLogFilePath` | `EXEC sp_OAGetProperty @jwt, 'DebugLogFilePath', @sValue OUT EXEC sp_OASetProperty @jwt, 'DebugLogFilePath', @sValue` | read/write | If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. |
| `LastBinaryResult` | `INSERT INTO @tmp EXEC sp_OAGetProperty @jwt, 'LastBinaryResult'` | 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. |
| `LastErrorHtml` | `EXEC sp_OAGetProperty @jwt, 'LastErrorHtml', @sValue OUT` | read-only | Provides HTML-formatted information about the last called method or property. |
| `LastErrorText` | `EXEC sp_OAGetProperty @jwt, 'LastErrorText', @sValue OUT` | read-only | Provides plain text information about the last called method or property. |
| `LastErrorXml` | `EXEC sp_OAGetProperty @jwt, 'LastErrorXml', @sValue OUT` | read-only | Provides XML-formatted information about the last called method or property. |
| `LastMethodSuccess` | `EXEC sp_OAGetProperty @jwt, 'LastMethodSuccess', @iValue OUT EXEC sp_OASetProperty @jwt, 'LastMethodSuccess', @iValue` | read/write | Indicates the success or failure of the most recent method call: `1` means success, `0` means failure. |
| `LastStringResult` | `EXEC sp_OAGetProperty @jwt, 'LastStringResult', @sValue OUT` | read-only | In SQL Server stored procedures, this property holds the string return value of the most recent method call that returns a string. |
| `LastStringResultLen` | `EXEC sp_OAGetProperty @jwt, 'LastStringResultLen', @iValue OUT` | read-only | The length, in characters, of the string contained in the LastStringResult property. |
| `VerboseLogging` | `EXEC sp_OAGetProperty @jwt, 'VerboseLogging', @iValue OUT EXEC sp_OASetProperty @jwt, 'VerboseLogging', @iValue` | read/write | If set to `1`, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. |
| `Version` | `EXEC sp_OAGetProperty @jwt, 'Version', @sValue OUT` | read-only | Version of the component/library, such as "10.1.0" |

## Member index

| Member | Kind | Signature |
|---|---|---|
| `AutoCompact` | property, read/write | `EXEC sp_OAGetProperty @jwt, 'AutoCompact', @iValue OUT EXEC sp_OASetProperty @jwt, 'AutoCompact', @iValue` |
| `UncommonOptions` | property, read/write | `EXEC sp_OAGetProperty @jwt, 'UncommonOptions', @sValue OUT EXEC sp_OASetProperty @jwt, 'UncommonOptions', @sValue` |
| `CreateJwt` | method | `EXEC sp_OAMethod @jwt, 'CreateJwt', @sResult OUT, @header, @payload, @password` |
| `CreateJwtCert` | method | `EXEC sp_OAMethod @jwt, 'CreateJwtCert', @sResult OUT, @header, @payload, @cert` |
| `CreateJwtPk` | method | `EXEC sp_OAMethod @jwt, 'CreateJwtPk', @sResult OUT, @header, @payload, @key` |
| `GenNumericDate` | method | `EXEC sp_OAMethod @jwt, 'GenNumericDate', @iResult OUT, @numSecOffset` |
| `GetHeader` | method | `EXEC sp_OAMethod @jwt, 'GetHeader', @sResult OUT, @token` |
| `GetPayload` | method | `EXEC sp_OAMethod @jwt, 'GetPayload', @sResult OUT, @token` |
| `IsTimeValid` | method | `EXEC sp_OAMethod @jwt, 'IsTimeValid', @success OUT, @jwt, @leeway` |
| `VerifyJwt` | method | `EXEC sp_OAMethod @jwt, 'VerifyJwt', @success OUT, @token, @password` |
| `VerifyJwtPk` | method | `EXEC sp_OAMethod @jwt, 'VerifyJwtPk', @success OUT, @token, @key` |

## Properties

### Jwt.AutoCompact

`Chilkat 11.7.0 · sqlserver · Jwt · AutoCompact · property · read/write · since 9.5.0.58`

```sql
EXEC sp_OAGetProperty @jwt, 'AutoCompact', @iValue OUT
EXEC sp_OASetProperty @jwt, 'AutoCompact', @iValue
```

Controls whether Chilkat removes insignificant JSON whitespace from the `header` and `payload` passed to `CreateJwt` and `CreateJwtPk` before Base64URL encoding and signing. The default is `1`.

Compaction reduces token size without changing the JSON data model. Because the exact header and payload bytes are part of the signing input, changing this property changes the encoded token and its signature even when the JSON values are equivalent.

**Whitespace inside JSON strings is preserved:** Compaction removes formatting whitespace between JSON tokens; it does not remove spaces that are part of a quoted string value.

### Jwt.UncommonOptions

`Chilkat 11.7.0 · sqlserver · Jwt · UncommonOptions · property · read/write · since 10.1.0`

```sql
EXEC sp_OAGetProperty @jwt, 'UncommonOptions', @sValue OUT
EXEC sp_OASetProperty @jwt, 'UncommonOptions', @sValue
```

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

**Leave empty unless instructed:** Set this property only when a Chilkat example, release note, or support response documents a specific option needed for an unusual interoperability case.

## Methods

### Jwt.CreateJwt

`Chilkat 11.7.0 · sqlserver · Jwt · CreateJwt · method · since 9.5.0.58`

```sql
EXEC sp_OAMethod @jwt, 'CreateJwt', @sResult OUT, @header, @payload, @password
```

Creates a signed JWT using an HMAC shared secret. `header` may be a complete JOSE header JSON object or the shorthand `HS256`, `HS384`, or `HS512`. A shorthand value produces a standard header containing the corresponding `alg` value.

`payload` is the JSON claims set. Chilkat signs the JSON supplied by the application; it does not automatically add claims such as `iss`, `sub`, `aud`, `iat`, `nbf`, or `exp`. `password` is the shared secret used by both the signer and verifier.

| Algorithm | Operation |
| :--- | :--- |
| `HS256` | HMAC with SHA-256. |
| `HS384` | HMAC with SHA-384. |
| `HS512` | HMAC with SHA-512. |

On success, the result is a compact JWS in the form `base64url(header).base64url(payload).base64url(signature)`. The Base64URL segments do not use padding.

**Signed, not encrypted:** Anyone who receives the token can decode its header and payload. The HMAC protects integrity and authenticity only; do not place confidential information in the claims unless the token is protected separately.

**Shared-secret guidance:** Use a high-entropy secret appropriate for the selected HMAC algorithm. A human password is usually weaker than a randomly generated key. Use `CreateJwtPk` when the trust model requires an asymmetric private key.

Returns `NULL` on failure

### Jwt.CreateJwtCert

`Chilkat 11.7.0 · sqlserver · Jwt · CreateJwtCert · method · since 9.5.0.99`

```sql
EXEC sp_OAMethod @jwt, 'CreateJwtCert', @sResult OUT, @header, @payload, @cert
```

Creates a signed JWT using the private key associated with `cert`. The certificate must provide access to an RSA or EC private key compatible with the `alg` value in `header`.

`header` may be a complete JOSE header JSON object or the shorthand `RS256`, `RS384`, `RS512`, `PS256`, `PS384`, `PS512`, `ES256`, `ES384`, or `ES512`. `payload` is the JSON claims set. PS256/384/512 support was added in Chilkat v10.0.0.

On success, the result is a compact JWS in the form `base64url(header).base64url(payload).base64url(signature)`.

**Private-key access is required:** A certificate containing only the public key cannot create a signature. Signing can also fail when the private key exists but is not accessible, is nonfunctional, requires unavailable user interaction, or is incompatible with the selected algorithm.

**Certificate trust is a verifier decision:** Creating a JWT with a certificate-backed key does not by itself establish that recipients should trust that certificate. The verifier must obtain the correct public key or certificate through a trusted mechanism and apply any required certificate validation policy.

Returns `NULL` on failure

### Jwt.CreateJwtPk

`Chilkat 11.7.0 · sqlserver · Jwt · CreateJwtPk · method · since 9.5.0.58`

```sql
EXEC sp_OAMethod @jwt, 'CreateJwtPk', @sResult OUT, @header, @payload, @key
```

Creates a signed JWT using an asymmetric private key. `header` may be a complete JOSE header JSON object or one of the documented shorthand algorithm names. `payload` is the JSON claims set, and `key` must be a private key compatible with the selected `alg`.

| JOSE algorithm | Required key and signature scheme |
| :--- | :--- |
| `RS256`, `RS384`, `RS512` | RSA private key; RSASSA-PKCS1-v1_5 with the corresponding SHA-2 digest. |
| `PS256`, `PS384`, `PS512` | RSA private key; RSASSA-PSS with the corresponding SHA-2 digest and MGF1. |
| `ES256`, `ES384`, `ES512` | EC private key compatible with the requested ECDSA algorithm. |
| `EdDSA` | Ed25519 private key. Use a full JOSE header containing `"alg":"EdDSA"`. |

The shorthand forms documented for this method are `RS256`, `RS384`, `RS512`, `PS256`, `PS384`, `PS512`, `ES256`, `ES384`, and `ES512`. PS256/384/512 support was added in Chilkat v10.0.0; Ed25519 signing with `EdDSA` requires Chilkat v9.5.0.95 or later.

On success, the result is a compact JWS in the form `base64url(header).base64url(payload).base64url(signature)`.

**Key compatibility:** The private-key type must agree with `alg`. Do not select an algorithm solely from untrusted input. Choose the algorithm as part of the application protocol and use a key intended for that algorithm.

**Claims remain application-defined:** This method creates the cryptographic signature. The application is responsible for constructing and later validating issuer, audience, subject, lifetime, nonce, and other required claims.

Returns `NULL` on failure

### Jwt.GenNumericDate

`Chilkat 11.7.0 · sqlserver · Jwt · GenNumericDate · method · since 9.5.0.58`

```sql
EXEC sp_OAMethod @jwt, 'GenNumericDate', @iResult OUT, @numSecOffset
```

Returns a JWT *NumericDate* equal to the current system time plus `numSecOffset`. The result is the number of whole seconds elapsed since `1970-01-01T00:00:00Z`, ignoring leap seconds.

A positive offset produces a future time and a negative offset produces a past time. Typical uses include generating values for `iat`, `nbf`, and `exp` claims. The method returns the numeric value only; it does not insert the value into a JSON payload.

**System-clock dependency:** The result is based on the computer's current clock. Token lifetimes and validation can be incorrect when the system clock is inaccurate.

### Jwt.GetHeader

`Chilkat 11.7.0 · sqlserver · Jwt · GetHeader · method · since 9.5.0.58`

```sql
EXEC sp_OAMethod @jwt, 'GetHeader', @sResult OUT, @token
```

Decodes and returns the JOSE header JSON from the first segment of the compact JWT. For a token in the form `header.payload.signature`, this method Base64URL-decodes the `header` segment and interprets it as JSON text.

**No verification is performed:** Decoding a header does not prove that the token is authentic. Until `VerifyJwt` or `VerifyJwtPk` succeeds, treat every header value—including `alg`, `kid`, `jku`, and `x5u`—as attacker-controlled input.

The method fails if the token does not contain a decodable compact-JWT header.

Returns `NULL` on failure

### Jwt.GetPayload

`Chilkat 11.7.0 · sqlserver · Jwt · GetPayload · method · since 9.5.0.58`

```sql
EXEC sp_OAMethod @jwt, 'GetPayload', @sResult OUT, @token
```

Decodes and returns the claims-set JSON from the second segment of the compact JWT. For a token in the form `header.payload.signature`, this method Base64URL-decodes the `payload` segment and returns the resulting JSON text.

**Decoding is not validation:** This method does not verify the signature, token lifetime, issuer, audience, nonce, or any other claim. Use the appropriate signature-verification method first, then apply the claim checks required by the application.

The method fails if the token does not contain a decodable compact-JWT payload.

Returns `NULL` on failure

### Jwt.IsTimeValid

`Chilkat 11.7.0 · sqlserver · Jwt · IsTimeValid · method · since 9.5.0.58`

```sql
EXEC sp_OAMethod @jwt, 'IsTimeValid', @success OUT, @jwt, @leeway
```

Checks the JWT `exp` (expiration time) and `nbf` (not before) claims against the current system time. It returns `1` when every present time constraint permits the token to be used, and `0` when the token is expired, is not yet valid, or its relevant time data cannot be processed.

| Claim | Validity rule |
| :--- | :--- |
| `exp` | The token is not accepted on or after the expiration time. |
| `nbf` | The token is not accepted before the not-before time. |

`leeway` is a number of seconds allowed for clock skew. Keep it small; a few minutes is typical. The method checks whichever of `exp` and `nbf` are present and does not require either claim to exist.

**Time checking is separate from signature verification:** `IsTimeValid` does not verify the JWT signature and does not validate `iss`, `aud`, `sub`, `iat`, `jti`, nonce values, or application-specific claims. A normal validation workflow verifies the signature, checks time constraints, and then validates all required claims.

### Jwt.VerifyJwt

`Chilkat 11.7.0 · sqlserver · Jwt · VerifyJwt · method · since 9.5.0.58`

```sql
EXEC sp_OAMethod @jwt, 'VerifyJwt', @success OUT, @token, @password
```

Verifies the signature of a compact JWT signed with the shared secret in `password`. This method accepts only the HMAC algorithms `HS256`, `HS384`, and `HS512`. It rejects `none` and algorithms intended for asymmetric keys.

Chilkat reads the token's `alg` value, computes the corresponding HMAC over the encoded header and payload, and compares the result with the signature segment. The method returns `1` only when the signature matches.

**Signature verification only:** A successful result does not validate expiration, not-before time, issuer, audience, subject, or any other claim. Call `IsTimeValid` and perform the application's required claim checks separately.

**Enforce the expected algorithm:** Applications should inspect the verified header and require the specific HMAC algorithm allowed by their protocol rather than accepting any algorithm merely because this method supports it.

Returns 1 for success, 0 for failure.

### Jwt.VerifyJwtPk

`Chilkat 11.7.0 · sqlserver · Jwt · VerifyJwtPk · method · since 9.5.0.58`

```sql
EXEC sp_OAMethod @jwt, 'VerifyJwtPk', @success OUT, @token, @key
```

Verifies the signature of a compact JWT using `key`. The public key must match the private key that created the signature and must be compatible with the algorithm named by the token's `alg` header.

| JOSE algorithm | Verification key |
| :--- | :--- |
| `RS256`, `RS384`, `RS512` | RSA public key for RSASSA-PKCS1-v1_5. |
| `PS256`, `PS384`, `PS512` | RSA public key for RSASSA-PSS. |
| `ES256`, `ES384`, `ES512` | EC public key compatible with the ECDSA algorithm. |
| `EdDSA` | Ed25519 public key. Ed25519 verification requires Chilkat v9.5.0.84 or later. |

The method returns `1` only when the signature is valid. It returns `0` for a malformed token, unsupported or incompatible algorithm/key combination, incorrect key, or invalid signature. The unsecured `none` algorithm is rejected.

**Use a trusted key-selection process:** Do not automatically trust a key URL or key identifier taken from an unverified JWT header. Select the verification key from trusted configuration or a securely obtained and validated key set, and enforce the expected algorithm.

**Claims are not checked:** Signature validity proves only that the token was signed by the holder of the corresponding private key and was not modified. Validate time, issuer, audience, nonce, and all other required claims separately.

Returns 1 for success, 0 for failure.

## Related classes

[`Cert`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/sqlserver/classes/Cert.md), [`PrivateKey`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/sqlserver/classes/PrivateKey.md), [`PublicKey`](https://www.chilkatsoft.com/ai-docs/v/11.7.0/sqlserver/classes/PublicKey.md)

