PowerBuilder
PowerBuilder
Get EC Public Key from EC Private Key
See more ECC Examples
Demonstrates how to get an EC public key from an EC private key.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_PrivKey
oleobject loo_PubKey
li_Success = 0
// We have an ECC private key...
// The contents of the private key PEM file look like this:
// -----BEGIN PRIVATE KEY-----
// MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg3J8q/24D1sEKGdP9
// 72MGYElLGpw/a56Y3t6pfON3uhShRANCAATlSmoizyhAwoYZAOuFBATl07/1RR54
// a1Dzfm16grxJe666AGKR+bSs24hk7TEpaeCTvT8YOOM3l+xKFg7zq6Q9
// -----END PRIVATE KEY-----
loo_PrivKey = create oleobject
li_rc = loo_PrivKey.ConnectToNewObject("Chilkat.PrivateKey")
if li_rc < 0 then
destroy loo_PrivKey
MessageBox("Error","Connecting to COM object failed")
return
end if
li_Success = loo_PrivKey.LoadPemFile("qa_data/ecc/secp256r1-key-pkcs8.pem")
if li_Success = 0 then
Write-Debug loo_PrivKey.LastErrorText
destroy loo_PrivKey
return
end if
// Get the public key.
loo_PubKey = create oleobject
li_rc = loo_PubKey.ConnectToNewObject("Chilkat.PublicKey")
loo_PrivKey.ToPublicKey(loo_PubKey)
// Save the public key to a PEM file.
li_Success = loo_PubKey.SavePemFile(0,"qa_data/ecc/secp256r1-pubkey.pem")
if li_Success = 0 then
Write-Debug loo_PubKey.LastErrorText
destroy loo_PrivKey
destroy loo_PubKey
return
end if
// The contents of the ECC public key PEM file look like this:
// -----BEGIN PUBLIC KEY-----
// MIIBSzCCAQMGByqGSM49AgEwgfcCAQEwLAYHKoZIzj0BAQIhAP////8AAAABAAAA
// AAAAAAAAAAAA////////////////MFsEIP////8AAAABAAAAAAAAAAAAAAAA////
// ///////////8BCBaxjXYqjqT57PrvVV2mIa8ZR0GsMxTsPY7zjw+J9JgSwMVAMSd
// NgiG5wSTamZ44ROdJreBn36QBEEEaxfR8uEsQkf4vOblY6RA8ncDfYEt6zOg9KE5
// RdiYwpZP40Li/hp/m47n60p8D54WK84zV2sxXs7LtkBoN79R9QIhAP////8AAAAA
// //////////+85vqtpxeehPO5ysL8YyVRAgEBA0IABOVKaiLPKEDChhkA64UEBOXT
// v/VFHnhrUPN+bXqCvEl7rroAYpH5tKzbiGTtMSlp4JO9Pxg44zeX7EoWDvOrpD0=
// -----END PUBLIC KEY-----
Write-Debug "Success."
destroy loo_PrivKey
destroy loo_PubKey