# Veracrypt

<figure><img src="/files/ZjCdbwp845QIOsMjDuTZ" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
This tutorial requires one device of any in the following categories:

* [x] [YubiKey 5 Series](https://www.yubico.com/store/#yubikey-5-series)
* [x] [YubiKey 5 FIPs Series](https://www.yubico.com/store/#yubikey-5-fips-series)
  {% endhint %}

##

## <mark style="color:red;">❊ How It Works</mark>

To have your Yubikey unlock your Veracrypt drive, you will need to have your Yubikey plugged into your computer with a keyfile imported into a particular PIV slot.

When creating a new encrypted drive, you will need to generate a keyfile that you will use to unlock your drive. Then you will need to import that keyfile onto your Yubikey. Every time you attempt to mount your encrypted drive, you will choose the **keyfile** option and then select your Yubikey as an authentication method. Veracrypt will then read your Yubikey's imported keyfile, match that with what is stored on the system and then unlock your drive.

If you have an existing drive, you can add Yubikey as an additional security measure.

Along with having this imported keyfile on your Yubikey, you should also save that keyfile somewhere else. A USB flash drive is recommended. If your Yubikey stops working, you will need that backup keyfile in order to unlock your drive.

## <mark style="color:red;">❊ Installation</mark>

Before starting, download and install ![](/files/cx3UyzbMaa2qyyOJ3lWy) [**VeraCrypt**](https://www.veracrypt.fr/en/Downloads.html).

Software is available for **Windows**, **MacOS**, and **Linux**.

{% hint style="danger" %} <mark style="color:red;">**Veracrypt Portable Warning (Windows)**</mark>

The **Windows** version includes a link to a portable download. This is a version of Veracrypt that can run on your computer without needing to be installed. It allows you to place the program on a flash drive and open it on any computer.

<mark style="color:orange;">**The portable version of Veracrypt does NOT support Yubikeys.**</mark>

You **must** download and install the full version of Veracrypt for Windows.
{% endhint %}

## <mark style="color:red;">❊ Creating a Keyfile</mark>

Launch Veracrypt.

Locate the <mark style="color:red;">**Tools**</mark> menu at the top and select <mark style="color:red;">**KeyFile Generator**</mark>.

<figure><img src="/files/DZtBAciuI9bAxeKhjITF" alt=""><figcaption></figcaption></figure>

You will notice a progress bar at the very bottom will start red and slowly progress to green as the bar fills.

To fill this bar, move your mouse back and forth.

<figure><img src="/files/ZKzKinNYfKDeGuGP61Lp" alt=""><figcaption></figcaption></figure>

For a Yubikey device, you must keep the <mark style="color:orange;">**Keyfile Size**</mark> at <mark style="color:red;">**64 bytes**</mark>.

You can leave <mark style="color:orange;">**Mixing PRF**</mark> at <mark style="color:red;">**SHA-512**</mark>.

Towrad the bottom, type a name for your keyfile in the field <mark style="color:red;">**Keyfiles Base Name**</mark>.

<figure><img src="/files/5ijvZSzDeIYY4rf2pJyE" alt=""><figcaption></figcaption></figure>

Click <mark style="color:red;">**Generate and Save Keyfile ...**</mark>

A dialog box will appear and ask you to select the folder you want to save the keyfile in. Select any folder.  After you complete that step, you should get a save notification:

<figure><img src="/files/mOeoONoqa6cq4MmdHDal" alt=""><figcaption></figcaption></figure>

Use a program like <mark style="color:red;">**Windows File Manager**</mark> and go to the folder where you saved your keyfile and confirm that it is there.

<figure><img src="/files/n1hooPeLRFsTHIGHPltE" alt=""><figcaption></figcaption></figure>

Once located, continue to the ![](/files/cx3UyzbMaa2qyyOJ3lWy) [**Import Keyfile to Yubikey**](#import-keyfile-to-yubikey) section.

## <mark style="color:red;">❊ Installing OpenSC</mark>

Veracrypt itself does not directly support reading a Yubikey and needs some help thanks to a third-party program called [**OpenSC**](https://github.com/OpenSC/OpenSC#downloads).

OpenSC will be the "bridge" for communication between Veracrypt and your Yubikey.

Download the latest version of OpenSC, ![](/files/cx3UyzbMaa2qyyOJ3lWy) [**visit the Github page's Downloads section here.**](https://github.com/OpenSC/OpenSC#downloads)

Install the program. It will set itself up and run in the background while your computer is on.

If installing on Windows, you may be greeted with this lovely screen:

<figure><img src="/files/iZGFFNISNBS3oxjJvdO7" alt=""><figcaption></figcaption></figure>

Fear not, as it isn't a virus. Simply click **More Info** and select ![](/files/bdciZ0cMfLGaClemfm4U)

Begin installation:

<figure><img src="/files/KiVdiERCzLy0Ht8GEJzA" alt=""><figcaption></figcaption></figure>

Continue to click **Next** until you get to a screen which lists features available for install:

<figure><img src="/files/Ijh8wKgKEaorL63vWBAH" alt=""><figcaption></figcaption></figure>

Select the following:

* Core components
* PKCS#11 module
* Smartcard Minidriver
* Command line tools

Other options are optional -- select if desired.

Let OpenSC finish installation:

<figure><img src="/files/D3AcMWd3SVDE9JCLrwXt" alt=""><figcaption></figcaption></figure>

Once you have installed OpenSC, you can give your computer a reboot and OpenSC should run at startup.

If you don't want to wait on reboot, you can manually start OpenSC by executing the file:

<mark style="color:red;">**`C:\Program Files\OpenSC Project\OpenSC\tools\opensc-notify.exe`**</mark>

Re-launch veracrypt and in the top menu, select **Tools** -> **Management Security Token Keyfiles**

<figure><img src="/files/ZzG3OJXiPZxdco9oejBu" alt=""><figcaption></figcaption></figure>

You will get a notification for some steps that need performed:

<figure><img src="/files/jESyS6ElHOQOCx7cwn4X" alt=""><figcaption></figcaption></figure>

Open the top menu back up, and select **Settings** -> **Security Tokens**.

<figure><img src="/files/8x2Rv4HRuJOGXOckeYG3" alt=""><figcaption></figcaption></figure>

You will need to provide the path to your Yubikey's PKCS#11 library.

The **Auto-Detect** button will sometimes work, if it doesn't and you receive an error that it cannot locate your module, you'll need to specify it manually.

Click the **Select Library** button, and navigate to:

<mark style="color:red;">**`C:\Program Files\OpenSC Project\OpenSC\pkcs11\opensc-pkcs11.dll`**</mark>

After you've selected the PKCS#11 module, save, and close Veracrypt completely.

Re-launch and you should be able to navigate to **Tools** -> **Management Security Token Keyfiles** and a dialog box should appear asking for your smartcard PIV PIN.

If you see nothing in the list, completely close Veracrypt and then remove your Yubikey from the USB port. Wait a few seconds, and then plug your Yubikey back in. Then launch Veracrypt and go back to **Tools** -> **Management Security Token Keyfiles**.

## <mark style="color:red;">❊ Import Keyfile to Yubikey</mark>

If you've read my other guides, you will know that the PIV module has four main slots. Slot 9A, 9C, 9D, and 9E. We will **not** be using those slots for this key. Your generated keyfile will need to be imported into a special PIV slot.&#x20;

We will use the command-line ![](/files/cx3UyzbMaa2qyyOJ3lWy) [**ykman** ](/yubikey5/guides/setting-up-cli-ykman.md)to do that.

The special slots being referred to, are the three slots that Veracrypt allows you to select when you connect your Yubikey and unlock or create a drive.

To view these slots, return to Veracrypt.

Select <mark style="color:red;">**Tools**</mark> -> <mark style="color:red;">**Manage Security Token Keyfiles...**</mark>

<figure><img src="/files/txqU1sS7VnNKpopjWHur" alt=""><figcaption></figcaption></figure>

A dialog box will appear and ask you for a PIV PIN:

<figure><img src="/files/OsuVtLwrJQ4mshZQOwyh" alt=""><figcaption></figcaption></figure>

Enter the PIV PIN you have configured for your Yubikey.

If you have not changed the default PIV PIN yet, enter: <mark style="color:blue;">**`123456`**</mark>

{% hint style="info" %}
To learn how to configure PIV and make PINs, visit the ![](/files/cx3UyzbMaa2qyyOJ3lWy) [PIV documentation](/yubikey5/piv-1/getting-started/2.-pins.md).
{% endhint %}

Press OK and a new dialog will appear and show the three special files in slot 0 referred to earlier:

<figure><img src="/files/5ofC7OHK2NtIs99xfIEa" alt=""><figcaption></figcaption></figure>

For this guide, we are going to import our generated keyfile into the PIV object / slot <mark style="color:red;">**Printed Information**</mark>**.**

### <mark style="color:blue;">SLOT / OBJECT IDS</mark>

The slot / object ID for these three slots are provided below:

| File Name                                                   | Slot / Object ID |
| ----------------------------------------------------------- | ---------------- |
| <mark style="color:red;">**Cardholder Fingerprints**</mark> | 0x5fc103         |
| <mark style="color:red;">**Printed Information**</mark>     | 0x5fc109         |
| <mark style="color:red;">**Cardholder Facial Image**</mark> | 0x5fc108         |

You will need to enter the **slot / object id** in a few moments.

Open your Command Prompt, Terminal, or Powershell.

Change directores to the folder which has <mark style="color:red;">**ykman.exe**</mark>:

```
cd "C:\Program Files\Yubico\YubiKey Manager\"
```

{% hint style="info" %}
If you are unsure where <mark style="color:red;">**Yubikey Manager**</mark> or <mark style="color:red;">**ykman.exe**</mark> are installed, ![](/files/cx3UyzbMaa2qyyOJ3lWy) [**view the documentation for ykman here**](/yubikey5/guides/setting-up-cli-ykman.md).&#x20;

That section will explain what ykman is, and how to download it for your operating system. It is included in your installation of Yubikey Manager.
{% endhint %}

Once you have navigated to the Yubikey Manager folder, change the information in the command below and then execute it:

<pre><code><strong>ykman piv objects import 0x5fc109 "C:\path\to\mykeyfile"
</strong></code></pre>

<table><thead><tr><th width="268">Argument</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:red;"><strong>0x5fc109</strong></mark></td><td>Slot for <mark style="color:red;"><strong>Personal Information</strong></mark> which was explained above. (See chart above)</td></tr><tr><td><mark style="color:red;"><strong>C:\Path\Keyfile\mykeyfile</strong></mark></td><td>The path and name of keyfile you created.</td></tr></tbody></table>

{% hint style="info" %}
Wrap the path to your keyfile in quotations, especially if the path to the file contains spaces in the folder / file names.
{% endhint %}

Execute the command; you will see the following message:

```
Enter a management key [blank to use default key]:
```

Type the <mark style="color:red;">**PIV Management**</mark> <mark style="color:red;">**Key**</mark> you've specified for your Yubikey's PIV interface. Press ENTER if you've never changed the default pre-programmed management key.

{% hint style="info" %}
Default Management Key:\ <mark style="color:red;">**`010203040506070801020304050607080102030405060708`**</mark>

If you're unsure how to change your <mark style="color:red;">**PIV Management Key**</mark>, view ![](/files/cx3UyzbMaa2qyyOJ3lWy) [**PIV documentation here**](/yubikey5/piv-1/getting-started/2.-pins.md#management-key-1).
{% endhint %}

## <mark style="color:red;">❊ Linking Yubikey to Drive</mark>

Once you have imported your keyfile onto your Yubikey, it's time to tell your encrypted drive where it's at.

Launch Veracrypt. You can either create a new encrypted drive, or edit an existing drive to accept a yubikey. The steps are almost identical.

For this tutorial; we'll explain both:

### <mark style="color:blue;">EXISTING DRIVE</mark>

<figure><img src="/files/rBlqC1pnbnt3WVjh3bkJ" alt=""><figcaption></figcaption></figure>

Select a drive letter assign to your encrypted drive, and click **Select File** to open the drive file you saved when you first made the encrypted drive.&#x20;

Next, click ![](/files/sr9bOfB9Nlt6141lcJzW) and select <mark style="color:yellow;">**Add/Remove keyfiles To/From Volume**</mark>.

<figure><img src="/files/B0Rl3F3BUdzVFhqnWiq9" alt=""><figcaption></figcaption></figure>

A dialog box will open.

<figure><img src="/files/psEyfao6Q6ozhDiHpsWM" alt=""><figcaption></figcaption></figure>

In the section labeled <mark style="color:yellow;">**Current**</mark>, fill in the credentials for how you normally unlock the encrypted drive. In our example, I enter the Password and a custom PIM.

<figure><img src="/files/QhPoUSN5aWTrzLkwqz38" alt=""><figcaption></figcaption></figure>

In the section labeled <mark style="color:yellow;">**New**</mark>, select ![](/files/vlHaMMw0C6CYpUYi0bDc) and press ![](/files/wE1OXOZciAGP2SN0f9YH).

<figure><img src="/files/dxwQjdWdhN4AR9w95Tti" alt=""><figcaption></figcaption></figure>

On the new dialog, press ![](/files/UHYInoZh9WK7nlXd6ECg)

A dialog will appear:

<figure><img src="/files/tR4b4nOIwqcKJ0AVPXG3" alt=""><figcaption></figcaption></figure>

This is the dialog associated to your Yubikey. You will need to enter your **PIV ADMIN PIN**.\
default: <mark style="color:red;">**`12345678`**</mark>

{% hint style="danger" %}
If you do not see a dialog asking for you to enter a PIN, perform the following steps:
{% endhint %}

* At the top of Veracrypt, select <mark style="color:yellow;">**TOOLS**</mark> -> <mark style="color:yellow;">**Close all Security Token Sessions**</mark>.
* Completely close Veracrypt, ensure it's not sitting in your Windows taskbar near your clock.
* Next to your taskbar clock, hover over the icons and check for a running program called <mark style="color:yellow;">**OpenSC**</mark>.
  * If you do not see OpenSC, find and launch the program <mark style="color:yellow;">**`C:\Program Files\OpenSC Project\OpenSC\tools\opensc-notify.exe`**</mark>
  * If you do see OpenSC near your clock, right click and select Exit / Close.
* Unplug your Yubikey, wait 5 seconds, and plug back in.&#x20;
* A notification should appear:

<figure><img src="/files/lXLKPGobg4YPHGA9rNne" alt=""><figcaption></figcaption></figure>

* Re-launch Veracrypt, select your encrypted drive, click ![](/files/DApitAZ3fkKAz9prWAhF), select <mark style="color:yellow;">**Add/Remove keyfiles To/From Volume**</mark>, and then fill in your drive credentials again.

You should see a Yubikey PIV PIN dialog box:

<figure><img src="/files/4Vfk6lL7QIOy7rJ3ZhlG" alt=""><figcaption><p>default pin: 12345678</p></figcaption></figure>

#### <mark style="color:purple;">Continued Issues?</mark>

{% hint style="danger" %}
If you continue at this point to either not get the PIN dialog box, or your list is empty for the **Select Security Token Keyfiles** box, read the ![](/files/cx3UyzbMaa2qyyOJ3lWy) [**Notes**](#notes) section and then return here when you get it working.
{% endhint %}

Once you enter your PIN, a dialog should appear with a list of files on your Yubikey:

<figure><img src="/files/k0wXBFAKvycn7zIMkL4m" alt=""><figcaption></figcaption></figure>

Select the file name <mark style="color:yellow;">**Printed Information**</mark>, which is the object we imported our keyfile onto earlier. This file is slot / object <mark style="color:red;">**0x5fc109**</mark> which came from the ![](/files/cx3UyzbMaa2qyyOJ3lWy) [**Object ID chart**](#slot-object-ids).

{% hint style="info" %}
Important Info

Prior to writing this guide, I attempted to write a keyfile to <mark style="color:blue;">**Cardholder Fingerprints**</mark> and <mark style="color:blue;">**Cardholder Facial Image**</mark>**.**

Importing to those two slots appeared to have no effect. I could unlock the drive with any Yubikey that I inserted, even if I hadn't imported the new keyfile yet.\
\
Some people have claimed success using the other two slots, but I had no such luck. Try at your own risk.
{% endhint %}

Once you select the <mark style="color:yellow;">**Printed Information**</mark> slot, press ![](/files/IlKCP1F7dxeOKXYa8mAo), the list on the previous page should now be populated with your selected object / file.

<figure><img src="/files/ajpX6INXbpwXWK4RsTNc" alt=""><figcaption></figcaption></figure>

Press ![](/files/IlKCP1F7dxeOKXYa8mAo) and go back to the first dialog where you filled in the information.

<figure><img src="/files/LxscyqU1neC8ldnuiXea" alt=""><figcaption></figcaption></figure>

Press ![](/files/IlKCP1F7dxeOKXYa8mAo), Veracrypt will start the process of adding the keyfile.

<figure><img src="/files/seDXccp9n1efvjOryOnR" alt=""><figcaption></figcaption></figure>

Eventually Veracrypt will show a dialog which makes you move your mouse cursor. Move your mouse until the bar is completely filled to the right.

<figure><img src="/files/Ng7bkZpLYMYUoB4WVHGZ" alt=""><figcaption></figcaption></figure>

Veracrypt should confirm the changes to your drive:

<figure><img src="/files/hbKKBtgD04fjVcXCoyfc" alt=""><figcaption></figcaption></figure>

From now on, every time you mount that drive, you will need to select ![](/files/762IP08ZG2o5hFHllhEN) and select your keys with the ![](/files/Fa5ekOQdyv1E32S13CX2) button.

This process is very similar for creating a new encrypted drive.

### <mark style="color:blue;">NEW DRIVE</mark>

For a new drive, you will follow the normal steps of creating a drive. However, the interface will look slightly different when it comes time to add your keyfiles from your Yubikey:

<figure><img src="/files/2okHRJcmLSn97bn8kOWC" alt=""><figcaption></figcaption></figure>

On the dialog box above, select a password, a modified PIM, and then checkmark ![](/files/762IP08ZG2o5hFHllhEN).&#x20;

Then click the ![](/files/g21pFXAn0sgdfGmwVUWM) -> ![](/files/BPVV4VmayOukhkQVhTh5).

You'll then be prompted for your Yubikey's PIV ADMIN PIN:

<figure><img src="/files/3zxitYP8QeZbxgqXhU4t" alt=""><figcaption><p>Default ADMIN PIN: 12345678</p></figcaption></figure>

Select the file <mark style="color:yellow;">**Printed Information**</mark> from your Yubikey slot:

<figure><img src="/files/9WA3MKMLJIcyo98aEKjr" alt=""><figcaption></figcaption></figure>

Click ![](/files/VqAnKI6MgGGZlGuzZ7HA) and confirm your selected file appears in the list:

<figure><img src="/files/VbeWiyqW68jszvOJSMDe" alt=""><figcaption></figcaption></figure>

Press ![](/files/VqAnKI6MgGGZlGuzZ7HA) once more until you're back on the page where you provide a password and PIM.

Proceed forward with the normal steps to create an encrypted drive.

## <mark style="color:red;">❊ Notes</mark>

It is possible to utilize a Yubikey with Veracrypt (I do it every day), it's just an extremely touchy system.

Sometimes when you attempt to load your Yubikey, you'll receive errors that it cannot see your Yubikey at all. Or the list which is supposed to show your three Yubikey files / slots will not populate.

On occasion, I also received this error:

<figure><img src="/files/oL5fjjDQKvOsmPBZbaTZ" alt=""><figcaption><p>A dumb error</p></figcaption></figure>

If you are having these issues, it's a game of "trial-and-error", which means:

* Unplug Yubikey from USB port.
* Click <mark style="color:red;">**TOOLS**</mark> -> ![](/files/NVI4nzUzjWD59dpz1O7K)
* Completely close Veracrypt *(ensure it's not sitting as an icon near your clock or tray)*.
* Check near your clock for OpenSC, which should be the icon ![](/files/j2A7dvNjrPFEtVVb9c3x)
* Completely close OpenSC by right-clicking it near the clock tray and selecting **Exit**.
* Re-launch OpenSC by running the program <mark style="color:yellow;">**`C:\Program Files\OpenSC Project\OpenSC\tools\opensc-notify.exe`**</mark>
* Plug your Yubikey back in.
* Double check that you did indeed import the keyfile to the PIV slot.
  * This means following the instructions for ![](/files/cx3UyzbMaa2qyyOJ3lWy) [**Import Keyfile to Yubikey**](#import-keyfile-to-yubikey) again.
* Make sure you don't have programs like Gpg Kleopatra running near your clock or in your taskbar. This program takes priority and will stop PIV from functioning for any other program.
* And continue doing these steps until you get a response.

![](/files/cx3UyzbMaa2qyyOJ3lWy) [**If you came here from the warning box above, click here to return.**](#continued-issues)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://yubico.gitbook.io/yubikey5/tutorials/veracrypt.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
