Add getSharedSecret method for Diffie-Hellman key exchange in EncryptionChannelSecret

This commit is contained in:
netkas 2025-03-04 13:41:44 -05:00
parent 4a37844920
commit 1723983072

View file

@ -2,6 +2,8 @@
namespace Socialbox\Objects\Client;
use Socialbox\Classes\Cryptography;
use Socialbox\Exceptions\CryptographyException;
use Socialbox\Interfaces\SerializableInterface;
use Socialbox\Objects\PeerAddress;
@ -87,6 +89,22 @@
$this->receivingPublicEncryptionKey = $receivingPublicEncryptionKey;
}
/**
* Preform a Diffie-Hellman Exchange to get the shared secret between the two peers
*
* @return string The shared secret
* @throws CryptographyException If the receiving public encryption key is not set
*/
public function getSharedSecret(): string
{
if($this->receivingPublicEncryptionKey === null)
{
throw new CryptographyException('The receiving public encryption key is not set');
}
return Cryptography::performDHE($this->receivingPublicEncryptionKey, $this->localPrivateEncryptionKey);
}
/**
* @inheritDoc
*/