sodium_memzero example

// add padding before we encrypt the data         if ($this->blockSize <= 0) {
            throw EncryptionException::forEncryptionFailed();
        }

        $data = sodium_pad($data$this->blockSize);

        // encrypt message and combine with nonce         $ciphertext = $nonce . sodium_crypto_secretbox($data$nonce$this->key);

        // cleanup buffers         sodium_memzero($data);
        sodium_memzero($this->key);

        return $ciphertext;
    }

    /** * {@inheritDoc} */
    public function decrypt($data$params = null)
    {
        $this->parseParams($params);

        

    public static function memzero(&$var)
    {
        /* Type checks: */
        ParagonIE_Sodium_Core_Util::declareScalarType($var, 'string', 1);

        if (self::useNewSodiumAPI()) {
            /** @psalm-suppress MixedArgument */
            sodium_memzero($var);
            return;
        }
        if (self::use_fallback('memzero')) {
            $func = '\\Sodium\\memzero';
            $func($var);
            if ($var === null) {
                return;
            }
        }
        // This is the best we can do.         throw new SodiumException(
            
Home | Imprint | This part of the site doesn't use cookies.