[securemail] Update Composer dependencies
[friendica-addons.git/.git] / securemail / vendor / singpolyma / openpgp-php / examples / deASCIIdeCrypt.php
1 <?php
2
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
5
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';
9
10 $keyASCII = file_get_contents($argv[1]);
11 $msgASCII = file_get_contents($argv[3]);
12
13 $keyEncrypted = OpenPGP_Message::parse(OpenPGP::unarmor($keyASCII, 'PGP PRIVATE KEY BLOCK'));
14
15 // Try each secret key packet
16 foreach($keyEncrypted as $p) {
17         if(!($p instanceof OpenPGP_SecretKeyPacket)) continue;
18
19         $key = OpenPGP_Crypt_Symmetric::decryptSecretKey($argv[2], $p);
20
21         $msg = OpenPGP_Message::parse(OpenPGP::unarmor($msgASCII, 'PGP MESSAGE'));
22
23         $decryptor = new OpenPGP_Crypt_RSA($key);
24         $decrypted = $decryptor->decrypt($msg);
25
26         var_dump($decrypted);
27 }