You are here

public static function ParagonIE_Sodium_Crypto32::box_seal in Automatic Updates 8

Same name and namespace in other branches
  1. 7 vendor/paragonie/sodium_compat/src/Crypto32.php \ParagonIE_Sodium_Crypto32::box_seal()

X25519-XSalsa20-Poly1305 with one ephemeral X25519 keypair.

@internal Do not use this directly. Use ParagonIE_Sodium_Compat.

Parameters

string $message:

string $publicKey:

Return value

string

Throws

SodiumException

TypeError

1 call to ParagonIE_Sodium_Crypto32::box_seal()
ParagonIE_Sodium_Compat::crypto_box_seal in vendor/paragonie/sodium_compat/src/Compat.php
Anonymous public-key encryption. Only the recipient may decrypt messages.

File

vendor/paragonie/sodium_compat/src/Crypto32.php, line 448

Class

ParagonIE_Sodium_Crypto32
Class ParagonIE_Sodium_Crypto

Code

public static function box_seal($message, $publicKey) {

  /** @var string $ephemeralKeypair */
  $ephemeralKeypair = self::box_keypair();

  /** @var string $ephemeralSK */
  $ephemeralSK = self::box_secretkey($ephemeralKeypair);

  /** @var string $ephemeralPK */
  $ephemeralPK = self::box_publickey($ephemeralKeypair);

  /** @var string $nonce */
  $nonce = self::generichash($ephemeralPK . $publicKey, '', 24);

  /** @var string $keypair - The combined keypair used in crypto_box() */
  $keypair = self::box_keypair_from_secretkey_and_publickey($ephemeralSK, $publicKey);

  /** @var string $ciphertext Ciphertext + MAC from crypto_box */
  $ciphertext = self::box($message, $nonce, $keypair);
  try {
    ParagonIE_Sodium_Compat::memzero($ephemeralKeypair);
    ParagonIE_Sodium_Compat::memzero($ephemeralSK);
    ParagonIE_Sodium_Compat::memzero($nonce);
  } catch (SodiumException $ex) {
    $ephemeralKeypair = null;
    $ephemeralSK = null;
    $nonce = null;
  }
  return $ephemeralPK . $ciphertext;
}