Better errors for unsupported ciphers.

This commit is contained in:
Stephen Paul Weber 2013-09-14 11:28:35 -05:00
parent e78424131e
commit 7ae4d539f2
1 changed files with 2 additions and 0 deletions

View File

@ -9,6 +9,7 @@ require_once 'Crypt/Random.php';
class OpenPGP_Crypt_AES_TripleDES {
public static function encrypt($passphrases_and_keys, $message, $symmetric_algorithm=9) {
list($cipher, $key_bytes, $key_block_bytes) = self::getCipher($symmetric_algorithm);
if(!$cipher) throw new Exception("Only AES/3DES are supported.");
$prefix = crypt_random_string($key_block_bytes);
$prefix .= substr($prefix, -2);
@ -73,6 +74,7 @@ class OpenPGP_Crypt_AES_TripleDES {
$packet = clone $packet; // Do not mutate orinigal
list($cipher, $key_bytes, $key_block_bytes) = self::getCipher($packet->symmetric_algorithm);
if(!$cipher) throw new Exception("Only AES/3DES are supported.");
$cipher->setKey($packet->s2k->make_key($pass, $key_bytes));
$cipher->setIV(substr($packet->encrypted_data, 0, $key_block_bytes));
$material = $cipher->decrypt(substr($packet->encrypted_data, $key_block_bytes));