Crypt::DSA::Key(3)

πŸ’– Crypt::DSA::Key β€” the DSA key glow-up πŸ’–

okay bestie, this is a page from the User Contributed Perl Documentation, and it's all about Crypt::DSA::Key, which is literally just... a DSA key. no cap. let's get into it 🫢


✨ NAME ✨

Crypt::DSA::Key β€” a DSA key, fr fr πŸ”‘


🌸 SYNOPSIS 🌸

use Crypt::DSA::Key;
my $key = Crypt::DSA::Key->new;

$key->p($p);

like. that's it. that's the whole vibe check. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

So Crypt::DSA::Key holds a DSA key β€” and not just part of it, bestie, it's got the public portion and the private portion. both. the whole thing. πŸ‘‘

Subclasses of Crypt::DSA::Key are the ones that bring the read and write methods to the party, so you can save your DSA keys to disk and then read them back into your application later. it's giving persistence. it's giving main character energy. πŸ’Ύβœ¨


πŸŽ€ USAGE πŸŽ€

Every single key attribute is reachable through a combo get/set method β€” like, you call the method with an argument to set it, and you call it with nothing to get it back. iconic behaviour honestly.

The key attributes are: p, q, g, priv_key, and pub_key.

For example:

$key->p($p);
my $p2 = $key->p;

see how that works?? first line sets p, second line gets it back. obsessed. 😌


🌈 $key = Crypt::DSA::Key->new(%arg) 🌈

Makes you a brand new (empty) key object. every single attribute starts out at 0. an empty little baby key. πŸ₯Ί

OR β€” plot twist β€” if you hand over the Filename parameter (peep below for the deets), the key gets read in from disk instead. And if you pass the Type parameter (mandatory if you're giving a Filename, okay, don't forget it), heads up: your key doesn't stay a plain Crypt::DSA::Key, it actually gets blessed into a subclass of Crypt::DSA::Key. specifically, it becomes whatever class implements the read functionality for that type, e.g. Crypt::DSA::Key::PEM.

Returns the key when it works, "undef" when it doesn't. (and yes, Password is one whole reason why new might come back with "undef" β€” see below.)

%arg can contain:

  • Type β€” the type of file where the key is stored. rn the only option is PEM, which means a PEM file (optionally encrypted, ASN.1-encoded object). the read/write support for PEM files comes from Convert::PEM, so if you don't have that module installed, the new method will literally die. πŸ’€

This argument is mandatory if you're either reading the file from disk (i.e. you provided a Filename argument) or you've specified the Content argument.

  • Filename β€” where the file lives that you wanna read the key from. needs a Type argument so the decoder knows what kind of file it's looking at. and you can't specify Content and Filename at the same time. pick a lane bestie πŸ™ˆ
  • Content β€” the serialized version of the key. also needs a Type argument so the decoder knows how to decode it. and again: you can't specify Content and Filename at the same time. same rule, no exceptions.
  • Password β€” if your key file is encrypted, you'll need to supply a passphrase to decrypt it, and this is where you do that. πŸ’œ

and if your passphrase is wrong? new will return "undef". that's the one we warned you about earlier. 😭


πŸ’« $key->write(%arg) πŸ’«

Writes a key (optionally) to disk, using whatever format you define with the Type parameter.

Here's the tea: if your $key object has a defined priv_key (that's the private key portion), the key gets written as a DSA private key object. otherwise it gets written out as a public key. and ngl, not every serialization mechanism can produce public keys in this version β€” currently, only PEM public keys are supported. so like. keep that in mind. πŸ”₯

%arg can include:

  • Type β€” the type of file format you wanna write. PEM is one example (and honestly, currently, it's the only example).

This argument is mandatory β€” unless your $key object is already blessed into a subclass (e.g. Crypt::DSA::Key::PEM) and you want to write the file using that same subclass. then you're already set. slay. ✨

  • Filename β€” the location on disk where you want the key file to be written.
  • Password β€” if you want the key file to be encrypted, pass this argument, and the ASN.1-encoded string will be encrypted using the passphrase as a key. πŸ”

🌟 $key->size 🌟

Returns the size of the key, in bits.

technically it's the number of bits in the large prime p. so like, that's the number you're actually getting. iykyk. 🧚


πŸ‘‘ AUTHOR & COPYRIGHTS πŸ‘‘

Please see the Crypt::DSA manpage for author, copyright, and license information. (yeah, they outsourced that part to the parent page β€” go peek over there, bestie 🫢)


and that's the whole page!! mwah πŸ’‹ this doc shipped with perl v5.42.2, dated 2026-07-03 β€” so go forth and handle your DSA keys responsibly, no cap. πŸŒˆπŸ’–

πŸ“¦ where this page comes from