Note that there are some explanatory texts on larger screens.

plurals
  1. POexample signatures php
    primarykey
    data
    text
    <p>I implemented an example (for better understanding for myself) of how digital signatures work (in my case with php).</p> <p>I used the story from Bob and Alice under "How is a digital signature used for authentication?" from <a href="http://www.verisign.com.au/repository/tutorial/digital/intro1.shtml" rel="nofollow">http://www.verisign.com.au/repository/tutorial/digital/intro1.shtml</a></p> <p><em>"Suppose Alice wants to send a signed message to Bob. She creates a message digest by using a hash function on the message. The message digest serves as a "digital fingerprint" of the message; if any part of the message is modified, the hash function returns a different result. Alice then encrypts the message digest with her private key. This encrypted message digest is the digital signature for the message. Alice sends both the message and the digital signature to Bob. When Bob receives them, he decrypts the signature using Alice's public key, thus revealing the message digest. To verify the message, he then hashes the message with the same hash function Alice used and compares the result to the message digest he received from Alice. If they are exactly equal, Bob can be confident that the message did indeed come from Alice and has not changed since she signed it. If the message digests are not equal, the message either originated elsewhere or was altered after it was signed (or the private key is different)."</em> </p> <p>Before I post the code I would like to mention that this is probably not the right way not using standard generated key. But I should give me (and maybe you) an understanding of how signatures work.</p> <pre><code>echo "Example 2 &lt;br&gt;&lt;br&gt;"; $res = openssl_pkey_new(); /* Extract the private key from $res to $privKey */ openssl_pkey_export($res, $privKey); /* Extract the public key from $res to $pubKey */ $pubKey = openssl_pkey_get_details($res); $pubKey = $pubKey["key"]; $message = "Im a message"; echo "&lt;br&gt;&lt;br&gt;&lt;strong&gt;Public key:&lt;/strong&gt;&lt;br&gt;"; echo $pubKey; echo "&lt;br&gt;&lt;br&gt;&lt;strong&gt;Private key:&lt;/strong&gt;&lt;br&gt;"; echo $privKey; echo "&lt;br&gt;&lt;br&gt;&lt;strong&gt;Message:&lt;/strong&gt;&lt;br&gt;"; echo $message; echo "&lt;br&gt;&lt;br&gt;&lt;strong&gt;Message digest:&lt;/strong&gt;&lt;br&gt;"; echo $md5message = sha1($message); echo "&lt;br&gt;&lt;br&gt;&lt;strong&gt;Message digest encrypted(signature):&lt;/strong&gt;&lt;br&gt;"; openssl_private_encrypt($md5message, $crypted, $privKey); echo $crypted; echo "&lt;br&gt;&lt;br&gt;&lt;strong&gt;Bob uses sha1 as well for the message:&lt;/strong&gt;&lt;br&gt;"; echo $md5message = md5($message); echo "&lt;br&gt;&lt;br&gt;&lt;strong&gt;Bob checks with decrypt(verify):&lt;/strong&gt;&lt;br&gt;"; openssl_public_decrypt($crypted, $decrypted, $pubKey); echo $decrypted; </code></pre> <p>I have 3 questions:</p> <p>1) Is the workflow right on how signatures work? What should I change (as mentioned before I dont want to generate "proper".pem,.crt etc keys...would be next step for me).</p> <p>2) In my understanding the private key was always to decrypt. The public key for encryption. I am aware wording here is sign for the private key, and verify with the public key. Obviously I can verify it in this example with only the public key. I cant get my head around that. How is this possible? Maybe you can give me a better example or links?</p> <p>3) What should I change in my implementation?</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload