本文整理汇总了PHP中mhash函数的典型用法代码示例。如果您正苦于以下问题:PHP mhash函数的具体用法?PHP mhash怎么用?PHP mhash使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mhash函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sha256
/**
* Create a SHA256 hash of a string
*
* Uses the PHP mhash library to create SHA256 hashes. It's better than MD5
* and SHA1, and for small amounts of data isn't much slower.
*
* @param string $string String to hash
* @return string Hexadecimal representation of SHA256 hash
*/
function sha256($string)
{
if (!function_exists('mhash')) {
trigger_error('mhash not supported by this PHP installation');
}
return bin2hex(mhash(MHASH_SHA256, $string));
}
示例2: payment
public function payment($data, $order_data, $auto_submit = false)
{
$data['order_id'] = $order_data['order_id'];
if ($order_data['currency_id'] != 'USD') {
throw new waPaymentException(_w('Order currency is not USD but payment gateway provide only USD transactions'));
}
$type_trans = array_flip(self::$type_trans);
if (!empty($data['type']) && !empty($type_trans[$data['type']])) {
$type = $type_trans[$data['type']];
} else {
$type = self::OPERATION_AUTH_ONLY;
}
if (empty($order_data['description_en'])) {
$order_data['description_en'] = 'Order #' . $order_data['order_id'] . ' (' . gmdate('F, d Y') . ')';
}
$c = new waContact($order_data['contact_id']);
$locale = $c->getLocale();
$form_fields = array('x_login' => $this->login, 'x_amount' => number_format($order_data['amount'], 2, '.', ''), 'x_description' => $order_data['description_en'], 'x_invoice_num' => $order_data['order_id'], 'x_fp_sequence' => rand(1, 1000), 'x_fp_timestamp' => time(), 'x_test_request' => 'false', 'x_show_form' => 'PAYMENT_FORM', 'x_type' => $type, 'x_version' => '3.1', 'x_method' => 'CC', 'x_cust_id' => $order_data['contact_id'], 'x_customer_ip' => wa()->getRequest()->server('REMOTE_ADDR'), 'x_duplicate_window' => '28800', 'x_first_name' => waLocale::transliterate($c->get('firstname'), $locale), 'x_last_name' => waLocale::transliterate($c->get('lastname'), $locale), 'x_company' => waLocale::transliterate($c->get('company'), $locale), 'x_address' => waLocale::transliterate($c->get('address:street', 'default'), $locale), 'x_city' => waLocale::transliterate($c->get('address:city', 'default'), $locale), 'x_state' => waLocale::transliterate($c->get('address:region', 'default'), $locale), 'x_zip' => waLocale::transliterate($c->get('address:zip', 'default'), $locale), 'x_country' => waLocale::transliterate($c->get('address:country', 'default'), $locale), 'x_phone' => $c->get('phone', 'default'), 'x_email' => $c->get('email', 'default'), 'x_relay_response' => isset($data['x_relay_response']) ? $data['x_relay_response'] : 'true', 'x_relay_url' => $this->getRelayUrl(), 'wa_success_url' => $this->getAdapter()->getBackUrl(waAppPayment::URL_SUCCESS, $data), 'wa_decline_url' => $this->getAdapter()->getBackUrl(waAppPayment::URL_DECLINE, $data), 'wa_cancel_url' => $this->getAdapter()->getBackUrl(waAppPayment::URL_FAIL, $data), 'wa_app_id' => $this->app_id, 'wa_merchant_id' => $this->merchant_id);
$form_fields['x_fp_hash'] = '';
// @TODO: get from common 'address' field
if (phpversion() >= '5.1.2') {
$form_fields['x_fp_hash'] = hash_hmac('md5', $this->login . "^" . $form_fields['x_fp_sequence'] . "^" . $form_fields['x_fp_timestamp'] . "^" . $form_fields['x_amount'] . "^", $this->trans_key);
} else {
$form_fields['x_fp_hash'] = bin2hex(mhash(MHASH_MD5, $this->login . "^" . $form_fields['x_fp_sequence'] . "^" . $form_fields['x_fp_timestamp'] . "^" . $form_fields['x_amount'] . "^", $this->trans_key));
}
if ($this->form_header) {
$form_fields['x_header_html_payment_form'] = $this->form_header;
}
$view = wa()->getView();
$view->assign('url', wa()->getRootUrl());
$view->assign('form_fields', $form_fields);
$view->assign('form_url', $this->getEndpointUrl());
$view->assign('auto_submit', $auto_submit);
return $view->fetch($this->path . '/templates/payment.html');
}
示例3: encrypt
public function encrypt($data, $settings)
{
$cipher = $settings['cipher'] ?? 'sha256';
$key = $settings['key'] ?? PROJECT_CONFIG['key'];
$cipher = Converter::toConstant($cipher, 'MHASH_');
return base64_encode(trim(mhash($cipher, $data, $key)));
}
示例4: generateRequestSign
/**
* Generates the fingerprint for request.
*
* @param string $merchantApiLoginId
* @param string $merchantTransactionKey
* @param string $amount
* @param string $fpSequence An invoice number or random number.
* @param string $fpTimestamp
* @return string The fingerprint.
*/
public function generateRequestSign($merchantApiLoginId, $merchantTransactionKey, $amount, $currencyCode, $fpSequence, $fpTimestamp)
{
if (phpversion() >= '5.1.2') {
return hash_hmac("md5", $merchantApiLoginId . "^" . $fpSequence . "^" . $fpTimestamp . "^" . $amount . "^" . $currencyCode, $merchantTransactionKey);
}
return bin2hex(mhash(MHASH_MD5, $merchantApiLoginId . "^" . $fpSequence . "^" . $fpTimestamp . "^" . $amount . "^" . $currencyCode, $merchantTransactionKey));
}
示例5: Cipher
function Cipher($textkey)
{
$this->enc = MCRYPT_RIJNDAEL_128;
$this->mode = MCRYPT_MODE_ECB;
$this->securekey = mhash(MHASH_SHA256, $textkey);
$iv_size = mcrypt_get_iv_size($this->enc, $this->mode);
$this->iv = mcrypt_create_iv($iv_size, MCRYPT_DEV_RANDOM);
}
示例6: ComparePassword
function ComparePassword($password, $hash)
{
$hash = base64_decode(substr($hash, 6));
$original_hash = substr($hash, 0, 20);
$salt = substr($hash, 20);
$new_hash = mhash(MHASH_SHA1, $password . $salt);
return strcmp($original_hash, $new_hash);
}
示例7: generatePrivateKey
public static function generatePrivateKey($s, $size)
{
if (function_exists('mhash') && defined('MHASH_SHA256')) {
return convertStringToByteArray(substr(mhash(MHASH_SHA256, $s), 0, $size));
} else {
throw new Exception('cryptoHelpers::generatePrivateKey currently requires mhash');
}
}
示例8: validateHash
/**
* Проверка подписи платежа
*/
public function validateHash($validator, $values)
{
$sign = base64_encode(mhash(MHASH_SHA1, sfConfig::get('app_sentry_password') . $values['MerID'] . $values['AcqID'] . $values['OrderID']));
if ($sign === @$values['Signature']) {
return $sign;
}
throw new sfValidatorError($validator, 'Invalid.');
}
示例9: encrypt
public function encrypt($data = '', $settings = array())
{
$cipher = isset($settings['cipher']) ? $settings['cipher'] : 'sha256';
$key = isset($settings['key']) ? $settings['key'] : Config::get('Encode', 'projectKey');
// MHASH_ ön eki ilave ediliyor.
$cipher = Convert::toConstant($cipher, 'MHASH_');
return base64_encode(trim(mhash($cipher, $data, $key)));
}
示例10: extractTokenFromMetadata
/**
* @param Metadata $metadata metadata
*
* @return string
*/
private function extractTokenFromMetadata(Metadata $metadata)
{
$phrase = $metadata->key;
if ($metadata->passphrase) {
$phrase .= ':' . $metadata->passphrase;
}
return mhash(MHASH_SHA256, $phrase);
}
示例11: make_md4_password
function make_md4_password($password)
{
if (function_exists('hash')) {
$hash = strtoupper(hash("md4", iconv("UTF-8", "UTF-16LE", $password)));
} else {
$hash = strtoupper(bin2hex(mhash(MHASH_MD4, iconv("UTF-8", "UTF-16LE", $password))));
}
return $hash;
}
示例12: punHash
/**
* old punbb hash function
* @return string
*/
public static function punHash($str)
{
if (function_exists('sha1')) {
return sha1($str);
} elseif (function_exists('mhash')) {
return bin2hex(mhash(MHASH_SHA1, $str));
}
return md5($str);
}
示例13: createAuthToken
public function createAuthToken()
{
$datePart = gmdate("Ymd");
$timePart = gmdate("H");
$authString = $this->securityWord . ":" . $datePart . ":" . $timePart;
$sha256 = bin2hex(mhash(MHASH_SHA256, $authString));
return strtoupper($sha256);
}
示例14: _digestMhash
protected static function _digestMhash($algorithm, $data, $binaryOutput)
{
$constant = constant('MHASH_' . strtoupper($algorithm));
$binary = mhash($constant, $data);
if ($binaryOutput) {
return $binary;
}
return bin2hex($binary);
}
示例15: create_form
/**
* 新增
*/
function create_form($list)
{
$pname = get_class($this);
$this_script = "http://{$_SERVER['HTTP_HOST']}";
$this->add_field('v_mid', GetValue($pname . "_id"));
//商户编号
$this->add_field('v_oid', date('Ymd') . '-' . GetValue($pname . "_id") . '-' . $list['sn']);
//订单编号
$this->add_field('v_rcvname', $list['delivery_firstname'] . " " . $list['delivery_lastname']);
//收货人姓名
$this->add_field('v_rcvaddr', $list['delivery_address']);
//收货人地址
$this->add_field('v_rcvtel', $list['delivery_telephone']);
//收货人电话
$this->add_field('v_rcvpost', $list['delivery_zip']);
//收货人邮编
$this->add_field('v_amount', $list['orders_total']);
//订单总金额
//$this->add_field('v_language','en');//订单语言
$this->add_field('v_ymd', date('Ymd', $list['dateline']));
//订单产生日期
$this->add_field('v_orderstatus', 1);
//配货状态
$this->add_field('v_ordername', $list['delivery_firstname'] . " " . $list['delivery_lastname']);
//订货人姓名
$this->add_field('v_moneytype', 1);
//币种,0为人民币,1为美元,2为欧元,3为英镑,4为日元,5为韩元,6为澳大利亚元
$this->add_field('v_url', $this_script . U('Payment/payeasy_return'));
//支付动作完成后返回到该url,支付结果以GET方式发送
$this->add_field('v_md5info', bin2hex(mhash(MHASH_MD5, "1" . date('Ymd', $list['dateline']) . $list['orders_total'] . $list['delivery_firstname'] . " " . $list['delivery_lastname'] . date('Ymd') . '-' . GetValue($pname . "_id") . '-' . $list['sn'] . GetValue($pname . "_id") . $this_script . U('Payment/payeasy_return'), GetValue($pname . "_key"))));
//订单数字指纹
$this->add_field('v_shipstreet', $list['delivery_address']);
//送货街道地址
$this->add_field('v_shipcity', $list['delivery_city']);
//送货城市
//$this->add_field('v_shipstate',$_POST['']);//送货省/州
$this->add_field('v_shippost', $list['delivery_zip']);
//送货邮编
//$this->add_field('v_shipcountry','840');//送货国家
$this->add_field('v_shipphone', $list['delivery_telephone']);
//送货电话
$this->add_field('v_shipemail', $list['delivery_email']);
//送货Email
$this->form .= "<form method=\"post\" name=\"pay_form\" ";
$this->form .= "action=\"" . $this->submit_url . "\">\n";
foreach ($this->fields as $name => $value) {
$this->form .= "<input type=\"hidden\" name=\"{$name}\" value=\"{$value}\"/>\n";
}
$this->form .= "</form>\n";
if (GetValue($list['payment_module_code'] . '_autosubmit') == 1) {
$delay = GetValue($list['payment_module_code'] . '_delay');
$delay = $delay ? $delay : 5;
$this->form .= $this->submit($delay);
//是否自动提交,延迟5秒
}
return $this->form;
}