PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Jws
oleobject loo_Header
integer li_BIncludeBom
oleobject loo_BdKey
string ls_JwsCompact
li_Success = 0
loo_Jws = create oleobject
li_rc = loo_Jws.ConnectToNewObject("Chilkat.Jws")
if li_rc < 0 then
destroy loo_Jws
MessageBox("Error","Connecting to COM object failed")
return
end if
// Protected header specifying HMAC-SHA256.
loo_Header = create oleobject
li_rc = loo_Header.ConnectToNewObject("Chilkat.JsonObject")
loo_Header.UpdateString("alg","HS256")
li_Success = loo_Jws.SetProtectedHeader(0,loo_Header)
if li_Success = 0 then
Write-Debug loo_Jws.LastErrorText
destroy loo_Jws
destroy loo_Header
return
end if
li_BIncludeBom = 0
li_Success = loo_Jws.SetPayload("This is the content to sign.","utf-8",li_BIncludeBom)
if li_Success = 0 then
Write-Debug loo_Jws.LastErrorText
destroy loo_Jws
destroy loo_Header
return
end if
// 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.
loo_BdKey = create oleobject
li_rc = loo_BdKey.ConnectToNewObject("Chilkat.BinData")
loo_BdKey.AppendEncoded("YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXowMTIzNDU=","base64")
li_Success = loo_Jws.SetMacKeyBd(0,loo_BdKey)
if li_Success = 0 then
Write-Debug loo_Jws.LastErrorText
destroy loo_Jws
destroy loo_Header
destroy loo_BdKey
return
end if
ls_JwsCompact = loo_Jws.CreateJws()
if loo_Jws.LastMethodSuccess = 0 then
Write-Debug loo_Jws.LastErrorText
destroy loo_Jws
destroy loo_Header
destroy loo_BdKey
return
end if
Write-Debug ls_JwsCompact
destroy loo_Jws
destroy loo_Header
destroy loo_BdKey