Sign & Encrypt a message
With the user's Cards in place, we are now ready to encryptEncryption is the process of encoding a message or information in such a way, that only authorized parties can access it more ... a message for encrypted communication. In this case we will encrypt the message using the Recipient's Virgil CardEach Card contains attributes associated with the holder of the Private key and are used to prove the ownership of a Public key more ....
As previously noted we encrypt data for secure communication, but a recipient also must be sure that no third party modified any of the message's content and that they can trust a sender, which is why we provide Data IntegrityGuarantees a receiver that their data has not been altered over its life-cycle more ... by adding a Digital SignatureA Digital Signature can be used with any kind of message, so the receiver can be sure of the sender's identity and that the message arrived intact more .... Therefore we must digitally sign data first and then encrypt.
In order to sign then encrypt messages, the Sender must load their own recently generated Virgil KeyThe Virgil Key is a wrapper of the user's secure Private Key more ... and search for the receiver's Virgil Cards at Virgil Services, where all Virgil Cards are saved.
# load a Virgil Key from device storage
alice_key = virgil.keys.load("[KEY_NAME]", "[OPTIONAL_KEY_PASSWORD]")
# search for Virgil Cards
bob_cards = virgil.cards.find("bob")
# prepare the message
message = "Hey Bob, how's it going?"
# sign and encrypt the message
cipher_text = virgil.sign_then_encrypt(message, [alice_key, bob_cards]).to_string("base64")
To sign a message, you will need to load Alice's Virgil Key. See Loading Key guide for more details.
Now the Receiver can verify that the message was sent by a specific Sender.
With the signature in place, the Sender is now ready to transmit the signed and encrypted message to the Receiver.