DOKK / manpages / debian 12 / libfile-kdbx-perl / File::KDBX::Key::File.3pm.en
File::KDBX::Key::File(3pm) User Contributed Perl Documentation File::KDBX::Key::File(3pm)

File::KDBX::Key::File - A file key

version 0.906

    use File::KDBX::Constants qw(:key_file);
    use File::KDBX::Key::File;
    ### Create a key file:
    my $key = File::KDBX::Key::File->new(
        filepath    => 'path/to/file.keyx',
        type        => KEY_FILE_TYPE_XML,   # optional
        version     => 2,                   # optional
        raw_key     => $raw_key,            # optional - leave undefined to generate a random key
    );
    $key->save;
    ### Use a key file:
    my $key2 = File::KDBX::Key::File->new('path/to/file.keyx');
    # OR
    my $key2 = File::KDBX::Key::File->new(\$secret);
    # OR
    my $key2 = File::KDBX::Key::File->new($fh); # or *IO

A file key (or "key file") is the type of key where the secret is a file. The secret is either the file contents or is generated based on the file contents. In order to lock and unlock a KDBX database with a key file, the same file must be presented. The database cannot be opened without the file.

Inherets methods and attributes from File::KDBX::Key.

There are multiple types of key files supported. See "type". This module can read and write key files.

    $type = $key->type;

Get the type of key file. Can be one of from ":key_file" in File::KDBX::Constants:

  • "KEY_FILE_TYPE_BINARY"
  • "KEY_FILE_TYPE_HEX"
  • "KEY_FILE_TYPE_XML"
  • "KEY_FILE_TYPE_HASHED"

    $version = $key->version;

Get the file version. Only applies to XML key files.

    $filepath = $key->filepath;

Get the filepath to the key file, if known.

    $key = $key->load($filepath);
    $key = $key->load(\$string);
    $key = $key->load($fh);
    $key = $key->load(*IO);

Load a key file.

    $key->reload;

Re-read the key file, if possible, and update the raw key if the key changed.

    $key->save;
    $key->save(%options);

Write a key file. Available options:

  • "type" - Type of key file (default: value of "type", or "KEY_FILE_TYPE_XML")
  • "verson" - Version of key file (default: value of "version", or 2)
  • "filepath" - Where to save the file (default: value of "filepath")
  • "fh" - IO handle to write to (overrides "filepath", one of which must be defined)
  • "raw_key" - Raw key (default: value of "raw_key")
  • "atomic" - Write to the filepath atomically (default: true)

Please report any bugs or feature requests on the bugtracker website <https://github.com/chazmcgarvey/File-KDBX/issues>

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

Charles McGarvey <ccm@cpan.org>

This software is copyright (c) 2022 by Charles McGarvey.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

2022-11-20 perl v5.36.0