Signing ✍ and Verifying ✅ Asymmetric Encryption Decryption with RSA Implementation

3 min readJun 23, 2021


This is Bob and Alice's secure message transaction implementation demonstration application. Specifically, I’m sharing how to sign and verify asymmetric encryption and decryption with the RSA crypto service in this article.

Overall Plan

As I mentioned in a previous article, since this is a public key sharing approach, the public key can access by Eve too. So She can send messages too. to avoid this scenario we have to go with the Sign and Verify approach.

This is the extended implementation of the previous asymmetric encryption-decryption program.

Solution View

The overall design can show in this way

Big Picture

mainly it will contain the following methods.

Interface Contract
Service Implementation

When Alice wants to send her message, she has to encrypt her message with bob’s public key and then the same plain text sign again with her private key, keep those as separate files.

encryptedData.dat (encrypted with Bob’s public key)
encryptedSignedData.dat (signed with Alice’s private key)

Alice (Sender) Console App

When Bob receives that message, he can decrypt the encryptedData.dat file using his private key and then verify that message sent by Alice, by decrypting the encryptedSignedData.dat file using Alice’s public key.

encryptedData.dat (decrypt with Bob’s private key)
encryptedSignedData.dat (decrypt with Alice’s public key, then compare)

Bob (Reciever) Console App

In order to make this solution work, there is a flow to run this application

  1. Run Bob Console App to generate Bob’s public/private key pair
The output of Bob Program Run

2. Run Alice Console App to Encrypt and Sign the Alice message

The output of Alice Program Run

3. Run Bob Console App to Decrypt and Verify Alice message

Final Verified Success, with Plain Text

We can test this actually working by changing some data in the encryptedSignedData.dat file

Before Change encryptedSignedData.dat file
After Change encryptedSignedData.dat file

Now we run again Bob program

Error message after change encryptedSignedData.dat file

By changing the encryptedSignedData.dat file we can imitate, Eve, Signed the message with her private key, then Bob won't be able to Verify that with Alice's Public key, as a conclusion he can understand this message was not signed by Alice.




Craftsment, AvGeek, Cyclist