Virgil SDK allows developers to get up and running with Virgil API quickly and add full end-to-end (E2EE) security to their existing digital solutions to become HIPAA and GDPR compliant and more.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Virgil Security Ruby SDK

Build Status Gem GitHub license Documentation YARD

SDK Features | Installation | Initialization | Usage Examples | Docs | Support

Virgil Security provides a set of APIs for adding security to any application. In a few simple steps you can encrypt communication, securely store data, provide passwordless login, and ensure data integrity.

The Virgil SDK allows developers to get up and running with Virgil API quickly and add full end-to-end security to their existing digital solutions to become HIPAA and GDPR compliant and more.

SDK Features


The Virgil SDK is provided as a gem named virgil-sdk and available for Ruby 2.1 and newer. The package is distributed via bundler package manager.

To install the package use the command below:

gem install virgil-sdk

or add the following line to your Gemfile:

gem 'virgil-sdk', '~> 4.4'


Be sure that you have already registered at the Dev Portal and created your application.

To initialize the SDK at the Client Side you need only the Access Token created for a client at Dev Portal. The Access Token helps to authenticate client's requests.


To initialize the SDK at the Server Side you need the application credentials (Access Token, App ID, App Key and App Key Password) you got during Application registration at the Dev Portal.

 # initialize Virgil SDK high-level instance.
context =
    access_token: "[YOUR_ACCESS_TOKEN_HERE]",
    # Credentials are required only to publish and revoke Virgil Cards.
        app_id: "[YOUR_APP_ID_HERE]",
        app_key_data: VirgilBuffer.from_file("[YOUR_APP_KEY_PATH_HERE]"),
        app_key_password: "[YOUR_APP_KEY_PASSWORD_HERE]"))

virgil = context)

Usage Examples

Before starting practicing with the usage examples, make sure that the SDK is configured. Check out our SDK configuration guides for more information.

Generate and publish user's Cards with Public Keys inside on Cards Service

Use the following code to create and publish user's Card with Public Key inside on Virgil Cards Service:

# generate a new Virgil Key
alice_key = virgil.keys.generate()

# save the Virgil Key into a storage"[KEY_NAME]", "[KEY_PASSWORD]")

# create a Virgil Card
alice_card ="alice", alice_key)

# export the Virgil Card to a string
exported_alice_card = alice_card.export

# transmit the Card to your App Server
# import the Virgil Card from the string
alice_card =

# publish the Virgil Card on the Virgil Cards Service

Sign then encrypt data

Virgil SDK allows you to use a user's Private key and his or her Cards to sign, then encrypt any kind of data.

In the following example, we load a Private Key from a customized Key Storage and get recipient's Card from the Virgil Cards Services. Recipient's Card contains a Public Key which we will encrypt the data and verify a signature with.

# load a Virgil Key from a device storage
alice_key = virgil.keys.load("[KEY_NAME]", "[OPTIONAL_KEY_PASSWORD]")

# search for Virgil Cards
bob_cards = await"bob")

# prepare a message
message = "Hey Bob, how's it going?"

# sign then encrypt the message
ciphertext = alice_key.sign_then_encrypt(message, bob_cards).to_base64

Decrypt then verify data

Once the Users have received the signed and encrypted message, they can decrypt it with their own Private Key and verify the signature with Sender's Card:

# load a Virgil Key from a device storage
bob_key = virgil.keys.load("[KEY_NAME]", "[OPTIONAL_KEY_PASSWORD]")

# get a sender's Virgil Card
alice_card ="[ALICE_CARD_ID]")

# decrypt the message
original_message = bob_key.decrypt_then_verify(ciphertext, alice_card).to_s


Virgil Security has a powerful set of APIs, and the documentation below can get you started today.

In order to use the Virgil SDK with your application, you will need to configure your application first. By default, the SDK will attempt to look for Virgil-specific settings in your application but you can change it during SDK configuration.


This library is released under the 3-clause BSD License.


Our developer support team is here to help you. Find out more information on our Help Center.

You can find us on Twitter or send us email

Also, get extra help from our support team on Slack.