Sample code for 30+ languages & platforms
PowerBuilder

Get a Private Key's Raw Hex Value

See more Private Key Examples

Demonstrates the Chilkat PrivateKey.GetRawHex method, which returns the raw private value as lowercase hexadecimal and replaces the contents of the supplied StringBuilder with the corresponding raw public key.

Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background: This drops below the structured container formats to the bare key bytes as hex, which is meaningful chiefly for fixed-size keys such as EC and Ed25519 where a key is essentially a fixed byte string. It is the export to use when another system wants raw values rather than PEM or JWK — the counterpart to LoadEd25519. Both the returned private hex and the public value are produced in one call.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_PrivKey
oleobject loo_SbPublic
string ls_PrivHex

li_Success = 0

//  Load a private key to export.
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
li_Success = loo_PrivKey.LoadPemFile("qa_data/private.pem")
if li_Success = 0 then
    Write-Debug loo_PrivKey.LastErrorText
    destroy loo_PrivKey
    return
end if

//  GetRawHex returns the raw private value as lowercase hex, and replaces the contents of the
//  StringBuilder argument with the corresponding raw public key.  This is most meaningful for
//  fixed-size keys such as EC and Ed25519.
loo_SbPublic = create oleobject
li_rc = loo_SbPublic.ConnectToNewObject("Chilkat.StringBuilder")

ls_PrivHex = loo_PrivKey.GetRawHex(loo_SbPublic)
if loo_PrivKey.LastMethodSuccess = 0 then
    Write-Debug loo_PrivKey.LastErrorText
    destroy loo_PrivKey
    destroy loo_SbPublic
    return
end if

Write-Debug "Raw private value: " + ls_PrivHex
Write-Debug "Raw public key: " + loo_SbPublic.GetAsString()


destroy loo_PrivKey
destroy loo_SbPublic