Creating a File-based key

Created on 13 May 2020, over 5 years ago
Updated 6 May 2025, 6 months ago

I had a need to implement 'webform_encrypt' for one of my webforms. Webform_encrypt begets Encrypt which begets Key. While trying to create an Encryption-type key, I had a heck of a time figuring out how to build a File for use with the Key module; nor was I able to find an example of someone building a key file for use with the Key module. Eventually I found this issue, where rlhawk β†’ provides the following command to create a random, 32-byte, Base64-encoded, string:

dd if=/dev/urandom bs=32 count=1 | base64 -i -

Put the result of that command into your key file. Then, when creating the Key (in the module), point a 256-bit-sized, encryption-type key at the file and, viola!, you have a 256-bit encryption key for use in your Drupal 8 environment!

If there is a better way to document this process, please let me know.

πŸ“Œ Task
Status

Fixed

Version

1.0

Component

Documentation

Created by

πŸ‡ΊπŸ‡ΈUnited States jrwest_webguy

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡³πŸ‡±Netherlands koosvdkolk

    For me the GUI was still puzzling.

    Previously I created a key with 'Configuration' as 'Key provider' and I had to enter a 'Key value' and the whole thing was stored in the database. For my current use case I wanted to use the 'File' key provider option, and I expected the module to behave the same.

    1. I press the 'Add key' button on admin/config/system/keys
    2. The form header says 'Add key'
    3. I select 'File' under 'Key provider' and fill out a path.
    4. As I am adding I key, my expectation is: The module will create a key file for me at 'File location' and store a key there.
    5. Upon saving, I receive a message that the file does not exist. Maybe a permission thing?
    6. I manually add an empty .key file at the location and re-save the form.
    7. I get a green message saying that I was successful
    8. In a (rare) moment of clarity, I decide to inspect the key file and find it to be... empty.
    9. I start Googling and end up here.

    Suggestion for improvement:

    1. Change "The location of the file in which the key will be stored." ('File location' field description') into something like "The location of the key file. For more information on generating a key file, see https://www.drupal.org/project/key β†’ "
Production build 0.71.5 2024