php-doc-en/reference/sodium/functions/sodium-crypto-box.xml
Paragon Initiative Enterprises 14e3e35ca0
Provide documentation for many ext/sodium functions
Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de>

Closes GH-592.
2021-06-04 13:10:30 +02:00

90 lines
2.7 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.sodium-crypto-box" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>sodium_crypto_box</refname>
<refpurpose>Authenticated public-key encryption</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>string</type><methodname>sodium_crypto_box</methodname>
<methodparam><type>string</type><parameter>message</parameter></methodparam>
<methodparam><type>string</type><parameter>nonce</parameter></methodparam>
<methodparam><type>string</type><parameter>key_pair</parameter></methodparam>
</methodsynopsis>
<para>
Encrypt a message using asymmetric (public key) cryptography.
</para>
<para>
The algorithm used by functions prefixed with <function>sodium_crypto_box</function> are
Elliptic Curve Diffie-Hellman over the Montgomery curve, Curve25519; usually abbreviated as
X25519.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term><parameter>message</parameter></term>
<listitem>
<para>
The message to be encrypted.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>nonce</parameter></term>
<listitem>
<para>
A number that must be only used once, per message. 24 bytes long.
This is a large enough bound to generate randomly (i.e. <function>random_bytes</function>).
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>key_pair</parameter></term>
<listitem>
<para>
See <function>sodium_crypto_box_keypair_from_secretkey_and_publickey</function>.
This should include the sender's X25519 secret key and the recipient's X25519 public key.
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns the encrypted message (ciphertext plus authentication tag). The ciphertext will be
16 bytes longer than the plaintext, and a raw binary string. See <function>sodium_bin2base64</function>
for safe encoding for storage.
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->