本文整理汇总了PHP中Zend_Crypt_Hmac::compute方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Crypt_Hmac::compute方法的具体用法?PHP Zend_Crypt_Hmac::compute怎么用?PHP Zend_Crypt_Hmac::compute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Crypt_Hmac
的用法示例。
在下文中一共展示了Zend_Crypt_Hmac::compute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _signAuthenticate
/**
* @desc Authenticate using sha1 Merchant signature
* @see success Action during checkout
* @param Varien_Object $response
*/
protected function _signAuthenticate(Varien_Object $response)
{
if ($this->_getConfigData('demoMode') === 'Y') {
$secretWord = $this->_getConfigData('secret_wordt', 'adyen_hpp');
} else {
$secretWord = $this->_getConfigData('secret_wordp', 'adyen_hpp');
}
// do it like this because $_GET is converting dot to underscore
$queryString = $_SERVER['QUERY_STRING'];
$result = array();
$pairs = explode("&", $queryString);
foreach ($pairs as $pair) {
$nv = explode("=", $pair);
$name = urldecode($nv[0]);
$value = urldecode($nv[1]);
$result[$name] = $value;
}
// do not use merchantSig in calculation
unset($result['merchantSig']);
// Sort the array by key using SORT_STRING order
ksort($result, SORT_STRING);
$signData = implode(":", array_map(array($this, 'escapeString'), array_merge(array_keys($result), array_values($result))));
$signMac = Zend_Crypt_Hmac::compute(pack("H*", $secretWord), 'sha256', $signData);
$localStringToHash = base64_encode(pack('H*', $signMac));
if (strcmp($localStringToHash, $response->getData('merchantSig')) === 0) {
return true;
}
return false;
}
示例2: _generateHmacKey
private static function _generateHmacKey($params = null, $apiKey = null)
{
$logger = self::getLoggerHandler();
$signatureData = CitrusPay_RequestData::_generateSignatureData($params, $apiKey);
$logger->info("Signature data is " . $signatureData);
$hmackey = Zend_Crypt_Hmac::compute($apiKey, "sha1", $signatureData);
$logger->info("Signature Key generated is " . $hmackey);
return $hmackey;
}
示例3: _generateAuthKey
/**
* Generate the mac key name. Must be the same function as used in the InsuranceFunctions.php
*
* @param string $requesthash Request hash of request
*/
private function _generateAuthKey($requesthash)
{
$config = Zend_Registry::get('params');
$secret = null;
// Capture HMAC secret key
if (isset($config->dms) && isset($config->dms->localcache) && isset($config->dms->localcache->hmacsecret)) {
$secret = $config->dms->localcache->hmacsecret;
}
if ($secret == null) {
throw new Exception('hmac secret not set');
}
return strtoupper(Zend_Crypt_Hmac::compute($secret, 'sha256', $requesthash));
}
示例4: _signAuthenticate
/**
* @desc Authenticate using sha1 Merchant signature
* @see success Action during checkout
* @param Varien_Object $response
*/
protected function _signAuthenticate(Varien_Object $response)
{
if ($this->_getConfigData('demoMode') === 'Y') {
$secretWord = $this->_getConfigData('secret_wordt', 'adyen_hpp');
} else {
$secretWord = $this->_getConfigData('secret_wordp', 'adyen_hpp');
}
$sign = $response->getData('authResult') . $response->getData('pspReference') . $response->getData('merchantReference') . $response->getData('skinCode');
$signMac = Zend_Crypt_Hmac::compute($secretWord, 'sha1', $sign);
$localStringToHash = base64_encode(pack('H*', $signMac));
if (strcmp($localStringToHash, $response->getData('merchantSig')) === 0) {
return true;
}
return false;
}
示例5: processCashResponse
public function processCashResponse()
{
$response = $_REQUEST;
$varienObj = new Varien_Object();
foreach ($response as $code => $value) {
if ($code == 'amount') {
if (is_object($value)) {
$value = $value->value;
}
$code = 'value';
}
$varienObj->setData($code, $value);
}
$pspReference = $varienObj->getData('pspReference');
$merchantReference = $varienObj->getData('merchantReference');
$skinCode = $varienObj->getData('skinCode');
$paymentAmount = $varienObj->getData('paymentAmount');
$currencyCode = $varienObj->getData('currencyCode');
$customPaymentMethod = $varienObj->getData('c_cash');
$paymentMethod = $varienObj->getData('paymentMethod');
$merchantSig = $varienObj->getData('merchantSig');
$sign = $pspReference . $merchantReference . $skinCode . $paymentAmount . $currencyCode . $customPaymentMethod . $paymentMethod;
$secretWord = $this->_getSecretWord();
$signMac = Zend_Crypt_Hmac::compute($secretWord, 'sha1', $sign);
$calMerchantSig = base64_encode(pack('H*', $signMac));
// check if signatures are the same
if ($calMerchantSig == $merchantSig) {
//get order && payment objects
$order = Mage::getModel('sales/order');
//error
$orderExist = $this->_incrementIdExist($varienObj, $merchantReference);
if (empty($orderExist)) {
$this->_writeLog("unknown order : {$merchantReference}");
} else {
$order->loadByIncrementId($merchantReference);
$comment = Mage::helper('adyen')->__('Adyen Cash Result URL Notification: <br /> pspReference: %s <br /> paymentMethod: %s', $pspReference, $paymentMethod);
$status = true;
$history = Mage::getModel('sales/order_status_history')->setStatus($status)->setComment($comment)->setEntityName("order")->setOrder($order);
$history->save();
return $status;
}
}
return false;
}
示例6: _signParameters
/**
* Computes the RFC 2104-compliant HMAC signature for request parameters
*
* This implements the Amazon Web Services signature, as per the following
* specification:
*
* 1. Sort all request parameters (including <tt>SignatureVersion</tt> and
* excluding <tt>Signature</tt>, the value of which is being created),
* ignoring case.
*
* 2. Iterate over the sorted list and append the parameter name (in its
* original case) and then its value. Do not URL-encode the parameter
* values before constructing this string. Do not use any separator
* characters when appending strings.
*
* @param string $queue_url Queue URL
* @param array $parameters the parameters for which to get the signature.
*
* @return string the signed data.
*/
protected function _signParameters($url, array &$paramaters)
{
$data = '';
uksort($paramaters, 'strcasecmp');
unset($paramaters['Signature']);
foreach ($paramaters as $key => $value) {
$data .= $key . $value;
}
$hmac = Zend_Crypt_Hmac::compute($this->_secretKey, 'SHA1', $data, Zend_Crypt_Hmac::BINARY);
$paramaters['Signature'] = base64_encode($hmac);
return $data;
}
示例7: _signS3UploadPolicy
/**
* Signed S3 Upload Policy
*
* @param string $policy Base64 Encoded string that is the upload policy
* @return string SHA1 encoded S3 Upload Policy
*/
protected function _signS3UploadPolicy($policy)
{
$hmac = Zend_Crypt_Hmac::compute($this->_getSecretKey(), 'SHA1', $policy, Zend_Crypt_Hmac::BINARY);
return $hmac;
}
示例8: _signParameters
/**
* Computes the RFC 2104-compliant HMAC signature for request parameters
*
* This implements the Amazon Web Services signature, as per the following
* specification:
*
* 1. Sort all request parameters (including <tt>SignatureVersion</tt> and
* excluding <tt>Signature</tt>, the value of which is being created),
* ignoring case.
*
* 2. Iterate over the sorted list and append the parameter name (in its
* original case) and then its value. Do not URL-encode the parameter
* values before constructing this string. Do not use any separator
* characters when appending strings.
*
* @param array $parameters the parameters for which to get the signature.
* @param string $secretKey the secret key to use to sign the parameters.
*
* @return string the signed data.
*/
protected function _signParameters(array $paramaters)
{
$data = "POST\n";
$data .= $this->getEndpoint()->getHost() . "\n";
$data .= "/\n";
uksort($paramaters, 'strcmp');
unset($paramaters['Signature']);
$arrData = array();
foreach ($paramaters as $key => $value) {
$value = urlencode($value);
$value = str_replace("%7E", "~", $value);
$value = str_replace("+", "%20", $value);
$arrData[] = urlencode($key) . '=' . $value;
}
$data .= implode('&', $arrData);
// require_once 'Zend/Crypt/Hmac.php';
$hmac = Zend_Crypt_Hmac::compute($this->_getSecretKey(), 'SHA256', $data, Zend_Crypt_Hmac::BINARY);
return base64_encode($hmac);
}
示例9: generateHmacKey
public function generateHmacKey($data, $apiKey = null)
{
$hmackey = Zend_Crypt_Hmac::compute($apiKey, "sha1", $data);
return $hmackey;
}
示例10: processCashResponse
public function processCashResponse()
{
$response = $_REQUEST;
$varienObj = new Varien_Object();
foreach ($response as $code => $value) {
if ($code == 'amount') {
if (is_object($value)) {
$value = $value->value;
}
$code = 'value';
}
$varienObj->setData($code, $value);
}
$pspReference = $varienObj->getData('pspReference');
$merchantReference = $varienObj->getData('merchantReference');
$skinCode = $varienObj->getData('skinCode');
$paymentAmount = $varienObj->getData('paymentAmount');
$currencyCode = $varienObj->getData('currencyCode');
$customPaymentMethod = $varienObj->getData('c_cash');
$paymentMethod = $varienObj->getData('paymentMethod');
$merchantSig = $varienObj->getData('merchantSig');
$sign = $pspReference . $merchantReference . $skinCode . $paymentAmount . $currencyCode . $customPaymentMethod . $paymentMethod;
$secretWord = $this->_getSecretWord();
$signMac = Zend_Crypt_Hmac::compute($secretWord, 'sha1', $sign);
$calMerchantSig = base64_encode(pack('H*', $signMac));
// check if signatures are the same
if ($calMerchantSig == $merchantSig) {
//get order && payment objects
$order = Mage::getModel('sales/order');
//error
$orderExist = $this->_incrementIdExist($varienObj, $merchantReference);
if (empty($orderExist)) {
$this->_writeLog("unknown order : {$merchantReference}");
} else {
$order->loadByIncrementId($merchantReference);
$comment = Mage::helper('adyen')->__('Adyen Cash Result URL Notification: <br /> pspReference: %s <br /> paymentMethod: %s', $pspReference, $paymentMethod);
$status = true;
$history = Mage::getModel('sales/order_status_history')->setStatus($status)->setComment($comment)->setEntityName("order")->setOrder($order);
$history->save();
if ($this->_getConfigData('cash_drawer', 'adyen_pos')) {
$printerIp = trim($this->_getConfigData('cash_drawer_printer_ip', 'adyen_pos'));
if ($printerIp != "") {
$drawCodeConfig = trim($this->_getConfigData('cash_drawer_code', 'adyen_pos'));
if ($drawCodeConfig != "") {
// split comm based
$drawCodes = explode(",", $drawCodeConfig);
// open the cash drawer
try {
$esc = "";
$fp = fsockopen($printerIp, 9100);
fwrite($fp, $esc . "@");
$write = "";
$count = 0;
foreach ($drawCodes as $drawCode) {
// first code 27 must be special character to let it work
if ($count == 0 && $drawCode == "27") {
$write .= $esc;
} else {
$write .= chr($drawCode);
}
++$count;
}
// example: fwrite($fp, $esc . chr(112) . chr(48) . chr(55) . chr(121));
fwrite($fp, $write);
// close connection
fclose($fp);
} catch (Exception $e) {
Mage::logException($e);
Mage::throwException($e->getMessage());
}
} else {
Mage::log("Cash drawer Code not filled in check your Adyen POS settings", Zend_Log::DEBUG, "adyen_notification.log", true);
Mage::throwException('Cash drawer Code not filled in check your Adyen POS settings');
}
} else {
Mage::log("Cash drawer Code not filled in check your Adyen POS settings", Zend_Log::DEBUG, "adyen_notification.log", true);
Mage::throwException('Cash drawer IP not filled in check your Adyen POS settings');
}
}
return $status;
}
}
return false;
}
示例11: _signParameters
/**
* Computes the RFC 2104-compliant HMAC signature for request parameters
*
* This implements the Amazon Web Services signature, as per the following
* specification:
*
* 1. Sort all request parameters (including <tt>SignatureVersion</tt> and
* excluding <tt>Signature</tt>, the value of which is being created),
* ignoring case.
*
* 2. Iterate over the sorted list and append the parameter name (in its
* original case) and then its value. Do not URL-encode the parameter
* values before constructing this string. Do not use any separator
* characters when appending strings.
*
* @param string $queue_url Queue URL
* @param array $parameters the parameters for which to get the signature.
*
* @return string the signed data.
*/
protected function _signParameters($url, array &$paramaters)
{
$data = $this->_httpMethod . "\n";
$data .= parse_url($url, PHP_URL_HOST) . "\n";
$data .= '' == ($path = parse_url($url, PHP_URL_PATH)) ? '/' : $path;
$data .= "\n";
uksort($paramaters, 'strcmp');
unset($paramaters['Signature']);
$arrData = array();
foreach ($paramaters as $key => $value) {
$arrData[] = $key . '=' . str_replace('%7E', '~', rawurlencode($value));
}
$data .= implode('&', $arrData);
$hmac = Zend_Crypt_Hmac::compute($this->_secretKey, 'SHA256', $data, Zend_Crypt_Hmac::BINARY);
$paramaters['Signature'] = base64_encode($hmac);
return $data;
}
示例12: getOptionalFormFields
public function getOptionalFormFields($adyFields, $order)
{
if (empty($order)) {
return $adyFields;
}
$helper = Mage::helper('adyen');
$secretWord = $this->_getSecretWord();
$billingAddress = $order->getBillingAddress();
$adyFields['shopper.firstName'] = $billingAddress->getFirstname();
$adyFields['shopper.lastName'] = $billingAddress->getLastname();
$adyFields['billingAddress.street'] = $helper->getStreet($billingAddress)->getName();
$adyFields['billingAddress.houseNumberOrName'] = $helper->getStreet($billingAddress)->getHouseNumber();
$adyFields['billingAddress.city'] = $billingAddress->getCity();
$adyFields['billingAddress.postalCode'] = $billingAddress->getPostcode();
$adyFields['billingAddress.stateOrProvince'] = $billingAddress->getRegionCode();
$adyFields['billingAddress.country'] = $billingAddress->getCountryId();
$sign = $adyFields['billingAddress.street'] . $adyFields['billingAddress.houseNumberOrName'] . $adyFields['billingAddress.city'] . $adyFields['billingAddress.postalCode'] . $adyFields['billingAddress.stateOrProvince'] . $adyFields['billingAddress.country'];
//Generate HMAC encrypted merchant signature
$signMac = Zend_Crypt_Hmac::compute($secretWord, 'sha1', $sign);
$adyFields['billingAddressSig'] = base64_encode(pack('H*', $signMac));
$deliveryAddress = $order->getShippingAddress();
if ($deliveryAddress != null) {
$adyFields['deliveryAddress.street'] = $helper->getStreet($deliveryAddress)->getName();
$adyFields['deliveryAddress.houseNumberOrName'] = $helper->getStreet($deliveryAddress)->getHouseNumber();
$adyFields['deliveryAddress.city'] = $deliveryAddress->getCity();
$adyFields['deliveryAddress.postalCode'] = $deliveryAddress->getPostcode();
$adyFields['deliveryAddress.stateOrProvince'] = $deliveryAddress->getRegionCode();
$adyFields['deliveryAddress.country'] = $deliveryAddress->getCountryId();
$sign = $adyFields['deliveryAddress.street'] . $adyFields['deliveryAddress.houseNumberOrName'] . $adyFields['deliveryAddress.city'] . $adyFields['deliveryAddress.postalCode'] . $adyFields['deliveryAddress.stateOrProvince'] . $adyFields['deliveryAddress.country'];
//Generate HMAC encrypted merchant signature
$secretWord = $this->_getSecretWord();
$signMac = Zend_Crypt_Hmac::compute($secretWord, 'sha1', $sign);
$adyFields['deliveryAddressSig'] = base64_encode(pack('H*', $signMac));
}
if ($adyFields['shopperReference'] != self::GUEST_ID . $order->getRealOrderId()) {
$customer = Mage::getModel('customer/customer')->load($adyFields['shopperReference']);
if ($this->getCustomerAttributeText($customer, 'gender') != "") {
$adyFields['shopper.gender'] = strtoupper($this->getCustomerAttributeText($customer, 'gender'));
} else {
// fix for OneStepCheckout (guest is not logged in but uses email that exists with account)
$_customer = Mage::getModel('customer/customer');
if ($order->getCustomerGender()) {
$customerGender = $order->getCustomerGender();
} else {
// this is still empty for OneStepCheckout so uses extra saved parameter
$payment = $order->getPayment();
$customerGender = $payment->getAdditionalInformation('customerGender');
}
$adyFields['shopper.gender'] = strtoupper($_customer->getResource()->getAttribute('gender')->getSource()->getOptionText($customerGender));
}
$adyFields['shopper.infix'] = $customer->getPrefix();
$dob = $customer->getDob();
if (!empty($dob)) {
$adyFields['shopper.dateOfBirthDayOfMonth'] = $this->getDate($dob, 'd');
$adyFields['shopper.dateOfBirthMonth'] = $this->getDate($dob, 'm');
$adyFields['shopper.dateOfBirthYear'] = $this->getDate($dob, 'Y');
} else {
// fix for OneStepCheckout (guest is not logged in but uses email that exists with account)
$dob = $order->getCustomerDob();
if (!empty($dob)) {
$adyFields['shopper.dateOfBirthDayOfMonth'] = $this->getDate($dob, 'd');
$adyFields['shopper.dateOfBirthMonth'] = $this->getDate($dob, 'm');
$adyFields['shopper.dateOfBirthYear'] = $this->getDate($dob, 'Y');
}
}
} else {
// checkout as guest use details from the order
$_customer = Mage::getModel('customer/customer');
$adyFields['shopper.gender'] = strtoupper($_customer->getResource()->getAttribute('gender')->getSource()->getOptionText($order->getCustomerGender()));
$adyFields['shopper.infix'] = $order->getCustomerPrefix();
$dob = $order->getCustomerDob();
if (!empty($dob)) {
$adyFields['shopper.dateOfBirthDayOfMonth'] = $this->getDate($dob, 'd');
$adyFields['shopper.dateOfBirthMonth'] = $this->getDate($dob, 'm');
$adyFields['shopper.dateOfBirthYear'] = $this->getDate($dob, 'Y');
}
}
// for sweden add here your socialSecurityNumber
// $adyFields['shopper.socialSecurityNumber'] = "Result of your custom input field";
$adyFields['shopper.telephoneNumber'] = $billingAddress->getTelephone();
$openinvoiceType = $this->_getConfigData('openinvoicetypes', 'adyen_openinvoice');
// get current payment method
if ($order->getPayment()->getMethod() == "adyen_openinvoice" || $order->getPayment()->getMethodInstance()->getInfoInstance()->getCcType() == "klarna" || $order->getPayment()->getMethodInstance()->getInfoInstance()->getCcType() == "afterpay_default") {
// initialize values if they are empty
$adyFields['shopper.gender'] = isset($adyFields['shopper.gender']) ? $adyFields['shopper.gender'] : "";
$adyFields['shopper.infix'] = isset($adyFields['shopper.infix']) ? $adyFields['shopper.infix'] : "";
$adyFields['shopper.dateOfBirthDayOfMonth'] = isset($adyFields['shopper.dateOfBirthDayOfMonth']) ? $adyFields['shopper.dateOfBirthDayOfMonth'] : "";
$adyFields['shopper.dateOfBirthMonth'] = isset($adyFields['shopper.dateOfBirthMonth']) ? $adyFields['shopper.dateOfBirthMonth'] : "";
$adyFields['shopper.dateOfBirthYear'] = isset($adyFields['shopper.dateOfBirthYear']) ? $adyFields['shopper.dateOfBirthYear'] : "";
$shoppperSign = $adyFields['shopper.firstName'] . $adyFields['shopper.infix'] . $adyFields['shopper.lastName'] . $adyFields['shopper.gender'] . $adyFields['shopper.dateOfBirthDayOfMonth'] . $adyFields['shopper.dateOfBirthMonth'] . $adyFields['shopper.dateOfBirthYear'] . $adyFields['shopper.telephoneNumber'];
$shopperSignMac = Zend_Crypt_Hmac::compute($secretWord, 'sha1', $shoppperSign);
$adyFields['shopperSig'] = base64_encode(pack('H*', $shopperSignMac));
}
$count = 0;
$currency = $order->getOrderCurrencyCode();
$additional_data_sign = array();
foreach ($order->getItemsCollection() as $item) {
//skip dummies
if ($item->isDummy()) {
continue;
//.........这里部分代码省略.........
示例13: addSignature
/**
* Add the S3 Authorization signature to the request headers
*
* @param string $method
* @param string $path
* @param array &$headers
* @return string
*/
protected function addSignature($method, $path, &$headers)
{
if (!is_array($headers)) {
$headers = array($headers);
}
$type = $md5 = $date = '';
// Search for the Content-type, Content-MD5 and Date headers
foreach ($headers as $key => $val) {
if (strcasecmp($key, 'content-type') == 0) {
$type = $val;
} else {
if (strcasecmp($key, 'content-md5') == 0) {
$md5 = $val;
} else {
if (strcasecmp($key, 'date') == 0) {
$date = $val;
}
}
}
}
// If we have an x-amz-date header, use that instead of the normal Date
if (isset($headers['x-amz-date']) && isset($date)) {
$date = '';
}
$sig_str = "{$method}\n{$md5}\n{$type}\n{$date}\n";
// For x-amz- headers, combine like keys, lowercase them, sort them
// alphabetically and remove excess spaces around values
$amz_headers = array();
foreach ($headers as $key => $val) {
$key = strtolower($key);
if (substr($key, 0, 6) == 'x-amz-') {
if (is_array($val)) {
$amz_headers[$key] = $val;
} else {
$amz_headers[$key][] = preg_replace('/\\s+/', ' ', $val);
}
}
}
if (!empty($amz_headers)) {
ksort($amz_headers);
foreach ($amz_headers as $key => $val) {
$sig_str .= $key . ':' . implode(',', $val) . "\n";
}
}
$sig_str .= '/' . parse_url($path, PHP_URL_PATH);
if (strpos($path, '?location') !== false) {
$sig_str .= '?location';
} else {
if (strpos($path, '?acl') !== false) {
$sig_str .= '?acl';
} else {
if (strpos($path, '?torrent') !== false) {
$sig_str .= '?torrent';
}
}
}
$signature = base64_encode(Zend_Crypt_Hmac::compute($this->_getSecretKey(), 'sha1', utf8_encode($sig_str), Zend_Crypt_Hmac::BINARY));
$headers['Authorization'] = 'AWS ' . $this->_getAccessKey() . ':' . $signature;
return $sig_str;
}
示例14: signParameters
/**
* Computes the RFC 2104-compliant HMAC signature for request parameters
*
* This implements the Amazon Web Services signature, as per the following
* specification:
*
* 1. Sort all request parameters (including <tt>SignatureVersion</tt> and
* excluding <tt>Signature</tt>, the value of which is being created),
* ignoring case.
*
* 2. Iterate over the sorted list and append the parameter name (in its
* original case) and then its value. Do not URL-encode the parameter
* values before constructing this string. Do not use any separator
* characters when appending strings.
*
* @param array $parameters the parameters for which to get the signature.
* @param string $secretKey the secret key to use to sign the parameters.
*
* @return string the signed data.
*/
protected function signParameters(array $paramaters)
{
$data = '';
uksort($paramaters, 'strcasecmp');
unset($paramaters['Signature']);
foreach ($paramaters as $key => $value) {
$data .= $key . $value;
}
require_once 'Zend/Crypt/Hmac.php';
$hmac = Zend_Crypt_Hmac::compute($this->getSecretKey(), 'SHA1', $data, Zend_Crypt_Hmac::BINARY);
return base64_encode($hmac);
}
示例15: testHmacRIPEMD160_7
public function testHmacRIPEMD160_7()
{
$data = 'Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data';
$key = str_repeat("ª", 80);
$hmac = Zend_Crypt_Hmac::compute($key, 'RIPEMD160', $data);
$this->assertEquals('69ea60798d71616cce5fd0871e23754cd75d5a0a', $hmac);
}