The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Crypt::OpenPGP::Ciphertext - Encrypted data packet

SYNOPSIS

    use Crypt::OpenPGP::Ciphertext;

    my $key_data = 'f' x 64;    ## Not a very good key :)

    my $ct = Crypt::OpenPGP::Ciphertext->new(
                              Data   => "foo bar baz",
                              SymKey => $key_data,
                    );
    my $serialized = $ct->save;

    my $ct = Crypt::OpenPGP::Ciphertext->parse($buffer);
    my $data = $ct->decrypt($key_data);

DESCRIPTION

Crypt::OpenPGP::Ciphertext implements symmetrically encrypted data packets, providing both encryption and decryption functionality. The encryption used in these packets is described in the OpenPGP RFC, in section 12.8 (OpenPGP CFB mode). It is a variant in standard CFB, and it differs slightly from the CFB used to encrypt secret key data.

USAGE

Crypt::OpenPGP::Ciphertext->new( %arg )

Creates a new symmetrically encrypted data packet object and returns that object. If there are no arguments in %arg, the object is created with an empty data container; this is used, for example, in parse (below), to create an empty packet which is then filled from the data in the buffer.

If you wish to initialize a non-empty object, %arg can contain:

  • Data

    A block of octets that make up the plaintext data to be encrypted.

    This argument is required (for a non-empty object).

  • SymKey

    The symmetric cipher key: a string of octets that make up the key data of the symmetric cipher key. This should be at least long enough for the key length of your chosen cipher (see Cipher, below), or, if you have not specified a cipher, at least 64 bytes (to allow for long cipher key sizes).

    This argument is required (for a non-empty object).

  • Cipher

    The name (or ID) of a supported PGP cipher. See Crypt::OpenPGP::Cipher for a list of valid cipher names.

    This argument is optional; by default Crypt::OpenPGP::Cipher will use DES3.

$ct->save

Returns the block of ciphertext created in new (assuming that you created a non-empty packet by specifying some data; otherwise returns an empty string).

Crypt::OpenPGP::Ciphertext->parse($buffer)

Given $buffer, a Crypt::OpenPGP::Buffer object holding (or with offset pointing to) a symmetrically encrypted data packet, returns a new Crypt::OpenPGP::Ciphertext object, initialized with the ciphertext in the buffer.

$ct->decrypt($key, $alg)

Decrypts the ciphertext in the Crypt::OpenPGP::Ciphertext object and returns the plaintext. $key is the encryption key, and $alg is the name (or ID) of the Crypt::OpenPGP::Cipher type used to encrypt the message. Obviously you can't just guess at these parameters; this method (along with parse, above) is best used along with the Crypt::OpenPGP::SessionKey object, which holds an encrypted version of the key and cipher algorithm.

AUTHOR & COPYRIGHTS

Please see the Crypt::OpenPGP manpage for author, copyright, and license information.