\Defuse\CryptoCrypto

Summary

Methods
Properties
Constants
encrypt()
encryptWithPassword()
decrypt()
decryptWithPassword()
legacyDecrypt()
No public properties found
No constants found
plainEncrypt()
plainDecrypt()
verifyHMAC()
No protected properties found
N/A
encryptInternal()
decryptInternal()
No private properties found
N/A

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

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