You are here

public static function ParagonIE_Sodium_Crypto32::box_seal_open in Automatic Updates 7

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

Opens a message encrypted via box_seal().

@internal Do not use this directly. Use ParagonIE_Sodium_Compat.

Parameters

string $message:

string $keypair:

Return value

string

Throws

SodiumException

TypeError

1 call to ParagonIE_Sodium_Crypto32::box_seal_open()
ParagonIE_Sodium_Compat::crypto_box_seal_open in vendor/paragonie/sodium_compat/src/Compat.php
Opens a message encrypted with crypto_box_seal(). Requires the recipient's keypair (sk || pk) to decrypt successfully.

File

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

Class

ParagonIE_Sodium_Crypto32
Class ParagonIE_Sodium_Crypto

Code

public static function box_seal_open($message, $keypair) {

  /** @var string $ephemeralPK */
  $ephemeralPK = ParagonIE_Sodium_Core32_Util::substr($message, 0, 32);

  /** @var string $ciphertext (ciphertext + MAC) */
  $ciphertext = ParagonIE_Sodium_Core32_Util::substr($message, 32);

  /** @var string $secretKey */
  $secretKey = self::box_secretkey($keypair);

  /** @var string $publicKey */
  $publicKey = self::box_publickey($keypair);

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

  /** @var string $keypair */
  $keypair = self::box_keypair_from_secretkey_and_publickey($secretKey, $ephemeralPK);

  /** @var string $m */
  $m = self::box_open($ciphertext, $nonce, $keypair);
  try {
    ParagonIE_Sodium_Compat::memzero($secretKey);
    ParagonIE_Sodium_Compat::memzero($ephemeralPK);
    ParagonIE_Sodium_Compat::memzero($nonce);
  } catch (SodiumException $ex) {
    $secretKey = null;
    $ephemeralPK = null;
    $nonce = null;
  }
  return $m;
}