Hi,
I have the private key 7a01628988d23fae697fa05fcdae5a82fe4f749aa9f24d35d23f81bee917dfc3 that I transform into privkey.pem and pubkey.pem with:
function pktopu($hash){
$hexadecimal_string="302e0201010420".$hash."a00706052b8104000a";
file_put_contents("$hash.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");
$out = array();
exec("openssl ec -conv_form compressed -in $hash.pem -text -noout",$out);
exec("openssl ec -in privkey.pem -pubout > pubkey.pem");
return str_replace(':', '', str_replace(' ', '', $out[6].$out[7].$out[8]));
}
Extracted public key is: 03359ac0aa241b1a40fcab68486f8a4b546ad3301d201c3645487093578592ec8f
Seems to work.
Now I wish to sign a message: iSignedThisDataThatIs256BitsLong
In order to recieve the signature.
How I have to process this message and signature?
file_put_contents("tmp.msg",$msg);
exec("openssl dgst -sha256 tmp.msg > msg.sha256");
file_put_contents("tmp.msg",$msg."\n");
exec("openssl dgst -sha256 tmp.msg > msg.sha256");
file_put_contents("tmp.msg",$msg."\n");
exec("openssl dgst -sha256 tmp.msg > msg.sha256");
$shafile = file_get_contents("msg.sha256");
$shafile=trim(str_replace("SHA256(tmp.msg)=","",$shafile));
file_put_contents("msg.sha256",hex2bin($shafile));
ETC.
The question is how I create a file msg.sha256 from message to be signed in order to obtain the right signature?
Any combination don't give me the right signature with:
exec("openssl dgst -sha256 -sign $hash.pem -out tmp.sig msg.sha256",$out);
exec("openssl dgst -sha256 -hex -sign $hash.pem -out tmp.sig.hex msg.sha256",$out);
exec("openssl dgst -sha256 -verify pubkey.pem -signature tmp.sig msg.sha256",$out);
signature must be: 304402205587dfc87c3227ad37b021c08c873ca4b1faada1a83f666d483711edb2f4f743022004e
e40d9fe8dd03e6d42bfc7d0e53f75286125a591ed14b39265978ebf3eea36