ParagonIE_Sodium_File

Extends\ParagonIE_Sodium_Core_Util

Class ParagonIE_Sodium_File

package

Default

Methods

abs

abs(integer $integer,integer $size): integer
inheritedstatic

Arguments

$integer

integer

$size

integer

(16, 32, 64)

Response

integer

Box a file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_box(), but produces the same result.

box(string $inputFile,string $outputFile,string $nonce,string $keyPair): boolean
static
Throws
\SodiumException
\TypeError

Arguments

$inputFile

string

Absolute path to a file on the filesystem

$outputFile

string

Absolute path to a file on the filesystem

$nonce

string

Number to be used only once

$keyPair

string

ECDH secret key and ECDH public key concatenated

Response

boolean

box_decrypt

box_decrypt(resource $ifp,resource $ofp,integer $mlen,string $nonce,string $boxKeypair): boolean
static
Throws
\SodiumException
\TypeError

Arguments

$ifp

resource

$ofp

resource

$mlen

integer

$nonce

string

$boxKeypair

string

Response

boolean

box_encrypt

box_encrypt(resource $ifp,resource $ofp,integer $mlen,string $nonce,string $boxKeypair): boolean
static
Throws
\SodiumException
\TypeError

Arguments

$ifp

resource

$ofp

resource

$mlen

integer

$nonce

string

$boxKeypair

string

Response

boolean

Open a boxed file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_box_open(), but produces the same result.

box_open(string $inputFile,string $outputFile,string $nonce,string $keypair): boolean
static

Warning: Does not protect against TOCTOU attacks. You should just load the file into memory and use crypto_box_open() if you are worried about those.

Throws
\SodiumException
\TypeError

Arguments

$inputFile

string

$outputFile

string

$nonce

string

$keypair

string

Response

boolean

Seal a file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_box_seal(), but produces the same result.

box_seal(string $inputFile,string $outputFile,string $publicKey): boolean
static
Throws
\SodiumException
\TypeError

Arguments

$inputFile

string

Absolute path to a file on the filesystem

$outputFile

string

Absolute path to a file on the filesystem

$publicKey

string

ECDH public key

Response

boolean

Open a sealed file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_box_seal_open(), but produces the same result.

box_seal_open(string $inputFile,string $outputFile,string $ecdhKeypair): boolean
static

Warning: Does not protect against TOCTOU attacks. You should just load the file into memory and use crypto_box_seal_open() if you are worried about those.

Throws
\SodiumException
\TypeError

Arguments

$inputFile

string

$outputFile

string

$ecdhKeypair

string

Response

boolean

If a variable does not match a given type, throw a TypeError.

declareScalarType(mixed &$mixedVar = null,string $type = 'void',integer $argumentIndex): void
inheritedstatic
Throws
\TypeError
\SodiumException

Arguments

$mixedVar

mixed

$type

string

$argumentIndex

integer

ftell

ftell(resource $resource): integer
static
Throws
\SodiumException

Arguments

$resource

resource

Response

integer

Calculate the BLAKE2b hash of a file.

generichash(string $filePath,string|null $key = '',integer $outputLength = 32): string
static
psalm-suppress

FailedTypeResolution

Throws
\SodiumException
\TypeError

Arguments

$filePath

string

Absolute path to a file on the filesystem

$key

string|null

BLAKE2b key

$outputLength

integer

Length of hash output

Response

string

BLAKE2b hash

Catch hash_update() failures and throw instead of silently proceeding

hash_update( &$hs,string $data): void
inheritedstatic
psalm-suppress

PossiblyInvalidArgument

Throws
\SodiumException

Arguments

$hs

$data

string

Evaluate whether or not two strings are equal (in constant-time)

hashEquals(string $left,string $right): boolean
inheritedstatic
Throws
\SodiumException
\TypeError

Arguments

$left

string

$right

string

Response

boolean

onetimeauth_verify

onetimeauth_verify(\ParagonIE_Sodium_Core_Poly1305_State $state,resource $ifp,string $tag = '',integer $mlen): boolean
static
Throws
\SodiumException
\TypeError

Arguments

$ifp

resource

$tag

string

$mlen

integer

Response

boolean

One-time message authentication for 32-bit systems

