Horde_Secret
in package
Provides an API for encrypting and decrypting small pieces of data with the use of a shared key stored in a cookie.
Copyright 1999-2017 Horde LLC (http://www.horde.org/)
See the enclosed file LICENSE for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.
Tags
Table of Contents
- DEFAULT_KEY = 'generic'
- Generic, default keyname.
- $_cipherCache : array<string|int, mixed>
- Cipher cache.
- $_keyCache : array<string|int, mixed>
- Key cache.
- $_params : array<string|int, mixed>
- Configuration parameters.
- __construct() : mixed
- Constructor.
- clearKey() : bool
- Clears a secret key entry from the current cookie.
- getKey() : string
- Return a secret key, either from a cookie, or if the cookie isn't there, assume we are using a munged version of a known base value.
- read() : string
- Decrypt a message encrypted with write().
- setKey() : string
- Generate a secret key (for encryption), either using a random string and storing it in a cookie if the user has cookies enabled, or munging some known values if they don't.
- write() : string
- Take a small piece of data and encrypt it with a key.
- _getCipherOb() : Horde_Crypt_Blowfish
- Returns the cached crypt object.
- _setCookie() : mixed
- Sets the cookie with the given keyname/key.
Constants
DEFAULT_KEY
Generic, default keyname.
public
mixed
DEFAULT_KEY
= 'generic'
Properties
$_cipherCache
Cipher cache.
protected
array<string|int, mixed>
$_cipherCache
= array()
$_keyCache
Key cache.
protected
array<string|int, mixed>
$_keyCache
= array()
$_params
Configuration parameters.
protected
array<string|int, mixed>
$_params
= array('cookie_domain' => '', 'cookie_path' => '', 'cookie_ssl' => \false, 'session_name' => 'horde_secret')
Methods
__construct()
Constructor.
public
__construct([array<string|int, mixed> $params = array() ]) : mixed
Parameters
- $params : array<string|int, mixed> = array()
-
Configuration parameters:
- cookie_domain: (string) The cookie domain.
- cookie_path: (string) The cookie path.
- cookie_ssl: (boolean) Only transmit cookie securely?
- session_name: (string) The cookie session name.
Return values
mixed —clearKey()
Clears a secret key entry from the current cookie.
public
clearKey([string $keyname = self::DEFAULT_KEY ]) : bool
Parameters
- $keyname : string = self::DEFAULT_KEY
-
The name of the key to clear.
Return values
bool —True if key existed, false if not.
getKey()
Return a secret key, either from a cookie, or if the cookie isn't there, assume we are using a munged version of a known base value.
public
getKey([string $keyname = self::DEFAULT_KEY ]) : string
Parameters
- $keyname : string = self::DEFAULT_KEY
-
The name of the key to get.
Return values
string —The secret key.
read()
Decrypt a message encrypted with write().
public
read(string $key, mixed $ciphertext) : string
Parameters
- $key : string
-
The key to use for decryption.
- $ciphertext : mixed
Tags
Return values
string —The plaintext message.
setKey()
Generate a secret key (for encryption), either using a random string and storing it in a cookie if the user has cookies enabled, or munging some known values if they don't.
public
setKey([string $keyname = self::DEFAULT_KEY ]) : string
Parameters
- $keyname : string = self::DEFAULT_KEY
-
The name of the key to set.
Return values
string —The secret key that has been generated.
write()
Take a small piece of data and encrypt it with a key.
public
write(string $key, string $message) : string
Parameters
- $key : string
-
The key to use for encryption.
- $message : string
-
The plaintext message.
Tags
Return values
string —The ciphertext message.
_getCipherOb()
Returns the cached crypt object.
protected
_getCipherOb(string $key) : Horde_Crypt_Blowfish
Parameters
- $key : string
-
The key to use for [de|en]cryption. Only the first 56 bytes of this string is used.
Tags
Return values
Horde_Crypt_Blowfish —The crypt object.
_setCookie()
Sets the cookie with the given keyname/key.
protected
_setCookie(string $keyname, string $key) : mixed
Parameters
- $keyname : string
-
The name of the key to set.
- $key : string
-
The key to use for encryption.