public static function hmacSha1Verify($key, $in, $expected) { $hmac = Crypto::hmacSha1($key, $in); if ($hmac != $expected) { throw new GeneralSecurityException("HMAC verification failure"); } }
/** * {@inheritDoc} */ public function wrap(array $in) { $encoded = $this->serializeAndTimestamp($in); $cipherText = Crypto::aes128cbcEncrypt($this->cipherKey, $encoded); $hmac = Crypto::hmacSha1($this->hmacKey, $cipherText); $b64 = base64_encode($cipherText . $hmac); return $b64; }
/** * Tests Crypto::hmacSha1() */ public function testHmacSha1() { $string = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit'; $key = 'Aliquam erat volutpat'; $expected = '%16%E7%E0E%22%08%5C%2B48%85d%FE%DE%C7%3A%C3%0D%11c'; $hmac = urlencode(Crypto::hmacSha1($key, $string)); $this->assertEquals($expected, $hmac); }
/** * {@inheritDoc} */ public function wrap(array $in) { $encoded = $this->serializeAndTimestamp($in); if (!function_exists('mcrypt_module_open') && $this->allowPlaintextToken) { $cipherText = base64_encode($encoded); } else { $cipherText = Crypto::aes128cbcEncrypt($this->cipherKey, $encoded); } $hmac = Crypto::hmacSha1($this->hmacKey, $cipherText); $b64 = base64_encode($cipherText . $hmac); return $b64; }
/** * @see BasicBlobCrypter::warp() */ public function wrap(array $in) { $encoded = $this->serializeAndTimestamp($in); if ($this->allowPlaintextToken) { $cipherText = base64_encode($encoded); } else { $cipherText = opShindigCrypto::encrypt($this->cipherKey, $encoded); } $hmac = Crypto::hmacSha1($this->hmacKey, $cipherText); $b64 = base64_encode($cipherText . $hmac); return $b64; }