10 defined(
'JPATH_PLATFORM') or die;
35 if ($key->type !=
'simple')
37 throw new InvalidArgumentException(
'Invalid key of type: ' . $key->type .
'. Expected simple.');
44 $chars = $this->_hexToIntArray($data);
45 $charCount = count($chars);
48 for ($i = 0; $i < $charCount; $i = strlen($tmp))
54 for ($i = 0; $i < $charCount; $i++)
56 $decrypted .= chr($chars[$i] ^ ord($tmp[$i]));
76 if ($key->type !=
'simple')
78 throw new InvalidArgumentException(
'Invalid key of type: ' . $key->type .
'. Expected simple.');
85 $chars = preg_split(
'//', $data, -1, PREG_SPLIT_NO_EMPTY);
86 $charCount = count($chars);
89 for ($i = 0; $i < $charCount; $i = strlen($tmp))
95 for ($i = 0; $i < $charCount; $i++)
97 $encrypted .= $this->_intToHex(ord($tmp[$i]) ^ ord($chars[$i]));
112 public function generateKey(array $options = array())
118 $key->private = $this->_getRandomKey();
119 $key->public = $key->private;
133 private function _getRandomKey($length = 256)
136 $salt =
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
137 $saltLength = strlen($salt);
140 for ($i = 0; $i < $length; $i++)
142 $key .= $salt[mt_rand(0, $saltLength - 1)];
158 private function _hexToInt($s, $i)
165 $c = substr($s1, $j, 1);
168 $c1 = substr($s1, $j + 1, 1);
194 (int) $k = $k + (16 * (
int) $c);
238 private function _hexToIntArray($hex)
242 $j = (int) strlen($hex) / 2;
244 for ($i = 0; $i < $j; $i++)
246 $array[$i] = (int) $this->_hexToInt($hex, $i);
261 private function _intToHex($i)
267 $j = (int) ($i / 16);
275 $s = strtoupper(dechex($j));
280 $s = $s . strtoupper(dechex($k));