Methods

encrypt()

encrypt(string  $plaintext, \Defuse\Crypto\Key  $key, boolean  $raw_binary = false) : string

Encrypts a string with a Key.

Parameters

string $plaintext
\Defuse\Crypto\Key $key
boolean $raw_binary

Throws

\Defuse\Crypto\Exception\EnvironmentIsBrokenException

Returns

string

encryptWithPassword()

encryptWithPassword(string  $plaintext, string  $password, boolean  $raw_binary = false) : string

Encrypts a string with a password, using a slow key derivation function to make password cracking more expensive.

Parameters

string $plaintext
string $password
boolean $raw_binary

Throws

\Defuse\Crypto\Exception\EnvironmentIsBrokenException

Returns

string

decrypt()

decrypt(string  $ciphertext, \Defuse\Crypto\Key  $key, boolean  $raw_binary = false) : string

Decrypts a ciphertext to a string with a Key.

Parameters

string $ciphertext
\Defuse\Crypto\Key $key
boolean $raw_binary

Throws

\TypeError
\Defuse\Crypto\Exception\EnvironmentIsBrokenException
\Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException

Returns

string

decryptWithPassword()

decryptWithPassword(string  $ciphertext, string  $password, boolean  $raw_binary = false) : string

Decrypts a ciphertext to a string with a password, using a slow key derivation function to make password cracking more expensive.

Parameters

string $ciphertext
string $password
boolean $raw_binary

Throws

\Defuse\Crypto\Exception\EnvironmentIsBrokenException
\Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException

Returns

string

legacyDecrypt()

legacyDecrypt(string  $ciphertext, string  $key) : string

Decrypts a legacy ciphertext produced by version 1 of this library.

Parameters

string $ciphertext
string $key

Throws

\Defuse\Crypto\Exception\EnvironmentIsBrokenException
\Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException

Returns

string

runtimeTest()

runtimeTest() : void

Runs the runtime tests.

Throws

\Defuse\Crypto\Exception\EnvironmentIsBrokenException

plainEncrypt()

plainEncrypt(string  $plaintext, string  $key, string  $iv) : string

Raw unauthenticated encryption (insecure on its own).

Parameters

string $plaintext
string $key
string $iv

Throws

\Defuse\Crypto\Exception\EnvironmentIsBrokenException

Returns

string

plainDecrypt()

plainDecrypt(string  $ciphertext, string  $key, string  $iv, string  $cipherMethod) : string

Raw unauthenticated decryption (insecure on its own).

Parameters

string $ciphertext
string $key
string $iv
string $cipherMethod

Throws

\Defuse\Crypto\Exception\EnvironmentIsBrokenException

Returns

string

verifyHMAC()

verifyHMAC(string  $expected_hmac, string  $message, string  $key) : boolean

Verifies an HMAC without leaking information through side-channels.

Parameters

string $expected_hmac
string $message
string $key

Throws

\Defuse\Crypto\Exception\EnvironmentIsBrokenException

Returns

boolean

encryptInternal()

encryptInternal(string  $plaintext, \Defuse\Crypto\KeyOrPassword  $secret, boolean  $raw_binary) : string

Encrypts a string with either a key or a password.

Parameters

string $plaintext
\Defuse\Crypto\KeyOrPassword $secret
boolean $raw_binary

Returns

string

decryptInternal()

decryptInternal(string  $ciphertext, \Defuse\Crypto\KeyOrPassword  $secret, boolean  $raw_binary) : string

Decrypts a ciphertext to a string with either a key or a password.

Parameters

string $ciphertext
\Defuse\Crypto\KeyOrPassword $secret
boolean $raw_binary

Throws

\Defuse\Crypto\Exception\EnvironmentIsBrokenException
\Defuse\Crypto\Exception\WrongKeyOrModifiedCiphertextException

Returns

string

testEncryptDecrypt()

testEncryptDecrypt() : void

High-level tests of Crypto operations.

Throws

\Defuse\Crypto\Exception\EnvironmentIsBrokenException

HKDFTestVector()

HKDFTestVector() : void

Test HKDF against test vectors.

Throws

\Defuse\Crypto\Exception\EnvironmentIsBrokenException

HMACTestVector()

HMACTestVector() : void

Test HMAC against test vectors.

Throws

\Defuse\Crypto\Exception\EnvironmentIsBrokenException

AESTestVector()

AESTestVector() : void

Test AES against test vectors.

Throws

\Defuse\Crypto\Exception\EnvironmentIsBrokenException