PHP Class ParagonIE\Halite\Symmetric\Crypto

Datei anzeigen Open project: paragonie/halite Class Usage Examples

Public Methods

Method Description
authenticate ( string $message, AuthenticationKey $secretKey, mixed $encoding = Halite::ENCODE_BASE64URLSAFE ) : string Authenticate a string
decrypt ( string $ciphertext, EncryptionKey $secretKey, mixed $encoding = Halite::ENCODE_BASE64URLSAFE ) : HiddenString Decrypt a message using the Halite encryption protocol
encrypt ( HiddenString $plaintext, EncryptionKey $secretKey, mixed $encoding = Halite::ENCODE_BASE64URLSAFE ) : string Encrypt a message using the Halite encryption protocol
splitKeys ( EncryptionKey $master, string $salt = '', BaseConfig $config = null ) : array Split a key (using HKDF-BLAKE2b instead of HKDF-HMAC-*)
unpackMessageForDecryption ( string $ciphertext ) : array Unpack a message string into an array (assigned to variables via list()).
verify ( string $message, AuthenticationKey $secretKey, string $mac, mixed $encoding = Halite::ENCODE_BASE64URLSAFE, SymmetricConfig $config = null ) : boolean Verify the authenticity of a message, given a shared MAC key

Protected Methods

Method Description
calculateMAC ( string $message, string $authKey, SymmetricConfig $config ) : string Calculate a MAC. This is used internally.
verifyMAC ( string $mac, string $message, string $authKey, SymmetricConfig $config ) : boolean Verify a Message Authentication Code (MAC) of a message, with a shared key.

Private Methods

Method Description
__construct ( ) Don't allow this to be instantiated.

Method Details

authenticate() public static method

Authenticate a string
public static authenticate ( string $message, AuthenticationKey $secretKey, mixed $encoding = Halite::ENCODE_BASE64URLSAFE ) : string
$message string
$secretKey AuthenticationKey
$encoding mixed
return string

calculateMAC() protected static method

Calculate a MAC. This is used internally.
protected static calculateMAC ( string $message, string $authKey, SymmetricConfig $config ) : string
$message string
$authKey string
$config SymmetricConfig
return string

decrypt() public static method

Decrypt a message using the Halite encryption protocol
public static decrypt ( string $ciphertext, EncryptionKey $secretKey, mixed $encoding = Halite::ENCODE_BASE64URLSAFE ) : HiddenString
$ciphertext string
$secretKey EncryptionKey
$encoding mixed
return HiddenString

encrypt() public static method

(Encrypt then MAC -- xsalsa20 then keyed-Blake2b) You don't need to worry about chosen-ciphertext attacks.
public static encrypt ( HiddenString $plaintext, EncryptionKey $secretKey, mixed $encoding = Halite::ENCODE_BASE64URLSAFE ) : string
$plaintext HiddenString
$secretKey EncryptionKey
$encoding mixed
return string

splitKeys() public static method

Split a key (using HKDF-BLAKE2b instead of HKDF-HMAC-*)
public static splitKeys ( EncryptionKey $master, string $salt = '', BaseConfig $config = null ) : array
$master EncryptionKey
$salt string
$config BaseConfig
return array

unpackMessageForDecryption() public static method

Should return exactly 6 elements.
public static unpackMessageForDecryption ( string $ciphertext ) : array
$ciphertext string
return array

verify() public static method

Verify the authenticity of a message, given a shared MAC key
public static verify ( string $message, AuthenticationKey $secretKey, string $mac, mixed $encoding = Halite::ENCODE_BASE64URLSAFE, SymmetricConfig $config = null ) : boolean
$message string
$secretKey AuthenticationKey
$mac string
$encoding mixed
$config SymmetricConfig
return boolean

verifyMAC() protected static method

Verify a Message Authentication Code (MAC) of a message, with a shared key.
protected static verifyMAC ( string $mac, string $message, string $authKey, SymmetricConfig $config ) : boolean
$mac string Message Authentication Code
$message string The message to verify
$authKey string Authentication key (symmetric)
$config SymmetricConfig Configuration object
return boolean