Signing ✍ and Verifying ✅ Asymmetric Encryption Decryption with RSA Implementation
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.
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.
The overall design can show in this way
mainly it will contain the following methods.
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)
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)
In order to make this solution work, there is a flow to run this application
- Run Bob Console App to generate Bob’s public/private key pair
2. Run Alice Console App to Encrypt and Sign the Alice message
3. Run Bob Console App to Decrypt and Verify Alice message
We can test this actually working by changing some data in the encryptedSignedData.dat file
Now we run again Bob program
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.