Namespace: \ParagonIE\Halite\Symmetric
public
authenticate(string $message
,AuthenticationKey
$secretKey
,$encoding = Halite::ENCODE_BASE64URLSAFE
) :string
Calculate a MAC for a given message, using a secret authentication key.
public
encrypt(HiddenString $plaintext
,EncryptionKey
$secretKey
,$encoding = Halite::ENCODE_BASE64URLSAFE
):string
Encrypt-then-authenticate a message. This method will:
- Generate a random HKDF salt.
- Split the
EncryptionKey
into an encryption key and authentication key using salted HKDF. - Generate a random nonce.
- Encrypt your plaintext (
$source
) with the derived encryption key (step 2). - MAC the ciphertext (step 4), along with the current library version, the HKDF salt, and the nonce, with the derived authentication key (step 2).
- Return the output of step 5 either as raw binary or as a hex-encoded string.
public
decrypt(string $ciphertext
,EncryptionKey
$secretKey
,$encoding = Halite::ENCODE_BASE64URLSAFE
) :HiddenString
Verify-then-decrypt a message. This method will:
- If we aren't expecting raw data, we treat
$source
as a hex string and decode it to raw binary. - Parse the library version tag, HKDF salt, and nonce from the message.
- Split the
EncryptionKey
into an encryption key and authentication key using salted HKDF. - Verify the MAC using the derived authentication key (step 3).
- If step 4 is successful, decrypt the ciphertext with the derived encryption key (step 3).
- Return what should be the original plaintext.
public
encryptWithAd(HiddenString $plaintext
,EncryptionKey
$secretKey
,string $additionalData = ''
,$encoding = Halite::ENCODE_BASE64URLSAFE
):string
This is similar to encrypt()
, except the $additionalData
string is prepended to the ciphertext (after the nonce) when calculating the Message Authentication Code (MAC).
public
decryptWithAd(string $ciphertext
,EncryptionKey
$secretKey
,string $additionalData = ''
,$encoding = Halite::ENCODE_BASE64URLSAFE
):HiddenString
This is similar to decrypt()
, except the $additionalData
string is prepended to the ciphertext (after the nonce) when calculating the Message Authentication Code (MAC).
public
verify(string $message
,AuthenticationKey
$secretKey
,string $mac
,$encoding = Halite::ENCODE_BASE64URLSAFE
) :boolean
Verify the MAC for a given message and secret authentication key.