Crypt::DSA::Key - DSA key
use Crypt::DSA::Key; my $key = Crypt::DSA::Key->new;
$key->p($p);
Crypt::DSA::Key contains a DSA key, both the public and private portions. Subclasses of Crypt::DSA::Key implement read and write methods, such that you can store DSA keys on disk, and read them back into your application.
Any of the key attributes can be accessed through combination get/set methods. The key attributes are: p, q, g, priv_key, and pub_key. For example:
$key->p($p); my $p2 = $key->p;
Creates a new (empty) key object. All of the attributes are initialized to 0.
Alternately, if you provide the Filename parameter (see below), the key will be read in from disk. If you provide the Type parameter (mandatory if Filename is provided), be aware that your key will actually be blessed into a subclass of Crypt::DSA::Key. Specifically, it will be the class implementing the specific read functionality for that type, eg. Crypt::DSA::Key::PEM.
Returns the key on success, undef
otherwise. (See Password
for one reason why new might return undef
).
%arg can contain:
The type of file where the key is stored. Currently the only option is PEM, which indicates a PEM file (optionally encrypted, ASN.1-encoded object). Support for reading/writing PEM files comes from Convert::PEM; if you don't have this module installed, the new method will die.
This argument is mandatory, if you're reading the file from disk (ie. you provide a Filename argument).
The location of the file from which you'd like to read the key.
If you're reading a key in from disk, this argument is (obviously) mandatory. In fact, the presence of this argument is how new determines whether or not to read a key from disk.
If your key file is encrypted, you'll need to supply a passphrase to decrypt it. You can do that here.
If your passphrase is incorrect, new will return undef
.
Writes a key (optionally) to disk, using a format that you define with the Type parameter.
%arg can include:
The type of file format that you wish to write. PEM is one example (in fact, currently, it's the only example).
This argument is mandatory, unless your $key object is already blessed into a subclass (eg. Crypt::DSA::Key::PEM), and you wish to write the file using the same subclass.
Returns the size of the key, in bits. This is actually the number of bits in the large prime p.
Please see the Crypt::DSA manpage for author, copyright, and license information.