(PureBasic) Get Base64 Public Key from Private Key
Demonstrates how to get the public key in base64 format from a private key.
IncludeFile "CkBinData.pb"
IncludeFile "CkPrivateKey.pb"
IncludeFile "CkPublicKey.pb"
Procedure ChilkatExample()
; Load a private key from base64.
bd.i = CkBinData::ckCreate()
If bd.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success.i = CkBinData::ckAppendEncoded(bd,"MHQCA....n0Q==","base64")
privKey.i = CkPrivateKey::ckCreate()
If privKey.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkPrivateKey::ckLoadAnyFormat(privKey,bd,"")
If success = 0
Debug CkPrivateKey::ckLastErrorText(privKey)
CkBinData::ckDispose(bd)
CkPrivateKey::ckDispose(privKey)
ProcedureReturn
EndIf
pubKey.i = CkPrivateKey::ckGetPublicKey(privKey)
If CkPrivateKey::ckLastMethodSuccess(privKey) = 0
Debug CkPrivateKey::ckLastErrorText(privKey)
CkBinData::ckDispose(bd)
CkPrivateKey::ckDispose(privKey)
ProcedureReturn
EndIf
pubKeyBase64.s = CkPublicKey::ckGetEncoded(pubKey,1,"base64")
Debug pubKeyBase64
CkPublicKey::ckDispose(pubKey)
CkBinData::ckDispose(bd)
CkPrivateKey::ckDispose(privKey)
ProcedureReturn
EndProcedure
|