1
1
Fork 0

Fix php-encryption version 2 compatibility issues

This commit is contained in:
Hypolite Petovan 2017-11-09 02:35:11 -05:00
parent b4ce07bdc5
commit d5aff9ac31
2 changed files with 5 additions and 3 deletions

View file

@ -183,7 +183,8 @@ function dfrn_notify_post(App $a) {
break; break;
case 2: case 2:
try { try {
$data = \Defuse\Crypto\Crypto::decrypt(hex2bin($data), $final_key); $FinalKey = \Defuse\Crypto\Key::loadFromAsciiSafeString($final_key);
$data = \Defuse\Crypto\Crypto::decrypt(hex2bin($data), $FinalKey);
} catch (\Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) { // VERY IMPORTANT } catch (\Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException $ex) { // VERY IMPORTANT
/* /*
* Either: * Either:

View file

@ -1296,13 +1296,14 @@ class DFRN
case 2: case 2:
// RINO 2 based on php-encryption // RINO 2 based on php-encryption
try { try {
$key = \Defuse\Crypto\Key::createNewRandomKey(); $KeyObject = \Defuse\Crypto\Key::createNewRandomKey();
} catch (\Defuse\Crypto\Exception\CryptoException $ex) { } catch (\Defuse\Crypto\Exception\CryptoException $ex) {
logger('Cannot safely create a key'); logger('Cannot safely create a key');
return -4; return -4;
} }
try { try {
$data = \Defuse\Crypto\Crypto::encrypt($postvars['data'], $key); $data = \Defuse\Crypto\Crypto::encrypt($postvars['data'], $KeyObject);
$key = $KeyObject->saveToAsciiSafeString();
} catch (\Defuse\Crypto\Exception\CryptoException $ex) { } catch (\Defuse\Crypto\Exception\CryptoException $ex) {
logger('Cannot safely perform encryption'); logger('Cannot safely perform encryption');
return -6; return -6;