Inheritance: extends PublicKey
Example #1
0
 /**
  * Encrypt a message with a target users' public key
  * 
  * @param string $source Message to encrypt
  * @param EncryptionPublicKey $publicKey
  * @param boolean $raw Don't hex encode the output?
  * @return string
  * @throws CryptoException\CannotPerformOperation
  */
 public static function seal(string $source, EncryptionPublicKey $publicKey, bool $raw = false) : string
 {
     if (!$publicKey instanceof EncryptionPublicKey) {
         throw new CryptoException\InvalidKey('Argument 2: Expected an instance of EncryptionPublicKey');
     }
     if (!function_exists('\\Sodium\\crypto_box_seal')) {
         throw new CryptoException\CannotPerformOperation('crypto_box_seal is not available');
     }
     $sealed = \Sodium\crypto_box_seal($source, $publicKey->getRawKeyMaterial());
     if ($raw) {
         return $sealed;
     }
     return \Sodium\bin2hex($sealed);
 }