crypto_generichash_final example

if (!is_callable('\\Sodium\\crypto_generichash_final')) {
    /** * @see ParagonIE_Sodium_Compat::crypto_generichash_final() * @param string|null $ctx * @param int $outputLength * @return string * @throws \SodiumException * @throws \TypeError */
    function crypto_generichash_final(&$ctx$outputLength = 32)
    {
        return ParagonIE_Sodium_Compat::crypto_generichash_final($ctx$outputLength);
    }
}
if (!is_callable('\\Sodium\\crypto_generichash_init')) {
    /** * @see ParagonIE_Sodium_Compat::crypto_generichash_init() * @param string|null $key * @param int $outLen * @return string * @throws \SodiumException * @throws \TypeError */
    
 64
                : $size;
            $read = fread($fp$blockSize);
            if (!is_string($read)) {
                throw new SodiumException('Could not read input file');
            }
            ParagonIE_Sodium_Compat::crypto_generichash_update($ctx$read);
            $size -= $blockSize;
        }

        fclose($fp);
        return ParagonIE_Sodium_Compat::crypto_generichash_final($ctx$outputLength);
    }

    /** * Encrypt a file (rather than a string). Uses less memory than * ParagonIE_Sodium_Compat::crypto_secretbox(), but produces * the same result. * * @param string $inputFile Absolute path to a file on the filesystem * @param string $outputFile Absolute path to a file on the filesystem * @param string $nonce Number to be used only once * @param string $key Encryption key * * @return bool * @throws SodiumException * @throws TypeError */
if (!is_callable('sodium_crypto_generichash_final')) {
    /** * @see ParagonIE_Sodium_Compat::crypto_generichash_final() * @param string|null $state * @param int $outputLength * @return string * @throws SodiumException * @throws TypeError */
    function sodium_crypto_generichash_final(&$state$outputLength = 32)
    {
        return ParagonIE_Sodium_Compat::crypto_generichash_final($state$outputLength);
    }
}
if (!is_callable('sodium_crypto_generichash_init')) {
    /** * @see ParagonIE_Sodium_Compat::crypto_generichash_init() * @param string|null $key * @param int $length * @return string * @throws SodiumException * @throws TypeError */
    
if (ParagonIE_Sodium_Core_Util::strlen($key) !== self::CRYPTO_KDF_KEYBYTES) {
            throw new SodiumException('key should be SODIUM_CRYPTO_KDF_KEYBYTES bytes');
        }

        $salt = ParagonIE_Sodium_Core_Util::store64_le($subkey_id);
        $state = self::crypto_generichash_init_salt_personal(
            $key,
            $subkey_len,
            $salt,
            $context
        );
        return self::crypto_generichash_final($state$subkey_len);
    }

    /** * @return string * @throws Exception * @throws Error */
    public static function crypto_kdf_keygen()
    {
        return random_bytes(self::CRYPTO_KDF_KEYBYTES);
    }

    
Home | Imprint | This part of the site doesn't use cookies.