DataFlex
DataFlex
Load a Public Key from a String
Demonstrates the Chilkat PublicKey.LoadFromString method, which loads a public key from a string. The only argument is the string. Chilkat examines the content and recognizes PEM public keys, unencrypted PEM private keys (taking only the public portion), XML, JWK, and more.
Background: This is the forgiving text loader: rather than requiring you to know the exact format, it inspects whatever string you provide and figures it out. A useful convenience is that it accepts an unencrypted private key too and keeps only the public half — handy when you have a key pair but need just the public key. Use it whenever the textual format is uncertain or varies by source.
Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoPubKey
String sKeyText
String sTemp1
Move False To iSuccess
// Demonstrates the PublicKey.LoadFromString method, which loads a public key from a string. The
// only argument is the string. Chilkat examines the content and recognizes PEM public keys,
// unencrypted PEM private keys (using only the public portion), XML, JWK, and more.
Get Create (RefClass(cComChilkatPublicKey)) To hoPubKey
If (Not(IsComObjectCreated(hoPubKey))) Begin
Send CreateComObject of hoPubKey
End
// The PEM text of a public key.
Move "-----BEGIN PUBLIC KEY-----" + (character(10)) + "MIIBIjANBgkq...IDAQAB" + (character(10)) + "-----END PUBLIC KEY-----" To sKeyText
Get ComLoadFromString Of hoPubKey sKeyText To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoPubKey To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComKeyType Of hoPubKey To sTemp1
Showln "Loaded a " sTemp1 " public key."
End_Procedure