View on
Benjamin Trott > Crypt-OpenPGP-1.06 > Crypt::OpenPGP::Ciphertext



Annotate this POD


New  12
Open  6
Stalled  1
View/Report Bugs
Source   Latest Release: Crypt-OpenPGP-1.12


Crypt::OpenPGP::Ciphertext - Encrypted data packet


    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 $buffer = Crypt::OpenPGP::Buffer->new;
    my $ct2 = Crypt::OpenPGP::Ciphertext->parse( $buffer );
    my $data = $ct->decrypt( $key_data );


Crypt::OpenPGP::Ciphertext implements symmetrically encrypted data packets, providing both encryption and decryption functionality. Both standard encrypted data packets and encrypted-MDC (modification detection code) packets are supported by this class. In the first case, the encryption used in the packets is a variant on standard CFB mode, and is described in the OpenPGP RFC, in section 12.8 (OpenPGP CFB mode). In the second case (encrypted-MDC packets), the encryption is performed in standard CFB mode, without the special resync used in PGP's CFB.


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:


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).


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.


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

syntax highlighting: