Refactor RPC framework and enhance error handling.
This commit is contained in:
parent
42ba7013f7
commit
ef3b10b286
10 changed files with 383 additions and 245 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Socialbox\Classes;
|
||||
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use Random\RandomException;
|
||||
use Socialbox\Exceptions\CryptographyException;
|
||||
|
@ -192,7 +193,15 @@ class Cryptography
|
|||
*/
|
||||
public static function encryptContent(string $content, string $publicKey): string
|
||||
{
|
||||
$publicKey = openssl_pkey_get_public(self::derToPem(Utilities::base64decode($publicKey), self::PEM_PUBLIC_HEADER));
|
||||
try
|
||||
{
|
||||
$publicKey = openssl_pkey_get_public(self::derToPem(Utilities::base64decode($publicKey), self::PEM_PUBLIC_HEADER));
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
throw new CryptographyException('Failed to decode public key: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
if (!$publicKey)
|
||||
{
|
||||
throw new CryptographyException('Invalid public key: ' . openssl_error_string());
|
||||
|
@ -203,7 +212,14 @@ class Cryptography
|
|||
throw new CryptographyException('Failed to encrypt content: ' . openssl_error_string());
|
||||
}
|
||||
|
||||
return base64_encode($encrypted);
|
||||
try
|
||||
{
|
||||
return base64_encode($encrypted);
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
throw new CryptographyException('Failed to encode encrypted content: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue