Protect, Track & Control Data.
Anywhere. Anytime.

Get started in JavaScript, Node.js, Python, or C++.

Client-side JS Encryption

After authenticating, you can encrypt a file with just a few lines of code:

<!DOCTYPE html>
<html>
<head>
    <title>Virtru SDK for JavaScript - Sample Application</title>
    <link href="https://sdk.virtru.com/js/latest/auth-widget/index.css" rel="stylesheet"/>
    <script src="https://sdk.virtru.com/js/latest/auth-widget/index.js"></script>
    <script src="https://sdk.virtru.com/js/1.6.11/virtru-sdk.min.js"></script>
</head>

<body>
  <div id="virtru-auth-widget-mount"></div>
  <script type="text/javascript">
    async function afterAuth(email) {
      // Run all client code from here. 
      // This will only be called when the user is successfully authenticated.
      const client = new Virtru.Client({email});
      const yourString = prompt('Type a sting to encrypt: ', 'Hello, world!');
      const encryptParams = new Virtru.EncryptParamsBuilder()
        .withStringSource(yourString)
        .withDisplayFilename('hello.txt')
        .build();
      ct = await client.encrypt(encryptParams);
      await ct.toFile('hello.txt.tdf3.html');
    }
    // Set up the auth widget.
    Virtru.AuthWidget('virtru-auth-widget-mount', {afterAuth});
  </script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
    <title>Virtru SDK for JavaScript - Sample Application</title>
    <link href="https://sdk.virtru.com/js/latest/auth-widget/index.css" rel="stylesheet"/>
    <script src="https://sdk.virtru.com/js/latest/auth-widget/index.js"></script>
    <script src="https://sdk.virtru.com/js/1.6.11/virtru-sdk.min.js"></script>
</head>

<body>
  <div id="virtru-auth-widget-mount"></div>
  <script type="text/javascript">
    async function afterAuth(email) {
      // Run all client code from here. 
      // This will only be called when the user is successfully authenticated.
      const client = new Virtru.Client({email});
      const yourString = prompt('Type a sting to encrypt: ', 'Hello, world!');
      const encryptParams = new Virtru.EncryptParamsBuilder()
        .withStringSource(yourString)
        .withDisplayFilename('hello.txt')
        .withZipFormat()
        .build();
      ct = await client.encrypt(encryptParams);
      await ct.toFile('hello.txt.tdf3');
    }
    // Set up the auth widget.
    Virtru.AuthWidget('virtru-auth-widget-mount', {afterAuth});
  </script>
</body>
</html>

File Formats

An encrypted file could be encoded in one of the two ways:

  • HTML file with .html extension (SDK default)
  • ZIP file with .tdf extension

While both options provide the same level of protection, they have other key differences:

Zip Format
HTML Format

File Size

Any file size

For file sizes less than 100 MB. (Some browsers don't handle files larger than this without significant performance impact.)

User Experience

The recipient of the file can access the file:

  • with any Virtru SDK app that supports decryption
  • by drag and drop the file into Virtru's Secure Reader

The recipient of the file can double click on the file to be redirected to Virtru's Secure Reader to decrypt. This offers the easiest cross-platform user experience for accessing protected data.

Need additional access controls?

Beyond encryption, the Virtru SDK offers access controls like expiration and watermarking.

Encryption Lifecycle

The Virtru SDK does many things behind the scenes for you to encrypt and protect your data.

Protecting a file and sending the policy and key materials to Virtru

Protecting a file and sending the policy and key materials to Virtru

Step 1: First, the client needs an authentication token from Virtru's Entity Attribute Service.

Step 2: Up next, invoking the client.encrypt() encrypts and protects the data into a TDF formatted file. This file stays local to the environment where encryption takes place (browser, end user device or server).

Step 3 and Step 4: The client.encrypt() also pushes the encrypted key material and corresponding policy materials to Virtru Key Management Infrastructure for safe keeping.

Updated 14 days ago


Client-side JS Encryption


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.