PowerBuilder
PowerBuilder
Encrypt a JWE with a Symmetric Wrapping Key
See more JSON Web Encryption (JWE) Examples
Demonstrates Jwe.SetWrappingKey, which sets the symmetric key-wrapping key for a recipient. The key bytes are supplied in a named encoding such as hex or base64.
Background. AES key wrapping protects the content-encryption key with a shared symmetric key. Both parties must possess the same wrapping key.
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Jwe
oleobject loo_Header
string ls_Base64Key
string ls_JweCompact
li_Success = 0
loo_Jwe = create oleobject
li_rc = loo_Jwe.ConnectToNewObject("Chilkat.Jwe")
if li_rc < 0 then
destroy loo_Jwe
MessageBox("Error","Connecting to COM object failed")
return
end if
// Protected header: AES key-wrap with AES-256-GCM content encryption.
loo_Header = create oleobject
li_rc = loo_Header.ConnectToNewObject("Chilkat.JsonObject")
loo_Header.UpdateString("alg","A256KW")
loo_Header.UpdateString("enc","A256GCM")
li_Success = loo_Jwe.SetProtectedHeader(loo_Header)
if li_Success = 0 then
Write-Debug loo_Jwe.LastErrorText
destroy loo_Jwe
destroy loo_Header
return
end if
// Set the symmetric key-wrapping key for recipient 0. The key bytes are provided in the named
// encoding (here base64). In production, obtain the key from a secure source rather than hard-coding
// it.
ls_Base64Key = "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXowMTIzNDU="
li_Success = loo_Jwe.SetWrappingKey(0,ls_Base64Key,"base64")
if li_Success = 0 then
Write-Debug loo_Jwe.LastErrorText
destroy loo_Jwe
destroy loo_Header
return
end if
ls_JweCompact = loo_Jwe.Encrypt("This is the secret content.","utf-8")
if loo_Jwe.LastMethodSuccess = 0 then
Write-Debug loo_Jwe.LastErrorText
destroy loo_Jwe
destroy loo_Header
return
end if
Write-Debug ls_JweCompact
destroy loo_Jwe
destroy loo_Header