DataFlex
DataFlex
Validate a JWS Signature
See more JSON Web Signatures (JWS) Examples
Demonstrates Jws.Validate, which validates exactly one signature, identified by a zero-based index, using the key configured at that same index.
Background. Validate returns 1 when the signature or MAC is cryptographically valid, 0 when it is not, or a negative value on error. The verifying key must be provided before validating.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoJws
String sJwsCompact
String sBase64Key
Integer v
String sTemp1
Move False To iSuccess
Get Create (RefClass(cComChilkatJws)) To hoJws
If (Not(IsComObjectCreated(hoJws))) Begin
Send CreateComObject of hoJws
End
// Load the JWS compact serialization.
Move "eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>" To sJwsCompact
Get ComLoadJws Of hoJws sJwsCompact To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoJws To sTemp1
Showln sTemp1
Procedure_Return
End
// Provide the key for signature 0 (here an HMAC key).
Move "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXowMTIzNDU=" To sBase64Key
Get ComSetMacKey Of hoJws 0 sBase64Key "base64" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoJws To sTemp1
Showln sTemp1
Procedure_Return
End
// Validate the signature identified by the zero-based index, using the key configured at that index.
// Validate returns 1 when the signature or MAC is cryptographically valid, 0 when it is not, or a
// negative value on error.
Get ComValidate Of hoJws 0 To v
If (v < 0) Begin
Get ComLastErrorText Of hoJws To sTemp1
Showln sTemp1
Procedure_Return
End
If (v <> 1) Begin
Showln "The signature is not valid."
Procedure_Return
End
Showln "The signature is valid."
End_Procedure