Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Attempt to generate a compressed public key from EC private key
#!/usr/bin/env ruby
require 'bundler/inline'
gemfile do
gem "openssl"
# See
def real_public_key(k)
# TODO? .point_conversion_form = :compressed
point = k.public_key
pub =
pub.public_key = point
ec1 ='secp256k1').generate_key
# Write a file to file to covert it via the CLI"test-compressed-key.pem", 'w') {|f| f.write(ec1.to_pem) }
# CLI Version:
puts `openssl ec -in test-compressed-key.pem -pubout -conv_form compressed`
# Ruby Version:
puts real_public_key(ec1).to_pem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.