require 'openssl' group = OpenSSL::PKey::EC::Group.new('prime256v1') generator = group.generator #the generator point ec = OpenSSL::PKey::EC.new ec.group = group ec.generate_key #generate a key pair priv = ec.private_key #this is a random number, a OpenSSL::BN # the public point P is given by P = priv * G, # where s is the private key and G is the generator point pub_point = generator.mul(priv) puts ec.public_key == pub_point # true, now convert the point to an EC pub_ec = OpenSSL::PKey::EC.new pub_ec.group = group pub_ec.public_key = pub_point puts ec.to_text puts pub_ec.to_text #pub parts are equal! puts pub_ec.to_pem #to serialize it in PEM format