(PureBasic) Duplicate openssl pkey -in private.pem -pubout -out pubkey.pem
How to output the public part of a private key:
Demonstrates how to duplicate this OpenSSL command:
openssl pkey -in private.pem -pubout -out pubkey.pem
IncludeFile "CkPublicKey.pb"
IncludeFile "CkPrivateKey.pb"
Procedure ChilkatExample()
pkey.i = CkPrivateKey::ckCreate()
If pkey.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; Load the private key from an PEM file:
success.i = CkPrivateKey::ckLoadPemFile(pkey,"private.pem")
If success <> 1
Debug CkPrivateKey::ckLastErrorText(pkey)
CkPrivateKey::ckDispose(pkey)
ProcedureReturn
EndIf
pubKey.i = CkPrivateKey::ckGetPublicKey(pkey)
If CkPrivateKey::ckLastMethodSuccess(pkey) = 0
Debug CkPrivateKey::ckLastErrorText(pkey)
CkPrivateKey::ckDispose(pkey)
ProcedureReturn
EndIf
success = CkPublicKey::ckSavePemFile(pubKey,0,"pubKey.pem")
If success <> 1
Debug CkPublicKey::ckLastErrorText(pubKey)
CkPublicKey::ckDispose(pubKey)
CkPrivateKey::ckDispose(pkey)
ProcedureReturn
EndIf
Debug "Success."
CkPublicKey::ckDispose(pubKey)
CkPrivateKey::ckDispose(pkey)
ProcedureReturn
EndProcedure
|