本文整理汇总了PHP中openssl_sign函数的典型用法代码示例。如果您正苦于以下问题:PHP openssl_sign函数的具体用法?PHP openssl_sign怎么用?PHP openssl_sign使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了openssl_sign函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filterHttpRequest
public function filterHttpRequest($method, $url, $headers = array(), $body = null, $contentType = null)
{
if ($this->getAuthSubToken() != null) {
// AuthSub authentication
if ($this->getAuthSubPrivateKeyId() != null) {
// secure AuthSub
$time = time();
$nonce = mt_rand(0, 999999999);
$dataToSign = $method . ' ' . $url . ' ' . $time . ' ' . $nonce;
// compute signature
$pKeyId = $this->getAuthSubPrivateKeyId();
$signSuccess = openssl_sign($dataToSign, $signature, $pKeyId, OPENSSL_ALGO_SHA1);
if (!$signSuccess) {
require_once 'Zend/Gdata/App/Exception.php';
throw new Zend_Gdata_App_Exception('openssl_signing failure - returned false');
}
// encode signature
$encodedSignature = base64_encode($signature);
// final header
$headers['authorization'] = 'AuthSub token="' . $this->getAuthSubToken() . '" ' . 'data="' . $dataToSign . '" ' . 'sig="' . $encodedSignature . '" ' . 'sigalg="rsa-sha1"';
} else {
// AuthSub without secure tokens
$headers['authorization'] = 'AuthSub token="' . $this->getAuthSubToken() . '"';
}
} elseif ($this->getClientLoginToken() != null) {
$headers['authorization'] = 'GoogleLogin auth=' . $this->getClientLoginToken();
}
return array('method' => $method, 'url' => $url, 'body' => $body, 'headers' => $headers, 'contentType' => $contentType);
}
示例2: signData
/**
* Generate a signature of the given data using a private key and an algorithm.
*
* @param string $data
* @param PrivateKey $privateKey
* @param int $algorithm
*
* @return string
*/
public function signData($data, PrivateKey $privateKey, $algorithm = OPENSSL_ALGO_SHA256)
{
if (!openssl_sign($data, $signature, $privateKey->getResource(), $algorithm)) {
throw new DataSigningException(sprintf('OpenSSL data signing failed with error: %s', openssl_error_string()));
}
return $signature;
}
示例3: sign
/**
* 签名数据
*
* @param string $data
* 要签名的数据
* @param string $private
* 私钥文件
* @return string 签名的16进制数据
*/
private function sign($data)
{
$p = openssl_pkey_get_private($this->chinaums_config['privateKey']);
openssl_sign($data, $signature, $p);
openssl_free_key($p);
return bin2hex($signature);
}
示例4: generateRSA
private static function generateRSA($input, $secret, $algo)
{
if (!openssl_sign($input, $signature, $secret, $algo)) {
throw new Exception("Unable to sign data.");
}
return $signature;
}
示例5: sign
/**
* @param array $params
* @return string
*/
public function sign(array $params)
{
$digestText = implode('|', $params);
openssl_sign($digestText, $digest, $this->getPrivateKeyResource());
$digest = base64_encode($digest);
return $digest;
}
示例6: sign
/**
* Signs the data using this private key
*
* @param string data
* @return string
* @throws security.crypto.CryptoException if the operation fails
*/
public function sign($data)
{
if (false === openssl_sign($data, $signature, $this->_hdl)) {
throw new CryptoException('Could not sign data', OpenSslUtil::getErrors());
}
return $signature;
}
示例7: createRSASign
/**
* 对数据进行RSA签名
*
* @param string $data
* 需要进行签名的数据.
* @param string $privateKey
* 签名用户的私钥
*
* @return string
*/
public static function createRSASign($data, $privateKey)
{
$private_key_id = openssl_pkey_get_private($privateKey);
openssl_sign($data, $signature, $private_key_id, OPENSSL_ALGO_SHA1);
openssl_free_key($private_key_id);
return base64_encode($signature);
}
示例8: array
/**
*
array(3) {
["cert"]=>
string(1334) "-----BEGIN CERTIFICATE-----
MIIDrTCCAxagAwIBAgIQWQKhEMePlPB2aPEW+YUIIDANBgkqhkiG9w0BAQUFADAk
MQswCQYDVQQGEwJDTjEVMBMGA1UEChMMQ0ZDQSBURVNUIENBMB4XDTExMDgyNDA3
NDc1MFoXDTEzMDgyNDA3NDc1MFowczELMAkGA1UEBhMCQ04xFTATBgNVBAoTDENG
Q0EgVEVTVCBDQTERMA8GA1UECxMITG9jYWwgUkExFDASBgNVBAsTC0VudGVycHJp
c2VzMSQwIgYDVQQDFBswNDFAWjIwMTEwODI0QFRFU1RAMDAwMDAwMjMwgZ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WhTfAamhV3A5v5y
PiZr4haMDpulU08Y0JxsegwDwfbscQrhG7nvilIqIa+HiI1xkfFxjtNUrMN5hpvO
8HUUfwqzb5EdllQcv/C0xxBkeCECIb86JJry7ty4mNBkN2idbGxldMi90QIDAQAB
AoGATvTIIdfbDss06Vyk/smlb8dohmkfQov6Q/AKHUDXmrCbIIDCiuw70/z73y4i
uviAuxYovrqSugryb4tStUMTogmft4methz1/O/083XHwBNKBPnS2fobYDfBxqkX
tH26woCjrEr/O/wngo6iFp7b5yJlyXapN0x+iOF3CShIhAECQQD2gZ6LLYdxSP8i
aRYAPOh10mF5IHt2dl89eOjNiqVGMlkV5aXNT80jAQr/kWGZfIjscb/xkawSKQKs
ovcn99GRAkEAteL02mBrCLfn2idBwXTdil+yeigReAZmRpqQuAfTRZN4RM+5Dw3q
X0IiCkR3oyiwx89n1eGmz1JTZRxoY1AIQQJAWVbQ5xAxLlWOYiJD3wI0Hb+JpCSp
ml18VwMjHJtLGw3US6NXW/m4Fx+hpM5D2STRWyA+uIZbHpnOZlMJ0Gp4gQJBAK38
66JV5y1Q1r2tHc6UHzQ1tMH7wDIjVQSm6FbSTXxZxAt29Rx8gD0dQvi1ZAg0bV7F
fRtwnqPlqZaoJQcTUMECQQD1Dh+Mu3OMb5AHnrtbk9l1qjM3U81QBKdyF0RY+djo
b3cR9I7+hurpqhJmQ7yuvAWe2xWc+YNTQ48FDJTogXlB
-----END RSA PRIVATE KEY-----
"
["extracerts"]=>
array(0) {
}
}
*/
function cfcasign_pkcs12($plainText)
{
$p12cert = array();
//①读取公匙文件内容:二进制数据
$file = 'ceshi/test.pfx';
//二进制文件
$fd = fopen($file, 'r');
//只读模式打开文件
$p12buf = fread($fd, filesize($file));
//读取文件
fclose($fd);
/**
* bool openssl_pkcs12_read ( string $pkcs12 , array &$certs , string $pass )
* 把以公匙加密标准证书存放区($pkcs12)转为数组存储($certs)
* $pass:解开公匙加密标准证书存放区加密的密码
*/
//②转为数组
openssl_pkcs12_read($p12buf, $p12cert, 'cfca1234');
$pkeyid = $p12cert["pkey"];
$binary_signature = "";
/**
* bool openssl_sign ( string $data , string &$signature , mixed $priv_key_id [, int $signature_alg = OPENSSL_ALGO_SHA1 ] )
* 生成签名
* $data:特殊数据
* $signature:如果成功,生成的签名(二进制数)
* $priv_key_id:用于加密sha散列法生成的数据
* 注意:$data没被加密过
*/
openssl_sign($plainText, $binary_signature, $pkeyid, OPENSSL_ALGO_SHA1);
return bin2hex($binary_signature);
//将二进制数据转换成十六进制表示
}
示例9: createHash
/**
* {@inheritdoc}
*/
public function createHash($payload, $key)
{
$this->validateKey($key);
$signature = '';
openssl_sign($payload, $signature, $key, $this->getAlgorithm());
return $signature;
}
示例10: sign
/**
* 签名
*
* @param String $params_str
*/
function sign(&$params, $cert_path, $cert_pwd)
{
//global $log;
$log = new PhpLog(SDK_LOG_FILE_PATH, "PRC", SDK_LOG_LEVEL);
$log->LogInfo('=====签名报文开始======');
if (isset($params['signature'])) {
unset($params['signature']);
}
// 转换成key=val&串
$params_str = createLinkString($params, true, false);
$log->LogInfo("签名key=val&...串 >" . $params_str);
$params_sha1x16 = sha1($params_str, FALSE);
$log->LogInfo("摘要sha1x16 >" . $params_sha1x16);
$private_key = getPrivateKey($cert_path, $cert_pwd);
// 签名
$sign_falg = openssl_sign($params_sha1x16, $signature, $private_key, OPENSSL_ALGO_SHA1);
if ($sign_falg) {
$signature_base64 = base64_encode($signature);
$log->LogInfo("签名串为 >" . $signature_base64);
$params['signature'] = $signature_base64;
} else {
$log->LogInfo(">>>>>签名失败<<<<<<<");
}
$log->LogInfo('=====签名报文结束======');
}
示例11: generateRSASignature
private function generateRSASignature($input, $key, $algo)
{
if (!openssl_sign($input, $signature, $key, $algo)) {
throw new \Exception("Unable to sign data.");
}
return $signature;
}
示例12: testSign
public function testSign()
{
$unencryptedValue = 'foobar';
openssl_sign($unencryptedValue, $encryptedValue, $this->key, OPENSSL_ALGO_SHA384);
$signature = $this->algorithm->sign($unencryptedValue, $this->key);
$this->assertSame($encryptedValue, $signature);
}
示例13: signData
/**
* Sign some data with a private key.
*
* @param string $data
* @param string $privateKey
* @param string|null $passphrase
* @return string
*/
protected function signData($data, $privateKey, $passphrase = null)
{
$privateKey = openssl_pkey_get_private($privateKey, $passphrase);
openssl_sign($data, $signature, $privateKey);
openssl_free_key($privateKey);
return $signature;
}
示例14: __construct
public function __construct()
{
$strCoreKey = "";
$strPackageKey = "";
//==================================================================
$objPackages = $this->db->query("SELECT * FROM __repo_packages WHERE category");
if ($objPackages) {
while ($row = $objPackages->fetchAssoc()) {
if (intval($row['category']) == 8) {
$privateKey = $strCoreKey;
} else {
$privateKey = $strPackageKey;
}
if ($row['filehash'] != "") {
$strHash = $row['filehash'];
// fetch private key from file and ready it
$strKey = "file://" . $privateKey;
$pkeyid = openssl_pkey_get_private($strKey);
// compute signature
openssl_sign($strHash, $signature, $pkeyid, "sha1WithRSAEncryption");
// free the key from memory
openssl_free_key($pkeyid);
$signature = base64_encode($signature);
echo "UPDATE eqdkp20_repo_packages SET signature = '" . $signature . "' WHERE id=" . $row['id'] . "; ";
}
}
}
}
示例15: getSignedURL
function getSignedURL($resource, $timeout)
{
//This comes from key pair you generated for cloudfront
$keyPairId = $this->config->item('cloudfront_keyPairId');
$key = $this->config->item('cloudfront_key');
//IMPORTANT: Keep private and not in a web-accessible location
//Set privateKey location based on web url (dev or production)
$privateKey = $this->config->item('cloudfront_keyLocation') . $key;
$expires = time() + $timeout;
//Time out in seconds
$json = '{"Statement":[{"Resource":"' . $resource . '","Condition":{"DateLessThan":{"AWS:EpochTime":' . $expires . '}}}]}';
//Read Cloudfront Private Key Pair
$fp = fopen($privateKey, "r");
$priv_key = fread($fp, 8192);
fclose($fp);
//Create the private key
$key = openssl_get_privatekey($priv_key);
if (!$key) {
echo "<p>Failed to load private key!</p>";
return;
}
//Sign the policy with the private key
if (!openssl_sign($json, $signed_policy, $key, OPENSSL_ALGO_SHA1)) {
echo '<p>Failed to sign policy: ' . openssl_error_string() . '</p>';
return;
}
//Create url safe signed policy
$base64_signed_policy = base64_encode($signed_policy);
$signature = str_replace(array('+', '=', '/'), array('-', '_', '~'), $base64_signed_policy);
//Construct the URL
$url = $resource . '?Expires=' . $expires . '&Signature=' . $signature . '&Key-Pair-Id=' . $keyPairId;
return $url;
}