PureBasic
PureBasic
Load a Private Key from PEM Text
See more Private Key Examples
Demonstrates the Chilkat PrivateKey.LoadPem method, which loads a private key from PEM text. The only argument is the PEM string. It has no password argument, so it cannot load an encrypted PEM — use LoadEncryptedPem for that.
Background: PEM is the Base64 text format (delimited by
-----BEGIN----- lines) that most tooling uses for keys. This method is for the plain, unencrypted case where the key material sits in the clear inside the PEM — convenient, but it means the file itself is the only thing protecting the key. When the PEM is password-protected (a BEGIN ENCRYPTED PRIVATE KEY block or a legacy encrypted header), reach for the Encrypted loader instead.Chilkat PureBasic Downloads
IncludeFile "CkPrivateKey.pb"
Procedure ChilkatExample()
success.i = 0
; Demonstrates the PrivateKey.LoadPem method, which loads a private key from PEM text. The only
; argument is the PEM string. This method has no password argument, so it cannot load an
; encrypted PEM -- use LoadEncryptedPem for that.
privKey.i = CkPrivateKey::ckCreate()
If privKey.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; The PEM text of an unencrypted private key.
pemText.s = "-----BEGIN PRIVATE KEY-----" + Chr(10) + "MIIEvAIBADANBgkq..." + Chr(10) + "-----END PRIVATE KEY-----"
success = CkPrivateKey::ckLoadPem(privKey,pemText)
If success = 0
Debug CkPrivateKey::ckLastErrorText(privKey)
CkPrivateKey::ckDispose(privKey)
ProcedureReturn
EndIf
Debug "Loaded a " + CkPrivateKey::ckKeyType(privKey) + " private key."
CkPrivateKey::ckDispose(privKey)
ProcedureReturn
EndProcedure