* Encrypt the string with fixed salt
*
* @param $str The unencrypted string
+ * @param $key Optional key, if none provided, a random key will be generated
* @return $encrypted Encrypted string
*/
- function encryptString ($str);
+ function encryptString ($str, $key = null);
/**
* Decrypt the string with fixed salt
* Encrypt the string with fixed salt
*
* @param $str The unencrypted string
+ * @param $key Optional key, if none provided, a random key will be generated
* @return $encrypted Encrypted string
*/
- function encryptStream ($str);
+ function encryptStream ($str, $key = null);
/**
* Decrypt the string with fixed salt
* Encrypt the string with fixed salt
*
* @param $str The unencrypted string
+ * @param $key Optional key, if none provided, a random key will be generated
* @return $encrypted Encrypted string
*/
- public function encryptString ($str) {
+ public function encryptString ($str, $key = null) {
// Encrypt the string through the stream
- $encrypted = $this->cryptoStreamInstance->encryptStream($str);
+ $encrypted = $this->cryptoStreamInstance->encryptStream($str, $key);
// Return the string
return $encrypted;
*/
public function randomString ($length = -1) {
// Is the number <1, then fix it to default length
- if ($length < 1) $length = $this->rndStrLen;
+ if ($length < 1) {
+ $length = $this->rndStrLen;
+ } // END - if
// Initialize the string
$randomString = '';
for ($idx = 0; $idx < $length; $idx++) {
// Add a random character and add it to our string
$randomString .= chr($this->randomNumber(0, 255));
- }
+ } // END - for
// Return the random string a little mixed up
return str_shuffle($randomString);
* Encrypt the string with fixed salt
*
* @param $str The unencrypted string
+ * @param $key Optional key, if none provided, a random key will be generated
* @return $encrypted Encrypted string
*/
- public function encryptStream ($str) {
+ public function encryptStream ($str, $key = null) {
// Init crypto module
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
- // Generate key
- $key = $this->getRngInstance()->generateKey();
+ // Generate key, if none provided
+ if (is_null($key)) {
+ // None provided
+ $key = $this->getRngInstance()->generateKey();
+ } // END - if
// Add some "garbage" to the string
switch ($this->getRngInstance()->randomNumber(0, 8)) {