/** * {@inheritDoc} */ public function unwrap($in, $maxAgeSec) { //TODO remove this once we have a better way to generate a fake token // in the example files if (Config::get('allow_plaintext_token') && count(explode(':', $in)) == 6) { $data = explode(":", $in); $out = array(); $out['o'] = $data[0]; $out['v'] = $data[1]; $out['a'] = $data[2]; $out['d'] = $data[3]; $out['u'] = $data[4]; $out['m'] = $data[5]; } else { //TODO Exception handling like JAVA $bin = base64_decode($in); $cipherText = substr($bin, 0, strlen($bin) - Crypto::$HMAC_SHA1_LEN); $hmac = substr($bin, strlen($cipherText)); Crypto::hmacSha1Verify($this->hmacKey, $cipherText, $hmac); $plain = Crypto::aes128cbcDecrypt($this->cipherKey, $cipherText); $out = $this->deserialize($plain); $this->checkTimestamp($out, $maxAgeSec); } return $out; }
/** * Tests Crypto::aes128cbcEncrypt() */ public function testAes128() { $string = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit'; $key = 'Aliquam erat volutpat'; $encrypted = Crypto::aes128cbcEncrypt($key, $string); $decrypted = Crypto::aes128cbcDecrypt($key, $encrypted); $this->assertEquals($decrypted, $string); }
public static function decrypt($key, $text) { if (extension_loaded('mcrypt')) { return Crypto::aes128cbcDecrypt($key, $text); } $iv = substr($text, 0, 8); $encrypted = substr($text, 8, strlen($text)); $blowfish = Crypt_Blowfish::factory('cbc', $key, $iv); return base64_decode($blowfish->decrypt($encrypted)); }
/** * {@inheritDoc} */ public function unwrap($in, $maxAgeSec) { //TODO remove this once we have a better way to generate a fake token in the example files if ($this->allowPlaintextToken && count(explode(':', $in)) >= 7) { //Parses the security token in the form st=o:v:a:d:u:m:c $data = $this->parseToken($in); $out = array(); $out['o'] = $data[0]; $out['v'] = $data[1]; $out['a'] = $data[2]; $out['d'] = $data[3]; $out['u'] = $data[4]; $out['m'] = $data[5]; } else { $bin = base64_decode($in); if (is_callable('mb_substr')) { $cipherText = mb_substr($bin, 0, -Crypto::$HMAC_SHA1_LEN, 'latin1'); $hmac = mb_substr($bin, mb_strlen($cipherText, 'latin1'), Crypto::$HMAC_SHA1_LEN, 'latin1'); } else { $cipherText = substr($bin, 0, -Crypto::$HMAC_SHA1_LEN); $hmac = substr($bin, strlen($cipherText)); } Crypto::hmacSha1Verify($this->hmacKey, $cipherText, $hmac); if (!function_exists('mcrypt_module_open') && $this->allowPlaintextToken) { $plain = base64_decode($cipherText); } else { $plain = Crypto::aes128cbcDecrypt($this->cipherKey, $cipherText); } $out = $this->deserialize($plain); $this->checkTimestamp($out, $maxAgeSec); } return $out; }
/** * {@inheritDoc} */ public function unwrap($in, $maxAgeSec) { //TODO remove this once we have a better way to generate a fake token in the example files if ($this->allowPlaintextToken && count(explode(':', $in)) == 6) { $data = explode(":", $in); $out = array(); $out['o'] = $data[0]; $out['v'] = $data[1]; $out['a'] = $data[2]; $out['d'] = $data[3]; $out['u'] = $data[4]; $out['m'] = $data[5]; } else { $bin = base64_decode($in); $cipherText = substr($bin, 0, strlen($bin) - Crypto::$HMAC_SHA1_LEN); $hmac = substr($bin, strlen($cipherText)); Crypto::hmacSha1Verify($this->hmacKey, $cipherText, $hmac); if (!function_exists('mcrypt_module_open') && $this->allowPlaintextToken) { $plain = base64_decode($cipherText); } else { $plain = Crypto::aes128cbcDecrypt($this->cipherKey, $cipherText); } $out = $this->deserialize($plain); $this->checkTimestamp($out, $maxAgeSec); } return $out; }