Sample code for 30+ languages & platforms
DataFlex

Load a Private Key from XML Text

See more Private Key Examples

Demonstrates the Chilkat PrivateKey.LoadXml method, which loads a private key from XML text. The only argument is the XML string. Supported roots include RSAKeyValue, DSAKeyValue, ECCKeyValue, and Ed25519KeyValue.

Background: XML key representations such as RSAKeyValue come from the .NET/XML-DSIG world, where keys are exchanged as XML elements. This loads that form — the inverse of GetXml — which is handy for interoperating with .NET code or systems built around XML signatures. It is a plaintext format, so protect the XML like any unencrypted key material.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoPrivKey
    String sXmlText
    String sTemp1

    Move False To iSuccess

    //  Demonstrates the PrivateKey.LoadXml method, which loads a private key from XML text.  The only
    //  argument is the XML string.  Supported roots include RSAKeyValue, DSAKeyValue, ECCKeyValue,
    //  and Ed25519KeyValue.

    Get Create (RefClass(cComChilkatPrivateKey)) To hoPrivKey
    If (Not(IsComObjectCreated(hoPrivKey))) Begin
        Send CreateComObject of hoPrivKey
    End

    //  The XML text of a private key (for example as produced by GetXml).
    Move "<RSAKeyValue><Modulus>...</Modulus><Exponent>AQAB</Exponent>...</RSAKeyValue>" To sXmlText

    Get ComLoadXml Of hoPrivKey sXmlText To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoPrivKey To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComKeyType Of hoPrivKey To sTemp1
    Showln "Loaded a " sTemp1 " private key."


End_Procedure