Now you need to register the users who will participate in encrypted communications.
In order to sign and encrypt a message each user must have his own tools, which allow him to perform cryptographic operations, and these tools must contain the necessary information to identify users. In Virgil Security, these tools are the Virgil Key and the Virgil Card.
When we have already set up the Virgil SDK on the server & client sides, we can finally create Virgil Cards for the users and transmit the Cards to your Server for further publication on Virgil Services.
Generate Keys and Create Virgil Card
Use the Virgil SDK on the client side to generate a new Key Pair, and then create a user's Virgil Card using the recently generated Virgil Key. All keys are generated and stored on the client side.
In this example, we will pass on the user's username and a password, which will lock in their private encryption key. Each Virgil Card is signed by a user's Virgil Key, which guarantees the Virgil Card's content integrity over its life cycle.
// generate a new Virgil Key
var aliceKeys = crypto.GenerateKeys();
// save the Virgil Key into the storage
var exportedPrivateKey = crypto.ExportPrivateKey(aliceKeys.PrivateKey, "[KEY_PASSWORD]");
var keyEntry = new KeyEntry
Name = "[KEY_NAME]",
Value = exportedPrivateKey
var keyStorage = new DefaultKeyStorage();
// prepare a request
var exportedPublicKey = crypto.ExportPublicKey(aliceKeys.PublicKey);
var request = new PublishCardRequest("alice", "member", exportedPublicKey);
// sign the request
var requestSigner = new RequestSigner(crypto);
requestSigner.AuthoritySign(request, "[APP_ID]", "[APP_KEY]");
Virgil doesn't keep a copy of your Virgil Key. If you lose a Virgil Key, there is no way to recover it.
In order for the Sender to be able to send a message, we also need a Virgil Card associated with the Recipient. It should be noted that recently created user Virgil Cards will be visible only for application users because they are related to the Application.
Read more about Virgil Cards and their types here.
Transmit the Cards to Your Server
Next, you must serialize and transmit this cards to your server, where you will Approve & Publish Users' Cards.
// export the request to a string
var exportedRequest = request.Export();
// transmit the request to the server
Use the approve & publish users guide to publish users Virgil Cards on Virgil Services.