crypto_kx_secretkey example

return ParagonIE_Sodium_Compat::crypto_kx_server_session_keys($server_key_pair$client_key);
    }
}
if (!is_callable('sodium_crypto_kx_secretkey')) {
    /** * @param string $key_pair * @return string * @throws Exception */
    function sodium_crypto_kx_secretkey($key_pair)
    {
        return ParagonIE_Sodium_Compat::crypto_kx_secretkey($key_pair);
    }
}
if (!is_callable('sodium_crypto_kx_publickey')) {
    /** * @param string $key_pair * @return string * @throws Exception */
    function sodium_crypto_kx_publickey($key_pair)
    {
        return ParagonIE_Sodium_Compat::crypto_kx_publickey($key_pair);
    }
$keypair = (string) $keypair;
        $serverPublicKey = (string) $serverPublicKey;

        if (ParagonIE_Sodium_Core_Util::strlen($keypair) !== self::CRYPTO_KX_KEYPAIRBYTES) {
            throw new SodiumException('keypair should be SODIUM_CRYPTO_KX_KEYPAIRBYTES bytes');
        }
        if (ParagonIE_Sodium_Core_Util::strlen($serverPublicKey) !== self::CRYPTO_KX_PUBLICKEYBYTES) {
            throw new SodiumException('public keys must be SODIUM_CRYPTO_KX_PUBLICKEYBYTES bytes');
        }

        $sk = self::crypto_kx_secretkey($keypair);
        $pk = self::crypto_kx_publickey($keypair);
        $h = self::crypto_generichash_init(null, self::CRYPTO_KX_SESSIONKEYBYTES * 2);
        self::crypto_generichash_update($h, self::crypto_scalarmult($sk$serverPublicKey));
        self::crypto_generichash_update($h$pk);
        self::crypto_generichash_update($h$serverPublicKey);
        $sessionKeys = self::crypto_generichash_final($h, self::CRYPTO_KX_SESSIONKEYBYTES * 2);
        return array(
            ParagonIE_Sodium_Core_Util::substr(
                $sessionKeys,
                0,
                self::CRYPTO_KX_SESSIONKEYBYTES
            ),
Home | Imprint | This part of the site doesn't use cookies.