Bitcoin Forum
May 13, 2024, 02:12:48 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Public key from private key and sign in php without gmp  (Read 168 times)
patinencomun (OP)
Jr. Member
*
Offline Offline

Activity: 76
Merit: 1


View Profile
October 09, 2019, 03:10:06 PM
 #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
1715566368
Hero Member
*
Offline Offline

Posts: 1715566368

View Profile Personal Message (Offline)

Ignore
1715566368
Reply with quote  #2

1715566368
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715566368
Hero Member
*
Offline Offline

Posts: 1715566368

View Profile Personal Message (Offline)

Ignore
1715566368
Reply with quote  #2

1715566368
Report to moderator
patinencomun (OP)
Jr. Member
*
Offline Offline

Activity: 76
Merit: 1


View Profile
October 09, 2019, 07:22:08 PM
 #2

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.
patinencomun (OP)
Jr. Member
*
Offline Offline

Activity: 76
Merit: 1


View Profile
October 10, 2019, 05:39:35 AM
 #3

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);
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!