PowerBuilder
PowerBuilder
Load a Private Key from a JWK
See more Private Key Examples
Demonstrates the Chilkat PrivateKey.LoadJwk method, which loads a private key from JWK (JSON Web Key) JSON. The only argument is the JWK JSON string. Supported key types are RSA, EC, and Ed25519 (kty=OKP).
Background: JWK is the JSON key format used throughout modern web security — JWT signing, OAuth, OpenID Connect — so this loader is what you use to consume a key from a JWK Set or an identity provider. A private JWK includes the private parameters (
d and, for RSA, the CRT values); a public-only JWK omits them. As JSON in the clear, a private JWK must be handled as sensitive material.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_PrivKey
string ls_Jwk
li_Success = 0
// Demonstrates the PrivateKey.LoadJwk method, which loads a private key from JWK (JSON Web Key)
// JSON. The only argument is the JWK JSON string. Supported key types are RSA, EC, and
// Ed25519 (kty=OKP).
loo_PrivKey = create oleobject
li_rc = loo_PrivKey.ConnectToNewObject("Chilkat.PrivateKey")
if li_rc < 0 then
destroy loo_PrivKey
MessageBox("Error","Connecting to COM object failed")
return
end if
// A private JWK. For a real key, "d" (and the other private parameters) would be present.
ls_Jwk = "{~"kty~":~"EC~",~"crv~":~"P-256~",~"x~":~"...~",~"y~":~"...~",~"d~":~"...~"}"
li_Success = loo_PrivKey.LoadJwk(ls_Jwk)
if li_Success = 0 then
Write-Debug loo_PrivKey.LastErrorText
destroy loo_PrivKey
return
end if
Write-Debug "Loaded a " + loo_PrivKey.KeyType + " private key."
destroy loo_PrivKey