I came to the conclusion why not make my own digital signature function.
The digital signature algorithm works as follows: first, the plaintext is hashed, then it is encrypted with the user's secret key, and then the result is combined with the plaintext.
pseudo code:
return [input + encrypt(md5(input),private_key)]
To verify: the input is divided into plain text and signature. then the signature is decrypted using the public key. The result is then compared with a hash of plain text, and if they are equal, this means that the signature is verified.
pseudo code:
explode(input) --> plain_text , signature if( decrypt(signature,public_key) == md5(plain_text) ) then signature is trusted
Now the real PHP code that I tested and am currently using:
function sign($cleartext,$private_key) { $msg_hash = md5($cleartext); openssl_private_encrypt($msg_hash, $sig, $private_key); $signed_data = $cleartext . "----SIGNATURE:----" . $sig; return mysql_real_escape_string($signed_data); } function verify($my_signed_data,$public_key) { list($plain_data,$old_sig) = explode("----SIGNATURE:----", $my_signed_data); openssl_public_decrypt($old_sig, $decrypted_sig, $public_key); $data_hash = md5($plain_data); if($decrypted_sig == $data_hash && strlen($data_hash)>0) return $plain_data; else return "ERROR -- untrusted signature"; }
Omidoo
source share