Created
August 4, 2012 00:58
-
-
Save emboss/3253173 to your computer and use it in GitHub Desktop.
Revisions
-
emboss created this gist
Aug 4, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ 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