DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoPrivKey
Variant vSbPublic
Handle hoSbPublic
String sPrivHex
String sTemp1
Boolean bTemp1
Move False To iSuccess
// Load a private key to export.
Get Create (RefClass(cComChilkatPrivateKey)) To hoPrivKey
If (Not(IsComObjectCreated(hoPrivKey))) Begin
Send CreateComObject of hoPrivKey
End
Get ComLoadPemFile Of hoPrivKey "qa_data/private.pem" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoPrivKey To sTemp1
Showln sTemp1
Procedure_Return
End
// 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.
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbPublic
If (Not(IsComObjectCreated(hoSbPublic))) Begin
Send CreateComObject of hoSbPublic
End
Get pvComObject of hoSbPublic to vSbPublic
Get ComGetRawHex Of hoPrivKey vSbPublic To sPrivHex
Get ComLastMethodSuccess Of hoPrivKey To bTemp1
If (bTemp1 = False) Begin
Get ComLastErrorText Of hoPrivKey To sTemp1
Showln sTemp1
Procedure_Return
End
Showln "Raw private value: " sPrivHex
Get ComGetAsString Of hoSbPublic To sTemp1
Showln "Raw public key: " sTemp1
End_Procedure