Project

General

Profile

Actions

Feature #12354

closed

PKey::EC Can't output public key pem when private key exists

Added by armour (Armour Comms) over 8 years ago. Updated over 2 years ago.

Status:
Closed
Target version:
-
[ruby-core:75387]

Description

Steps to reproduce:

Create EC key:

key = OpenSSL::PKey::EC.new("prime256v1")
key.generate_key

Try and output in pem format

key.to_pem #Outputs private key pem
key.public_key.to_pem #Error

In order to output a public key pem, a new key object must be created with no private key:

key_pub = OpenSSL::PKey::EC.new(key.group)
key_pub.public_key = key.public_key

Output pem

key_pub.to_pem #Success!

From viewing the source, http://rxr.whitequark.org/mri/source/ext/openssl/ossl_pkey_ec.c#466 it seems that if the key is private there is no way to output a public key for that key object

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0