Visual FoxPro
Visual FoxPro
Sign a JWS with an HMAC Key from BinData
See more JSON Web Signatures (JWS) Examples
Demonstrates Jws.SetMacKeyBd, which sets the symmetric MAC key for a signature from the raw bytes in a BinData.
Background. This is the in-memory equivalent of SetMacKey, for when the key material is already available as bytes.
Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loJws
LOCAL loHeader
LOCAL lnBIncludeBom
LOCAL loBdKey
LOCAL lcJwsCompact
lnSuccess = 0
loJws = CreateObject('Chilkat.Jws')
* Protected header specifying HMAC-SHA256.
loHeader = CreateObject('Chilkat.JsonObject')
loHeader.UpdateString("alg","HS256")
lnSuccess = loJws.SetProtectedHeader(0,loHeader)
IF (lnSuccess = 0) THEN
? loJws.LastErrorText
RELEASE loJws
RELEASE loHeader
CANCEL
ENDIF
lnBIncludeBom = 0
lnSuccess = loJws.SetPayload("This is the content to sign.","utf-8",lnBIncludeBom)
IF (lnSuccess = 0) THEN
? loJws.LastErrorText
RELEASE loJws
RELEASE loHeader
CANCEL
ENDIF
* Set the symmetric MAC key for signature 0 from the raw bytes in a BinData. In production, obtain
* the key material from a secure source.
loBdKey = CreateObject('Chilkat.BinData')
loBdKey.AppendEncoded("YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXowMTIzNDU=","base64")
lnSuccess = loJws.SetMacKeyBd(0,loBdKey)
IF (lnSuccess = 0) THEN
? loJws.LastErrorText
RELEASE loJws
RELEASE loHeader
RELEASE loBdKey
CANCEL
ENDIF
lcJwsCompact = loJws.CreateJws()
IF (loJws.LastMethodSuccess = 0) THEN
? loJws.LastErrorText
RELEASE loJws
RELEASE loHeader
RELEASE loBdKey
CANCEL
ENDIF
? lcJwsCompact
RELEASE loJws
RELEASE loHeader
RELEASE loBdKey