Sample code for 30+ languages & platforms
PowerShell Requires Chilkat v11.0.0+

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 PowerShell Downloads

PowerShell
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"

$success = $false

#  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-----

$privKey = New-Object Chilkat.PrivateKey
$success = $privKey.LoadPemFile("qa_data/ecc/secp256r1-key-pkcs8.pem")
if ($success -eq $false) {
    $($privKey.LastErrorText)
    exit
}

#  Get the public key.
$pubKey = New-Object Chilkat.PublicKey
$privKey.ToPublicKey($pubKey)

#  Save the public key to a PEM file.
$success = $pubKey.SavePemFile($false,"qa_data/ecc/secp256r1-pubkey.pem")
if ($success -eq $false) {
    $($pubKey.LastErrorText)
    exit
}

#  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-----

$("Success.")