Author image Salvador Fandiño García
and 1 contributors

NAME

Win32::SecretFile - Save secret data into files with restricted accessibility

SYNOPSIS

  use Win32::SecretFile qw(create_secret_file)
  my $short = create_secret_file($path, $path, short_path => 1);
  system $cmd, "-pwdpath=$short";
  unlink $short;

DESCRIPTION

Sometimes you need to pass secret data to some other process through the filesystem. This module allows you to create a file with a quite restricted set of access permissions and save some data inside.

The module exports the following function:

$path = create_secret_file($filename, $data, %opts)

Creates at the given position $filename a file which only the current user has permissions to access and saves the contents of $data inside.

The function returns the final absolute file path. In case of failure it returns undef ($^E can be inspected then to discover the cause of failure).

The following optional arguments are accepted:

local_appdata => $bool

When given a true value, the filename is taken relative to the user's local application data directory (usually, something like C:\\Documents and Settings\\Rolf\\Local Configuration\\Program Data).

Defaults to false.

make_path => $bool

The function creates any non-existent directories on the target path. Defaults to true.

overwrite => $bool

If a file with the same name already exists it is overwritten. Defaults to true.

unique => $bool

Appends a pseudo-random string into the filename until it finds an unoccupied path. Defaults to false.

short_path => $bool

Returns the short form of the final path.

hidden => $bool

Sets the hidden attribute on the created file. Defaults to true.

temporary => $bool

Sets the temporary attribute on the created file. Defaults to true.

encrypted => $bool

Sets the encrypted attributed on the created file. Defaults to false.

SEE ALSO

This module was a spin-off of Net::SSH::Any where it is used to pass passwords to slave commands.

The thread in Perlmonks where it was discussed: http://perlmonks.org/?node_id=1110748

See also the MSDN documentation for CreateFile for further information about the hidden, temporary and encrypted flags.

COPYRIGHT AND LICENSE

Copyright (C) 2014-2015 by Salvador Fandiño <sfandino@yahoo.com> Copyright (C) 2014 by BrowserUk

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.21.7 or, at your option, any later version of Perl 5 you may have available.