3 // USAGE: php examples/deASCIIdeCrypt.php secretkey.asc password message.asc
4 // This will fail if the algo on key or message is not 3DES or AES
6 require_once dirname(__FILE__).'/../lib/openpgp.php';
7 require_once dirname(__FILE__).'/../lib/openpgp_crypt_rsa.php';
8 require_once dirname(__FILE__).'/../lib/openpgp_crypt_symmetric.php';
10 $keyASCII = file_get_contents($argv[1]);
11 $msgASCII = file_get_contents($argv[3]);
13 $keyEncrypted = OpenPGP_Message::parse(OpenPGP::unarmor($keyASCII, 'PGP PRIVATE KEY BLOCK'));
15 // Try each secret key packet
16 foreach($keyEncrypted as $p) {
17 if(!($p instanceof OpenPGP_SecretKeyPacket)) continue;
19 $key = OpenPGP_Crypt_Symmetric::decryptSecretKey($argv[2], $p);
21 $msg = OpenPGP_Message::parse(OpenPGP::unarmor($msgASCII, 'PGP MESSAGE'));
23 $decryptor = new OpenPGP_Crypt_RSA($key);
24 $decrypted = $decryptor->decrypt($msg);