I am working on a chat application, and I am trying to secure the communication by using asymmetric encryption. I am able to encrypt a message with the receiver's public key and decrypt a message with the receiver's private key.

However, how can a client be sure that the sender is the real sender?

Example: We have Alice and Bob. Alice encrypts a message with Bob's public key, and Bob decrypts the message with his own private key. However, how can he be sure that the sender of the message is Alice?

I have read about adding a nonce, but I am not sure how that will help. What I understand is that Alice will add a random number to the message she sends. Bob will be, somehow, able to identify the sender of the message as Alice by looking at this number?.

Let us say that the message is: "Hello Bob" and the nonce is "6". The message gets encrypted with Bob's public key, but what about the nonce?

  • 1
    Have you ever see whatsupp, signal; square code?
    – kelalaka
    Nov 1, 2018 at 19:07
  • No sorry, I have not :/
    – Bab
    Nov 1, 2018 at 19:09
  • See faq section of Whatsapp
    – kelalaka
    Nov 1, 2018 at 19:11
  • Regarding the nonce exchanging, does that have to happen before a chat starts, or is it the beginning of a chat?
    – Bab
    Nov 1, 2018 at 19:14
  • 1
    Write the public key into paper and send a photo, or call out loud in a telephone call
    – kelalaka
    Nov 1, 2018 at 19:25

1 Answer 1


In typical public-key cryptography, a user generates locally his public/private key pair. The private key is generally chosen at random and the public key is easily computed given the private. The problem in this approach is that you have no guarantee that the public key of a specific user is indeed associated to his private key; an man-in-the-middle can intercept the communication and substitute the public key with his public key so he can later decrypt the messages with his private key. To overcome this problem, usually a trusted third party issues certificates to prove the ownership of a public key. The certificate includes information about the key, information about the identity of its owner (called the subject), and the digital signature of the third party that has verified the certificate's contents. X.509 is a standard defining the format of public key certificates. Another solution to overcome this problem is to use identity-based cryptography. It was introduced in 1984 by Shamir (the 'S' guy is 'RSA') but his scheme was only working for signatures. In 2001, Boneh and Franklin proposed an encryption scheme using bilinear pairings over elliptic curves.

You must log in to answer this question.