本文整理汇总了PHP中openssl_pkey_get_public函数的典型用法代码示例。如果您正苦于以下问题:PHP openssl_pkey_get_public函数的具体用法?PHP openssl_pkey_get_public怎么用?PHP openssl_pkey_get_public使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了openssl_pkey_get_public函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: post_id_new1_new2_handler
public function post_id_new1_new2_handler()
{
global $FANNIE_PLUGIN_SETTINGS, $FANNIE_OP_DB;
$dbc = FannieDB::get($FANNIE_PLUGIN_SETTINGS['GiveUsMoneyDB']);
$ret = array('errors' => '');
$safe = $this->safetyCheck();
if ($safe !== true) {
$ret['errors'] = $safe;
} else {
$keyfile = realpath(dirname(__FILE__) . '/keys/public.key');
$pubkey = openssl_pkey_get_public(file_get_contents($keyfile));
$try = openssl_public_encrypt($this->new1, $encrypted, $pubkey);
if (!$try) {
$ret['errors'] = 'Error occurred during encryption';
} else {
if ($this->new1 !== $this->new2) {
$ret['errors'] = 'New values do not match';
} else {
$model = new GumTaxIdentifiersModel($dbc);
$model->card_no($this->id);
$model->encryptedTaxIdentifier($encrypted);
$model->maskedTaxIdentifier(substr($this->new1, -4));
$model->save();
}
}
}
echo json_encode($ret);
return false;
}
示例2: getResource
/**
* {@inheritdoc}
*/
public function getResource()
{
if (!($resource = openssl_pkey_get_public($this->keyPEM))) {
throw new KeyFormatException(sprintf('Fail to convert key into resource: %s', openssl_error_string()));
}
return $resource;
}
示例3: getKey
/**
* getPrivateKey
* @return resource|FALSE
* @see http://cn2.php.net/manual/en/function.openssl-get-publickey.php
*/
private function getKey()
{
if ($this->_keyInstance === false) {
$this->_keyInstance = openssl_pkey_get_public($this->key);
}
return $this->_keyInstance;
}
示例4: ValidateGooglePlaySignature
function ValidateGooglePlaySignature($receipt, $signature)
{
$publicGoogleKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt+zLT00kiP/8iHZrvBwbAOIibC6qhGW9Mt6FHFHh+uJN5+wIYWKfsWS8cU9383iJ6Q0zL2Gk7UQtZvp9ug3yCzWkTADWzepO8rm0+gBuv7OcrIq5TF5qIS4qXrmTg1VkloJb0C4OP9IPqRpa9VKa1nWIa1VbLY2U4U7vgQIcLBIGL+5d2/qhjj4UeK3seWvY8XxHh9CElxMAmaOWU6aNUSon0G7r68gwx15hMOoVy4ICeKrGyn8XibTiruYwXHwBJ6JQNYzWRtJPEF1DL1TLev/DneVVoFgrc6ZnZMZGwlnYLKn0AolCTfq2c1GRUj/FI/wd3Rcm6lHeN3pbkmb1GwIDAQAB";
$receipt = trim($receipt);
$signature = trim($signature);
//Create an RSA key compatible with openssl_verify from our Google Play sig
$key = "-----BEGIN PUBLIC KEY-----\n" . chunk_split($publicGoogleKey, 64, "\n") . '-----END PUBLIC KEY-----';
$key = openssl_pkey_get_public($key);
//print $signature;print_r(openssl_pkey_get_details($key)); exit();
if ($key == false) {
return $ret = 100;
}
//Signature should be in binary format, but it comes as BASE64.
$signature = base64_decode($signature);
//Verify the signature
$result = openssl_verify($receipt, $signature, $key, OPENSSL_ALGO_SHA1);
//print $result . ' / ' . $receipt . ' / ' . $signature . ' / ' . $key;exit();
if ($result == 1) {
$ret = 1;
} elseif ($result == 0) {
$ret = 0;
} else {
$ret = 2;
}
return $ret;
}
示例5: loadPEM
/**
* @param $data
*
* @throws \Exception
* @throws \FG\ASN1\Exception\ParserException
*
* @return array
*/
private function loadPEM($data)
{
$res = openssl_pkey_get_private($data);
if (false === $res) {
$res = openssl_pkey_get_public($data);
}
if (false === $res) {
throw new \Exception('Unable to load the key');
}
$details = openssl_pkey_get_details($res);
if (!array_key_exists('rsa', $details)) {
throw new \Exception('Unable to load the key');
}
foreach ($details['rsa'] as $key => $value) {
$value = Base64Url::encode($value);
if ($key === 'dmp1') {
$this->dp = $value;
} elseif ($key === 'dmq1') {
$this->dq = $value;
} elseif ($key === 'iqmp') {
$this->qi = $value;
} else {
$this->{$key} = $value;
}
}
}
示例6: publicKeyEncrypt
function publicKeyEncrypt($publicKey, $content)
{
$pKey = openssl_pkey_get_public($publicKey);
$encrypted = "";
openssl_public_encrypt($content, $encrypted, $pKey);
return base64_encode($encrypted);
}
示例7: __construct
public function __construct($headers = null, $body = null)
{
$config = Payplug::getConfig();
if (is_null($config)) {
throw new ParametersNotSetException();
}
if (is_null($body)) {
$body = file_get_contents("php://input");
}
if (is_null($headers)) {
$headers = getallheaders();
}
$headers = array_change_key_case($headers, CASE_UPPER);
$signature = base64_decode($headers['PAYPLUG-SIGNATURE']);
$publicKey = openssl_pkey_get_public($config->payplugPublicKey);
$isValid = openssl_verify($body, $signature, $publicKey, OPENSSL_ALGO_SHA1);
if (!$isValid) {
throw new InvalidSignatureException();
}
$data = json_decode($body, true);
$this->amount = $data['amount'];
$this->customData = $data['custom_data'];
$this->customer = $data['customer'];
$this->email = $data['email'];
$this->firstName = $data['first_name'];
$this->idTransaction = $data['id_transaction'];
$this->lastName = $data['last_name'];
$this->order = $data['order'];
$this->origin = $data['origin'];
$this->state = $data['state'];
}
示例8: __construct
public function __construct($certificate)
{
if (!extension_loaded('openssl')) {
throw new OpenSSLExtensionNotLoadedException('The openssl module is not loaded.');
}
$this->keyResource = openssl_pkey_get_public($certificate);
}
示例9: fetchPublicKey
/**
* Fetches public key from the remote certificate
*
* @param $url
* @return string|false
*/
protected function fetchPublicKey($url)
{
$cache = \Yii::$app->cache;
$cacheKey = 'paypal-public-key-' . md5($url);
$publicKey = $cache->get($cacheKey);
if ($publicKey) {
return $publicKey;
}
// trying to fetch certificate
$cert = @file_get_contents($url);
if (!$cert) {
return false;
}
$key = openssl_pkey_get_public($cert);
if (!$key) {
return false;
}
$keyData = openssl_pkey_get_details($key);
$result = ArrayHelper::getValue($keyData, 'key', false);
if (!$result) {
return false;
}
$cache->add($cacheKey, $result);
return $result;
}
示例10: encrypt
/**
* {@inheritdoc}
*/
public function encrypt($data, $key)
{
$publicKey = openssl_pkey_get_public($key);
openssl_public_encrypt($data, $messageEncrypted, $publicKey);
openssl_free_key($publicKey);
return $messageEncrypted;
}
示例11: decryptPublic
function decryptPublic($path, $cText)
{
$fcontents = file_get_contents($path);
$publicKey = openssl_pkey_get_public($fcontents);
openssl_public_decrypt($cText, $decrypted, $publicKey);
return $decrypted;
}
示例12: getKeyResource
/**
* Converts a string representation of a key into an OpenSSL resource
*
* @param string|resource $key
* @param string $password
* @return resource OpenSSL key resource
*/
protected function getKeyResource($key, $password = null)
{
if (is_resource($key)) {
return $key;
}
return openssl_pkey_get_public($key) ?: openssl_pkey_get_private($key, $password);
}
示例13: __construct
function __construct($clientcrt, $clientkey, $clientpw = NULL, $logging = false)
{
if (is_bool($logging)) {
$this->logging = $logging;
}
if (!openssl_pkey_get_private(is_file($clientkey) ? "file://" . $clientkey : $clientkey, $clientpw)) {
$this->log("Invalid client private key.", true);
}
if (!openssl_pkey_get_public(is_file($clientcrt) ? "file://" . $clientcrt : $clientcrt)) {
$this->log("Invalid client public key.", true);
}
$this->log("Certificate / key looks valid.");
$handle = curl_init();
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_HEADER, true);
curl_setopt($handle, CURLOPT_USERAGENT, sprintf("StartSSL-PHP-API/%s", self::VERSION));
curl_setopt($handle, CURLOPT_URL, $this->authUrl);
curl_setopt($handle, CURLOPT_SSLCERT, $clientcrt);
curl_setopt($handle, CURLOPT_SSLKEY, $clientkey);
if (!is_null($clientpw)) {
curl_setopt($handle, CURLOPT_SSLKEYPASSWD, $clientpw);
}
$this->log("Authenticating...");
$result = curl_exec($handle);
preg_match('/^Set-Cookie: (MyStartSSLCookie=.*)$/m', $result, $matches);
if (isset($matches[1])) {
$this->cookie = $matches[1];
$this->log("User authenticated.");
} else {
$this->log("Unable to authenticate. Check certificate/key.", true);
}
}
示例14: getPublicKey
/**
* @return resource
*/
protected function getPublicKey()
{
if (is_null($this->publicKey)) {
throw new ParameterNotFoundException("'publicKey' in JWTEncoder");
}
return openssl_pkey_get_public('file://' . $this->publicKey);
}
示例15: userAuthAction
/**
* @Rest\Post("/users/auth")
* @param unknown $request
*/
public function userAuthAction()
{
$data = $this->getRequest()->get("data");
$stringDecrypted = "";
openssl_private_decrypt(base64_decode($data), $stringDecrypted, openssl_pkey_get_private(file_get_contents(__DIR__ . "/keys/server/private_key_server.pem")));
$jsonDecrypted = json_decode($stringDecrypted);
$entityManager = $this->container->get('fos_user.user_manager');
$user = $entityManager->findUserByUsername($jsonDecrypted->username);
$encoder_service = $this->get('security.encoder_factory');
$encoder = $encoder_service->getEncoder($user);
$encoded_pass = $encoder->isPasswordValid($user->getPassword(), $jsonDecrypted->password, $user->getSalt());
$token = 0;
if ($encoded_pass) {
$currentTime = time();
$tokenTime = $currentTime + 86400;
// on day
$user->setTokenExpiresAt($tokenTime);
$clearToken = $user->getUsername() . '@' . $tokenTime;
$shaToken = sha1($clearToken);
$user->setToken($shaToken);
$stringCrypted = "";
$json = "{'token':'" . $clearToken . "'}";
openssl_public_encrypt($json, $stringCrypted, openssl_pkey_get_public(file_get_contents(__DIR__ . "/keys/server/public_key_mobile.pem")));
$token = base64_encode($stringCrypted);
return json_encode(["data" => $token]);
} else {
return false;
}
}