ParagonIE_Sodium_Compat::crypto_box() public WP 1.0
Authenticated asymmetric-key encryption. Both the sender and recipient may decrypt messages.
Algorithm: X25519-XSalsa20-Poly1305.
X25519: Elliptic-Curve Diffie Hellman over Curve25519. XSalsa20: Extended-nonce variant of salsa20. Poyl1305: Polynomial MAC for one-time message authentication.
{} It's a method of the class: ParagonIE_Sodium_Compat{}
No Hooks.
Return
String
. Ciphertext with 16-byte Poly1305 MAC
Usage
$result = ParagonIE_Sodium_Compat::crypto_box( $plaintext, $nonce, $keypair );
- $plaintext(string) (required)
- The message to be encrypted
- $nonce(string) (required)
- A Number to only be used Once; must be 24 bytes
- $keypair(string) (required)
- Your secret key and your recipient's public key
Code of ParagonIE_Sodium_Compat::crypto_box() ParagonIE Sodium Compat::crypto box WP 5.7
public static function crypto_box($plaintext, $nonce, $keypair)
{
/* Type checks: */
ParagonIE_Sodium_Core_Util::declareScalarType($plaintext, 'string', 1);
ParagonIE_Sodium_Core_Util::declareScalarType($nonce, 'string', 2);
ParagonIE_Sodium_Core_Util::declareScalarType($keypair, 'string', 3);
/* Input validation: */
if (ParagonIE_Sodium_Core_Util::strlen($nonce) !== self::CRYPTO_BOX_NONCEBYTES) {
throw new SodiumException('Argument 2 must be CRYPTO_BOX_NONCEBYTES long.');
}
if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== self::CRYPTO_BOX_KEYPAIRBYTES) {
throw new SodiumException('Argument 3 must be CRYPTO_BOX_KEYPAIRBYTES long.');
}
if (self::useNewSodiumAPI()) {
return (string) sodium_crypto_box($plaintext, $nonce, $keypair);
}
if (self::use_fallback('crypto_box')) {
return (string) call_user_func('\\Sodium\\crypto_box', $plaintext, $nonce, $keypair);
}
if (PHP_INT_SIZE === 4) {
return ParagonIE_Sodium_Crypto32::box($plaintext, $nonce, $keypair);
}
return ParagonIE_Sodium_Crypto::box($plaintext, $nonce, $keypair);
}