php - why different result with sign and encrypt with priv key -
i coding openssl, , know, why openssl_sign function, gives diferent result openssl_private_encrypt
in logical sense.
specifically openssl_sign:
$fp = fopen("i.pem", "r"); //i.pem private key file $priv_key = fread($fp, 8192); fclose($fp); $pkeyid = openssl_get_privatekey($priv_key); $data="f2e140eb-2b09-44ab-8504-87b25d81914c"; openssl_sign($data, $signature, $pkeyid); $reto22 = base64_encode($signature); //this gives unmlefwisea9hogfiwdm.......
specifically openssl_private_encrypt:
$llave_priv = file_get_contents("i.pem"); //i.pem private key file $plaintext = "f2e140eb-2b09-44ab-8504-87b25d81914c"; openssl_private_encrypt($plaintext, $encrypted, $llave_priv); $reto = base64_encode($encrypted); //this gives ugsmascqlikilq17exivseqka60.......
why reto22
different $reto
? should same, shouldn't they? encrypt priv key = sign
, far know
thanks clarifying mario
generally speaking, encryption in public key systems performed public key (so private key can used decrypt it) while signing done private key (so public key can used verify it)
signatures openssl involve encrypting hash of message. if same key used, output different, because while openssl_private_encrypt
encrypt private key in signature scheme, doesn't hash message, or (possibly, not certain) perform same padding signature scheme perform.
stick openssl_sign
, more efficient , less prone potential side channel attacks rolling own signature scheme.
php encryption signature
No comments:
Post a Comment