I am confused in digital signature. what is use of encryption with private key and decryption with public key. Using public key we can decrypt the signature then what is use of private key privacy. Explain in detail.
When talking about digital signatures, the private key is what proves the authenticity of the signature, precisely because it is private.
The use case proceeds like this: I choose a private and public key pair. Because I chose it, only I know both keys. I then send a message and sign it by using my private key, typically by encrypting a digest, hash, or checksum of the message with the private key, so that it can only be decrypted with the matching public key.
I publish my public key for others to verify my signature with.
The receiver then manually computes the same digest of the message, decrypts the signature I sent along with it using my public key, and compares the two. If they are identical, the only way that is possible is if I am indeed the person who has the private key and published its matching public key. Otherwise, I would not have been able to properly sign the message without my private key.
This works because it is exceedingly difficult to compute the private key from the public key, so much so that it would take a very long time even on a supercomputer.
You might ask at this point, why is the signature an encrypted digest or hash of the message? If the message differs in any way (was tampered with or intercepted, as with a man-in-the-middle attack), the digest won't match whether it's decrypted correctly or not. So tampering with the message necessarily invalidates the signature, because it's a digest of the message itself, proving it's the same message sent by the person who signed it.
"what is use of encryption with private key and decryption with public key"
The sender can sign a message with their private key (not encrypt it). This creates a signature, which is a blob with the message, to be sent with the message. The message is still in plaintext-> it is not encrypted and anyone can read it.
The purpose is to allow the receiver to authenticate, meaning to know without a doubt who the sender is.
You may ask yourself, why would I want to authenticate? Well, for just sending messages in emails, you might not want to use this function, and that's ok! But, just know that there computer systems that automatically use this authentication function, and they must, or they can easily be hacked. This includes TLS (the padlock in your browser).
Keep in mind, though, that this signing is not encrypting, although some documentation confuses people by saying it is.
I leave an example of RSA signature creation and verification process (note that other signature schemes will work in other way):
- Sender computes the hash of the message that's going to be sent.
- Sender signs the hash of that message with his private key. We call this signature a digital signature.
- Senders sends to the receiver the message along with the digital signature and his public key.
- Receiver verifies the digital signature deciphering it with sender's public key and obtains the original hash computed over the message.
- Receiver computes the hash of the message and compares it with the obtained hash.
Now, if both hashes match then we know:
Message has not been altered or modified.
The message belongs to the sender since we have deciphered the digital signature with his public key, that means he signed it with his private key.
Take a look at PGP. It is a mix of this scheme including symmetric-key encryption.