2. Using the SafeQuard Solution

2.1. TL;DR

The SafeQuard App Service sets up a file server on Microsoft Azure to host the SafeQuard Module. The SafeQuard Module provides quantum-secure encryption (Kyber ML-KEM-768 + AES-256) functionality for web browsers. The module can be easily integrated into any webpage by importing the SafeQuard.js file and calling its functions directly via JavaScript.

2.2. SafeQuard File Server

2.2.1. Accessing the SafeQuard File Server

The file server is accessed through the SafeQuard App Service. Here are the steps to follow:

  1. Navigate to the SafeQuard App Service on Azure Console.

  2. Move to the Overview page and you will be able to see the Properties tab.

  3. Under the Domain column, click on the URL shown beside Default Domain.

    Note

    Optionally, you can link your own domain/sub-domain to the SafeQuard App Service.

    _images/get_domain_url.png
  4. The URL will open up the file server in your browser, which will look like this:

    _images/safequard_fs.png

2.2.2. Files

These are the files that are deployed as part of the SafeQuard solution. The directory structure of the file server is as follows:

/
├── License
├── SafeQuard.js
└── SafeQuard.wasm
  • The License contains the terms and conditions for using the SafeQuard solution.

  • The SafeQuard.js contains the JavaScript file that handles the logic for SafeQuard.

  • The SafeQuard.wasm the WebAssembly file that powers the core functionality of SafeQuard.

2.2.3. Using the SafeQuard Module

This section explains how to use the SafeQuard_enc() function to encrypt user-provided data.

2.2.3.1. Step 1: Include the SafeQuard Module

First, add the SafeQuard.js file to your webpage by including it in a <script> tag. This will load the module into the browser. Replace https://<SafeQuard-app-service-url> with the actual URL of the file server hosting the SafeQuard.js.

<script src="https://<SafeQuard-app-service-url>/SafeQuard.js"></script>

2.2.3.2. Step 2: Implement Encryption Logic

In your JavaScript code, you can define an asynchronous function, SafeQuard_enc(), to handle encryption. This function accepts input from an HTML element (such as a text input), encrypts the plaintext using the SafeQuard module, and then outputs the encrypted result to a JavaScript object.

The following snippet provides a simple reference on using the encryption function.

<script>
    // Call SafeQuard_enc() when the user clicks the "Encrypt" button.
    async function SafeQuard_enc() {
        // Get input text from HTML element
        let text = document.getElementById("mydata");

        // Call the encryption function pQCee_SafeQuard_enc() with the following arguments:
        // - Internal encryption function: 'pQCee_SafeQuard_enc'
        // - Return type of encryption function: 'string'
        // - Data types of input arguments for plaintext and key: ['string', 'string']
        // - Input text (from the 'mydata' element): text.value
        // - Encryption key: "5dfa..c49b"
        let result = Module.ccall('pQCee_SafeQuard_enc',
                                  'string',
                                  ['string', 'string'],
                                  [text.value, "5dfa..c49b"]);

        document.getElementById("encdata").value = result;  // Set encrypted value in output
    }
</script>

2.3. Example Use Case

<!DOCTYPE html>
<html>
<head>
    <script src="https://<SafeQuard-app-service-url>/SafeQuard.js"></script>
    <script>
        async function SafeQuard_enc() {
            var text = document.getElementById("mydata");
            var result = Module.ccall('pQCee_SafeQuard_enc', 'string', ['string', 'string'], [text.value, "key"]);
            document.getElementById("encdata").value = result;
        }
    </script>
</head>
<body>
    <h1>SafeQuard Encryption Example</h1>
    <textarea id="mydata" placeholder="Enter text to encrypt"></textarea>
    <textarea id="encdata" placeholder="Encrypted data will appear here"></textarea>
    <button onclick="SafeQuard_enc()">Encrypt</button>
</body>
</html>

2.4. Notes

  • The encryption function, pQCee_SafeQuard_enc, currently uses a fixed key (“key”) in this example. This should be replaced with a secure key management approach for real-world applications.

  • Ensure that the SafeQuard module (SafeQuard.js) is loaded before attempting to use the Module.ccall function.