/** * @see \Fine47\MicroRouter\Hashers\SHA1::generateImpl() */ protected function generateImpl($string, $asRaw) { $string = crc32($string); if (!$asRaw) { $string = String::dec2hex($string); } return $string; }
/** * Generate the SIP-2-4 hash of the specified string. No double hashing is * employed for this algorithm, though. * * @see \Fine47\MicroRouter\Interfaces\Hasher::generate() */ public function generate($data, $asRaw = false) { if (!is_string($data)) { $data = serialize($data); } $data = sip_hash($this->getSalt(), $data); if (!$asRaw) { $data = String::bin2hex($data); } return $data; }
/** * @see \Fine47\MicroRouter\Interfaces\Encryptor::decryptString() */ public function decryptString($string, $defValue = null) { // Automatically detect if the data is hexadecimal. if (String::isHex($string)) { $string = String::hex2bin($string); } // If hex string is correct. if ($string) { // Prepare decryption buffers. mcrypt_generic_init($this->module, $this->getSecret(), $this->getIV()); // Decrypt encrypted string. $data = mdecrypt_generic($this->module, $string); // Free resources. mcrypt_generic_deinit($this->module); // Size of decrypted data. $decryptedSize = strlen($data); // Time to validate the existance of 4 TAB characters in predefined // positions. if (15 < $decryptedSize && "\t" === $data[4] && "\t" === $data[8] && "\t" === $data[12]) { // Looking good, decode length of the original data. $dataSize = unpack('L*', substr($data, 5, 4)); // Does the size look genuine? Make sure also that there's a TAB // character immediately after the data. if ($decryptedSize > $dataSize + 15 && "\t" === $data[$dataSize + 15]) { return substr($data, 15, $dataSize); } } } return $defValue; }
/** * Checks whether the specified string is a valid Email. * * @param string $string to check * @return boolean TRUE if the specified string is an Email, FALSE otherwise */ protected function isEmail($string) { return String::isEmail($string); }