|
3 | 3 |
|
4 | 4 | SYNOPSIS
|
5 | 5 | my $pgp = Crypt::OpenPGP->new;
|
| 6 | + |
| 7 | + # Given an input stream (could be a signature, ciphertext, etc), |
| 8 | + # do the "right thing" to it. |
| 9 | + my $message_body; $message_body .= $_ while <STDIN>; |
6 | 10 | my $result = $pgp->handle( Data => $message_body );
|
7 | 11 |
|
| 12 | + # Create a detached, ASCII-armoured signature of $file using the |
| 13 | + # secret key $key_id, protected with the passphrase $pass. |
| 14 | + my $file = 'really-from-me.txt'; |
| 15 | + my $key_id = '...'; |
| 16 | + my $pass = 'foo bar'; |
8 | 17 | my $signature = $pgp->sign(
|
9 |
| - Filename => $file, |
10 |
| - KeyID => $key_id, |
11 |
| - Passphrase => $pass, |
12 |
| - Detach => 1, |
13 |
| - Armour => 1, |
14 |
| - ); |
15 |
| - |
16 |
| - my $valid = $pgp->verify( |
17 |
| - Signature => $signature, |
18 |
| - Files => [ $file ], |
19 |
| - ); |
20 |
| - |
| 18 | + Filename => $file, |
| 19 | + KeyID => $key_id, |
| 20 | + Passphrase => $pass, |
| 21 | + Detach => 1, |
| 22 | + Armour => 1, |
| 23 | + ); |
| 24 | + |
| 25 | + # Verify the detached signature $signature, which should be of the |
| 26 | + # source file $file. |
| 27 | + my $is_valid = $pgp->verify( |
| 28 | + Signature => $signature, |
| 29 | + Files => [ $file ], |
| 30 | + ); |
| 31 | + |
| 32 | + # Using the public key associated with $key_id, encrypt the contents |
| 33 | + # of the file $file, and ASCII-armour the ciphertext. |
21 | 34 | my $ciphertext = $pgp->encrypt(
|
22 |
| - Filename => $file, |
23 |
| - Recipients => $key_id, |
24 |
| - Armour => 1, |
25 |
| - ); |
| 35 | + Filename => $file, |
| 36 | + Recipients => $key_id, |
| 37 | + Armour => 1, |
| 38 | + ); |
26 | 39 |
|
| 40 | + # Decrypt $ciphertext using the secret key used to encrypt it, |
| 41 | + # which key is protected with the passphrase $pass. |
27 | 42 | my $plaintext = $pgp->decrypt(
|
28 |
| - Data => $ciphertext, |
29 |
| - Passphrase => $pass, |
30 |
| - ); |
| 43 | + Data => $ciphertext, |
| 44 | + Passphrase => $pass, |
| 45 | + ); |
31 | 46 |
|
32 | 47 | DESCRIPTION
|
33 | 48 | *Crypt::OpenPGP* is a pure-Perl implementation of the OpenPGP
|
|
0 commit comments