Author

Topic: Public key from private key and sign in php without gmp (Read 168 times)

jr. member
Activity: 76
Merit: 1
Solution:

// hex to bin this in order to accomplish EC secp256k1 curve: 302e0201010420 7a01628988d23fae697fa05fcdae5a82fe4f749aa9f24d35d23f81bee917dfc3 a00706052b8104000a
$hexadecimal_string="302e02010104207a01628988d23fae697fa05fcdae5a82fe4f749aa9f24d35d23f81bee917dfc3a 00706052b8104000a";

//Write to file in PEM format

file_put_contents("pk.pem","-----BEGIN EC PARAMETERS-----
BgUrgQQACg==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
".chunk_split(base64_encode(pack('H*',$hexadecimal_string)), 64, "\n")."-----END EC PRIVATE KEY-----\n");

//pem to der

exec('openssl ec -outform der -in pk.pem -out pk.der',$out);

//output both, private and public key

exec('openssl ec -conv_form compressed -inform DER -in pk.der -text -noout',$out);
jr. member
Activity: 76
Merit: 1
I generate the private key:
7a01628988d23fae697fa05fcdae5a82fe4f749aa9f24d35d23f81bee917dfc3 (taken from: https://www.block.io/api/simple/signing )

Then I wish to transform that private key to .pem format in order to apply:

exec("openssl ec -in pk.pem -pubout -out pu.pem",$out);

It works when:
exec("openssl ecparam -genkey -name secp256k1 -rand /dev/urandom -out pk.pem",$out);
exec("openssl ec -in pk.pem -pubout -out pu.pem",$out);

creates pk.pem and pu.pem.

If I try to:
file_put_contents("pk.pem","-----BEGIN EC PARAMETERS-----
BgUrgQQACg==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
".chunk_split(base64_encode($private_key), 64, "\n")."-----END EC PRIVATE KEY-----\n");

Doesn't generate public key pem (pu.pem).
What I'm doing wrong??

Mising create some extended version of private keys?

Thank you.
PD: Next step will be transform pu.pem to some bitcoin public key format.
jr. member
Activity: 76
Merit: 1
Hi,

unfortunatelly my hosting isn't updated with gmp libraries (https://www.php.net/manual/es/book.gmp.php),
need it in order to find public key from private key and complete signing process.

There is any form to work with openssl via exec or similar to get public key from private key?

I'm working with block.io and everthing is fine.

Thank you
Jump to: