mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2025-04-26 13:50:13 +00:00
[securemail] Update Composer dependencies
- Update phpseclib/phpseclib to version 2.0.4 - Update singpolyma/openpgp-php to version 0.3.0
This commit is contained in:
parent
37dd8a938b
commit
af672ecd1b
161 changed files with 13940 additions and 7678 deletions
|
@ -1,20 +1,24 @@
|
|||
<?php
|
||||
|
||||
use phpseclib\Crypt\TripleDES as Crypt_TripleDES;
|
||||
use phpseclib\Crypt\AES as Crypt_AES;
|
||||
use phpseclib\Crypt\Random;
|
||||
|
||||
define('CRYPT_DES_MODE_CFB', Crypt_TripleDES::MODE_CFB);
|
||||
define('CRYPT_AES_MODE_CFB', Crypt_AES::MODE_CFB);
|
||||
|
||||
require_once dirname(__FILE__).'/openpgp.php';
|
||||
@include_once dirname(__FILE__).'/openpgp_crypt_rsa.php';
|
||||
@include_once dirname(__FILE__).'/openpgp_mcrypt_wrapper.php';
|
||||
@include_once 'Crypt/AES.php';
|
||||
@include_once 'Crypt/TripleDES.php';
|
||||
require_once 'Crypt/Random.php'; // part of phpseclib is absolutely required
|
||||
|
||||
class OpenPGP_Crypt_Symmetric {
|
||||
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("Unsupported cipher");
|
||||
$prefix = crypt_random_string($key_block_bytes);
|
||||
$prefix = Random::string($key_block_bytes);
|
||||
$prefix .= substr($prefix, -2);
|
||||
|
||||
$key = crypt_random_string($key_bytes);
|
||||
$key = Random::string($key_bytes);
|
||||
$cipher->setKey($key);
|
||||
|
||||
$to_encrypt = $prefix . $message->to_bytes();
|
||||
|
@ -36,7 +40,7 @@ class OpenPGP_Crypt_Symmetric {
|
|||
$esk = pack('n', OpenPGP::bitlength($esk)) . $esk;
|
||||
array_unshift($encrypted, new OpenPGP_AsymmetricSessionKeyPacket($pass->algorithm, $pass->fingerprint(), $esk));
|
||||
} else if(is_string($pass)) {
|
||||
$s2k = new OpenPGP_S2K(crypt_random_string(10));
|
||||
$s2k = new OpenPGP_S2K(Random::string(10));
|
||||
$cipher->setKey($s2k->make_key($pass, $key_bytes));
|
||||
$esk = $cipher->encrypt(chr($symmetric_algorithm) . $key);
|
||||
array_unshift($encrypted, new OpenPGP_SymmetricSessionKeyPacket($s2k, $esk, $symmetric_algorithm));
|
||||
|
@ -143,38 +147,32 @@ class OpenPGP_Crypt_Symmetric {
|
|||
$cipher = NULL;
|
||||
switch($algo) {
|
||||
case 2:
|
||||
if(class_exists('Crypt_TripleDES')) {
|
||||
$cipher = new Crypt_TripleDES(CRYPT_DES_MODE_CFB);
|
||||
$key_bytes = 24;
|
||||
$key_block_bytes = 8;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if(defined('MCRYPT_CAST_128')) {
|
||||
$cipher = new MCryptWrapper(MCRYPT_CAST_128);
|
||||
} else {
|
||||
throw new Exception("Unsupported cipher: you must have mcrypt installed to use CAST5");
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
if(class_exists('Crypt_AES')) {
|
||||
$cipher = new Crypt_AES(CRYPT_AES_MODE_CFB);
|
||||
$cipher->setKeyLength(128);
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
if(class_exists('Crypt_AES')) {
|
||||
$cipher = new Crypt_AES(CRYPT_AES_MODE_CFB);
|
||||
$cipher->setKeyLength(192);
|
||||
}
|
||||
break;
|
||||
case 9:
|
||||
if(class_exists('Crypt_AES')) {
|
||||
$cipher = new Crypt_AES(CRYPT_AES_MODE_CFB);
|
||||
$cipher->setKeyLength(256);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if(!$cipher) return array(NULL, NULL, NULL); // Unsupported cipher
|
||||
if(!isset($key_bytes)) $key_bytes = $cipher->key_size;
|
||||
if(!isset($key_bytes)) $key_bytes = isset($cipher->key_size)?$cipher->key_size:$cipher->key_length;
|
||||
if(!isset($key_block_bytes)) $key_block_bytes = $cipher->block_size;
|
||||
return array($cipher, $key_bytes, $key_block_bytes);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue