parent
575baaf3f2
commit
752d80f14a
@ -150,10 +150,12 @@ class OpenPGP_S2K {
|
|||||||
$bytes .= chr($this->hash_algorithm);
|
$bytes .= chr($this->hash_algorithm);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
|
if(strlen($this->salt) != 8) throw new Exception("Invalid salt length");
|
||||||
$bytes .= chr($this->hash_algorithm);
|
$bytes .= chr($this->hash_algorithm);
|
||||||
$bytes .= $this->salt;
|
$bytes .= $this->salt;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
|
if(strlen($this->salt) != 8) throw new Exception("Invalid salt length");
|
||||||
$bytes .= chr($this->hash_algorithm);
|
$bytes .= chr($this->hash_algorithm);
|
||||||
$bytes .= $this->salt;
|
$bytes .= $this->salt;
|
||||||
$bytes .= chr(OpenPGP::encode_s2k_count($this->count));
|
$bytes .= chr(OpenPGP::encode_s2k_count($this->count));
|
||||||
|
@ -40,7 +40,7 @@ class OpenPGP_Crypt_Symmetric {
|
|||||||
$esk = pack('n', OpenPGP::bitlength($esk)) . $esk;
|
$esk = pack('n', OpenPGP::bitlength($esk)) . $esk;
|
||||||
array_unshift($encrypted, new OpenPGP_AsymmetricSessionKeyPacket($pass->algorithm, $pass->fingerprint(), $esk));
|
array_unshift($encrypted, new OpenPGP_AsymmetricSessionKeyPacket($pass->algorithm, $pass->fingerprint(), $esk));
|
||||||
} else if(is_string($pass)) {
|
} else if(is_string($pass)) {
|
||||||
$s2k = new OpenPGP_S2K(Random::string(10));
|
$s2k = new OpenPGP_S2K(Random::string(8));
|
||||||
$cipher->setKey($s2k->make_key($pass, $key_bytes));
|
$cipher->setKey($s2k->make_key($pass, $key_bytes));
|
||||||
$esk = $cipher->encrypt(chr($symmetric_algorithm) . $key);
|
$esk = $cipher->encrypt(chr($symmetric_algorithm) . $key);
|
||||||
array_unshift($encrypted, new OpenPGP_SymmetricSessionKeyPacket($s2k, $esk, $symmetric_algorithm));
|
array_unshift($encrypted, new OpenPGP_SymmetricSessionKeyPacket($s2k, $esk, $symmetric_algorithm));
|
||||||
|
@ -155,6 +155,7 @@ class Encryption extends PHPUnit_Framework_TestCase {
|
|||||||
public function oneSymmetric($algorithm) {
|
public function oneSymmetric($algorithm) {
|
||||||
$data = new OpenPGP_LiteralDataPacket('This is text.', array('format' => 'u', 'filename' => 'stuff.txt'));
|
$data = new OpenPGP_LiteralDataPacket('This is text.', array('format' => 'u', 'filename' => 'stuff.txt'));
|
||||||
$encrypted = OpenPGP_Crypt_Symmetric::encrypt('secret', new OpenPGP_Message(array($data)), $algorithm);
|
$encrypted = OpenPGP_Crypt_Symmetric::encrypt('secret', new OpenPGP_Message(array($data)), $algorithm);
|
||||||
|
$encrypted = OpenPGP_Message::parse($encrypted->to_bytes());
|
||||||
$decrypted = OpenPGP_Crypt_Symmetric::decryptSymmetric('secret', $encrypted);
|
$decrypted = OpenPGP_Crypt_Symmetric::decryptSymmetric('secret', $encrypted);
|
||||||
$this->assertEquals($decrypted[0]->data, 'This is text.');
|
$this->assertEquals($decrypted[0]->data, 'This is text.');
|
||||||
}
|
}
|
||||||
@ -193,6 +194,7 @@ class Encryption extends PHPUnit_Framework_TestCase {
|
|||||||
$key = OpenPGP_Message::parse(file_get_contents(dirname(__FILE__) . '/data/helloKey.gpg'));
|
$key = OpenPGP_Message::parse(file_get_contents(dirname(__FILE__) . '/data/helloKey.gpg'));
|
||||||
$data = new OpenPGP_LiteralDataPacket('This is text.', array('format' => 'u', 'filename' => 'stuff.txt'));
|
$data = new OpenPGP_LiteralDataPacket('This is text.', array('format' => 'u', 'filename' => 'stuff.txt'));
|
||||||
$encrypted = OpenPGP_Crypt_Symmetric::encrypt($key, new OpenPGP_Message(array($data)));
|
$encrypted = OpenPGP_Crypt_Symmetric::encrypt($key, new OpenPGP_Message(array($data)));
|
||||||
|
$encrypted = OpenPGP_Message::parse($encrypted->to_bytes());
|
||||||
$decryptor = new OpenPGP_Crypt_RSA($key);
|
$decryptor = new OpenPGP_Crypt_RSA($key);
|
||||||
$decrypted = $decryptor->decrypt($encrypted);
|
$decrypted = $decryptor->decrypt($encrypted);
|
||||||
$this->assertEquals($decrypted[0]->data, 'This is text.');
|
$this->assertEquals($decrypted[0]->data, 'This is text.');
|
||||||
|
Loading…
Reference in New Issue
Block a user