onetimeauth_verify_core32(\ParagonIE_Sodium_Core32_Poly1305_State $state,resource $ifp,string $tag = '',integer $mlen): boolean
static
Throws
\SodiumException
\TypeError

Arguments

$ifp

resource

$tag

string

$mlen

integer

Response

boolean

Encrypt a file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_secretbox(), but produces the same result.

secretbox(string $inputFile,string $outputFile,string $nonce,string $key): boolean
static
Throws
\SodiumException
\TypeError

Arguments

$inputFile

string

Absolute path to a file on the filesystem

$outputFile

string

Absolute path to a file on the filesystem

$nonce

string

Number to be used only once

$key

string

Encryption key

Response

boolean

Decrypt a file

secretbox_decrypt(resource $ifp,resource $ofp,integer $mlen,string $nonce,string $key): boolean
static
Throws
\SodiumException
\TypeError

Arguments

$ifp

resource

$ofp

resource

$mlen

integer

$nonce

string

$key

string

Response

boolean

Decrypt a file (32-bit)

secretbox_decrypt_core32(resource $ifp,resource $ofp,integer $mlen,string $nonce,string $key): boolean
static
Throws
\SodiumException
\TypeError

Arguments

$ifp

resource

$ofp

resource

$mlen

integer

$nonce

string

$key

string

Response

boolean

Encrypt a file

secretbox_encrypt(resource $ifp,resource $ofp,integer $mlen,string $nonce,string $key): boolean
static
Throws
\SodiumException
\TypeError

Arguments

$ifp

resource

$ofp

resource

$mlen

integer

$nonce

string

$key

string

Response

boolean

Encrypt a file (32-bit)

secretbox_encrypt_core32(resource $ifp,resource $ofp,integer $mlen,string $nonce,string $key): boolean
static
Throws
\SodiumException
\TypeError

Arguments

$ifp

resource

$ofp

resource

$mlen

integer

$nonce

string

$key

string

Response

boolean

Seal a file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_secretbox_open(), but produces the same result.

secretbox_open(string $inputFile,string $outputFile,string $nonce,string $key): boolean
static

Warning: Does not protect against TOCTOU attacks. You should just load the file into memory and use crypto_secretbox_open() if you are worried about those.

Throws
\SodiumException
\TypeError

Arguments

$inputFile

string

$outputFile

string

$nonce

string

$key

string

Response

boolean

Sign a file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_sign_detached(), but produces the same result.

sign(string $filePath,string $secretKey): string
static
Throws
\SodiumException
\TypeError

Arguments

$filePath

string

Absolute path to a file on the filesystem

$secretKey

string

Secret signing key

Response

string

Ed25519 signature

Sign a file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_sign_detached(), but produces the same result. (32-bit)

sign_core32(string $filePath,string $secretKey): string
static
Throws
\SodiumException
\TypeError

Arguments

$filePath

string

Absolute path to a file on the filesystem

$secretKey

string

Secret signing key

Response

string

Ed25519 signature

Update a hash context with the contents of a file, without loading the entire file into memory.

updateHashWithFile(resource|\HashContext $hash,resource $fp,integer $size): resource|object
static
psalm-suppress

PossiblyInvalidArgument PHP 7.2 changes from a resource to an object, which causes Psalm to complain about an error.

TypeCoercion Ditto.

Throws
\SodiumException
\TypeError

Arguments

$hash

resource|\HashContext

$fp

resource

$size

integer

Response

resource|object

Resource on PHP < 7.2, HashContext object on PHP >= 7.2

Verify a file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_sign_verify_detached(), but produces the same result.

verify(string $sig,string $filePath,string $publicKey): boolean
static
Throws
\SodiumException
\TypeError
\Exception

Arguments

$sig

string

Ed25519 signature

$filePath

string

Absolute path to a file on the filesystem

$publicKey

string

Signing public key

Response

boolean

Verify a file (rather than a string). Uses less memory than ParagonIE_Sodium_Compat::crypto_sign_verify_detached(), but produces the same result. (32-bit)

verify_core32(string $sig,string $filePath,string $publicKey): boolean
static
Throws
\SodiumException
\Exception

Arguments

$sig

string

Ed25519 signature

$filePath

string

Absolute path to a file on the filesystem

$publicKey

string

Signing public key

Response

boolean

Constants

BUFFER_SIZE

BUFFER_SIZE