Crypt::HSM - A PKCS11 interface for Perl
version 0.004
my $hsm = Crypt::HSM->load('/usr/lib/pkcs11/libsofthsm2.so'); my ($slot) = $hsm->slots; my $session = $hsm->open_session($slot); $session->login('user', '1234'); my ($key) = $session->find_objects({ class => 'secret-key', label => "my-key" }); my $ciphertext = $session->encrypt('aes-gcm', $key, $plaintext, $iv);
This module interfaces with any PKCS11 library to use its cryptography.
This loads the pkcs11 found a $path, and returns it as a new Crypt::HSM object.
This lists the slots of this interface. If $available is true only slots with a token available will be listed.
$available
This returns all mechanisms supported by the token in the slot.
This returns more information about the mechanism. This includes the following fields.
min-key-size
The minimum key size
max-key-size
The maximum key size
flags
This array lists properties of the mechanism. It may contain values like 'encrypt', 'decrypt', 'sign', 'verify', 'generate', 'wrap' and 'unwrap'.
'encrypt'
'decrypt'
'sign'
'verify'
'generate'
'wrap'
'unwrap'
This opens a session to $slot. $flag is an optional array that may currenlt contain the value 'rw-session' to enable writing to the token.
$slot
$flag
'rw-session'
This closes all sessions on $slot.
This returns a hash with information about the HSM.
This returns a hash with information about the slot.
This returns a hash with information about the token in the slot.
This initializes a token on $slot, with the associalted $pin and $label (max 32 characters).
$pin
$label
Leon Timmermans <leont@cpan.org>
This software is copyright (c) 2023 by Leon Timmermans.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Crypt::HSM, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Crypt::HSM
CPAN shell
perl -MCPAN -e shell install Crypt::HSM
For more information on module installation, please visit the detailed CPAN module installation guide.