jwtAlgSetSym (Function)

Top  Previous  Next

Architecture:

NX32L

Firmware version:

1.70.00


jwtAlgSetSym configures the JWT object to use a symmetrical encryption.

Mainly for use with JWT objects created with jwtCreate.

To configure an asymmetrical encryption, see jwtAlgSetAsym.

 

 

Input:

jwt : SYSHANDLE

The JWT object to set the encryption algorithm for.

 

 

type : INT default 0

The kind of algorithm to use:

0

- No encryption

1

- HS256

2

- HS384

3

- HS512

 

 

key: PTR

The key to use for encoding the token.

 

key_len : INT

The size of the key.

 

 

Returns: INT

1

- Success

0

- Not supported.

-2

- Could not find JWT object.

-3

- Unsupported algorithm.

-99

- Failed to set algorithm.

 

 

Declaration:

FUNCTION jwtAlgSetSym : INT;
VAR_INPUT
   type    : INT;
   jwt     : SYSHANDLE;
   key     : PTR;
   key_len : INT;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
PROGRAM test;
VAR
   rc      : INT;
   jwt     : SYSHANDLE;
   key     : ARRAY[0..20OF BYTE;
   key_len : INT;
END_VAR;
 
BEGIN
   ...
   // Prepare key
   key_len := strlen(str:="your-256-bit-secret");
   rc := strToMemory(dst:=ADDR(key), str:="your-256-bit-secret", len := key_len);
   // Set algorithm
   rc := jwtAlgSetSym(jwt:=jwttype := 1key := ADDR(key), key_len := key_len);
   ...
END;
 
END_PROGRAM;